Expected plot didn't come out! I did the following things:


Generated a 2 Hz sine wave (s1) with sampling frequency 1000 hz
Generated a 8 Hz sine wave (s2) with sampling frequency 1000 hz
combined both of them to get a new waveform (s3)
created a filter with cutoff 4 Hz and gave s3 as input.


filter used is :

[b,a] = fir1(7,4/fs); 

filter_out = filter(b,a,s3);


where fs is sampling frequency .

I expected that the filter will remove the 8 Hz component from the composite waveform (s3) and the filter output will be a 2 Hz sinewave.  ie both filter output and s1 will look alike.
But this is what i got.



What is wrong with my understanding/expectation?

Thanks in advance
7 is a very small number of taps and you're expecting very sharp cutoff. Also, the cutoff frequency needs to be normalized such that 1.0 is half of the sample rate. Try a much larger order. e.g.

[b,a] = fir1(300,4/fs/2);


Also beware that the beginning of the filtered output is going to have a big transient so you might try a longer waveform.