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

np.random.seed(2019)

import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
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)

fig, (ax_t, ax_w) = plt.subplots(2,1, figsize=(8,6))

ax_t.plot(t, signal + noise, color='r', label="Noisy signal")
ax_t.plot(t, signal, color='k', label="Pure signal")
ax_t.set_xlim([t[0], t[-1]])
ax_t.set_xlabel("Time [s]")
ax_t.set_ylabel("Amplitude [a.u.]")
ax_t.legend()


w = np.fft.fftshift(np.fft.fftfreq(t.shape[0], d=t[1] - t[0]))
signal_w = np.abs(np.fft.fftshift(np.fft.fft(signal)))**2
noise_w = np.abs(np.fft.fftshift(np.fft.fft(noise)))**2
noise_multiplier = 15

ax_w.plot(w, signal_w, color='k', label="Signal power spectrum")
ax_w.plot(w, noise_multiplier * noise_w, color='r', label="Noise power spectrum")
ax_w.text(x=1, y=(noise_multiplier * noise_w).max()/2, s=f"✕{noise_multiplier:0.0f}", color='r')
ax_w.set_xlim([-10, 10])
ax_w.set_xlabel("Angular frequency [rad/s]")
ax_w.set_ylabel("Spectral power [a.u.]")
ax_w.legend()
Click here to see how this plot was generated.