Doing some work at the minute on digital filters in matlab, I have a file with artifical noise added (sine wave added at specific frequency). The goal is to filter the signal and get it as close as possible to the clean signal provided.
I've done an FFT and plotted the results and found a very large spike at 29.3Hz which is not present in the clean signal.
I've tried using a notch filter, which I thought would work since it operates at such a specific frequency, however it just seems to attenuate the signal and remove some power but not block it completely. I then added a bandstop filter to try and block any signals in that region and it simply attenuated the signal also. Does anyone have any thoughts? I just seem to be lowering power of the entire signal and not actually removing anything, getting the basic shape of the clean signal but still a lot of noise present after both filters. Thanks!
[b1,a1] = iirnotch((29.3*(2/fs)),0.99999);
IIR1 = filter(b1,a1,ecg58_DC_removed);
FFT_resultFilter1 = (1/length(t))*fft(IIR1);
f=(0:1024)/1024*(200/2);
figure(4)
stem(f, 2*abs(FFT_resultFilter1(1:1025)));
xlabel ('Frequency (Hz)');
ylabel ('Spectral Magnitude');
title('First filter')
grid on
[a2,b2] = butter(2,[29.2 29.4]*2/fs, 'stop');
IIR2 = filter(a2,b2,IIR1);
FFT_resultFilter2 = (1/length(t))*fft(IIR2);
f=(0:1024)/1024*(200/2);
figure(5)
stem(f, 2*abs(FFT_resultFilter2(1:1025)));
xlabel ('Frequency (Hz)');
ylabel ('Spectral Magnitude');
title('First filter')
grid on
figure (6)
plot(t(1:1000), IIR2(1:1000));
xlabel('time (s)')
ylabel('amplitude')
title('two filters');
b1 =
1.0e-04 *
0.1571 -0.1902 0.1571
a1 =
1.0000 -0.0000 -1.0000
iirnotch
. The bandwidth is very large, i.e. the Q factor of the filter is very small, resulting in a useless filter. According to the Mathworks doc page, you could try choosingBW=w0/35
. $\endgroup$[b1,a1]
to your answer so we can see what's going on. $\endgroup$