I have a periodic signal like this one with period $T=120$:
I would like to apply a bandstop filter to the signal, the stop band should go from 90% of $\frac{1}{T}$ to 110% of $\frac{1}{T}$.
So I run this code in Octave
A=-ones(1,35);
B=ones(1,45);
C=-ones(1,20);
D=ones(1,20);
E=[A B C D];
x=repmat(E,[1 6]);
figure
plot(x,'b');
axis([1 numel(x) -1.5 1.5]);
title('Input signal');
print -dpng input.png
figure
plot(x,'b');
axis([1 numel(x) -1.5 1.5]);
signal_period=numel(E);
signal_frequency=1/signal_period;
sampling_period=1;
sampling_frequency=1/sampling_period;
% "The Nyquist frequency is half the sample rate",
% from http://it.mathworks.com/help/signal/ref/fir1.html#inputarg_Wn
Nyquist_frequency=sampling_frequency/2;
signal_normalized_frequency = signal_frequency/Nyquist_frequency;
b = fir1(40,[0.9*signal_normalized_frequency 1.1*signal_normalized_frequency],'stop');
y = filter(b,1,x);
hold on
plot(y,'r');
title('Input (blue), output (red)');
print -dpng filter_response.png
and I get this filtered signal:
I would expect an attenuation of the signal but I only get a slightly "delayed" signal with some "ringing".
What am I missing?
My ideas:
- I made a mistake in
fir1
with the definition of the lower and upper cutoff frequencies, perhaps I do not understand the normalized frequency concept? - Maybe the cutoff frequencies are too low? The frequency response of the filter is the following:
and I cannot see the classical "deep" stop band of a notch filter in the magnitude graph.