# Generated by pandoc-plot 1.5.5
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(2019)

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pywt
from numpy.random import default_rng

random = default_rng(seed=2022)

data = np.loadtxt(
    Path("files") / "wavelet-filter" / "diffraction.csv", delimiter=",", skiprows=1
)
t = data[:, 0]
signal = data[:, 1]

noise = random.normal(size=t.shape[0], loc=-0.5, scale=1)

approx, *details= pywt.wavedec(signal + noise, wavelet=pywt.Wavelet('sym17'), level=3, mode='zero')
filtered = pywt.waverec([approx] + [ np.zeros_like(bank) for bank in details ], wavelet=pywt.Wavelet('sym17'), mode='zero')

fig, ax = plt.subplots(1, 1, figsize=(8,4))
ax.plot(t, signal, label="Pure signal", color='k')
ax.plot(t, filtered, label="Filtered signal", color='g')
ax.set_xlabel("Time [s]")
ax.set_ylabel('Amplitude [a.u.]')
ax.legend()
Click here to see how this plot was generated.