im trying to denoise a signal to which i added AWGN. Here is what ive done so far:
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
"""Creating a cosine and adding AWGN to it. Then denoising it.
"""
# Create cosing and cosine with noise
f_0 = 50
f_max = 2*f_0
t = np.linspace(0, 2*1/f_0, 256)
y = np.cos(2*np.pi*f_0*t)
sigma, mu = 3, 5
noise = sigma * np.random.randn(len(t)) + mu
y_noise = y + noise
# Plot both signals
figure, (ax1, ax2, ax3) = plt.subplots(3, 1)
ax1.plot(t, y, label='Signal')
ax1.set_xlabel('Time / $s$')
ax1.set_ylabel('Voltage / $V$')
ax1.legend(loc='upper right')
ax2.plot(t, y_noise, color='green', label='Signal with noise')
ax2.set_xlabel('Time / $s$')
ax2.set_ylabel('Voltage / $V$')
ax2.legend(loc='upper right')
#peaks, _ = signal.find_peaks(y_noise)
#ax2.scatter(t[peaks], y_noise[peaks], color='red')
# Design a low-pass filter for denoising
order = 6
f_c = 10
f_s = f_0 / 2
b, a = signal.butter(order, f_c / f_s)
# Apply filter to signal
y_denoised = signal.lfilter(b, a, y_noise)
# Plot transformed signal
ax3.plot(t, y_denoised, label='Denoised Signal')
ax3.set_xlabel('Time / $s$')
ax3.set_ylabel('Voltage / $V$')
ax3.legend(loc='upper right')
Any ideas why this doesnt get me the cosine signal?