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.

enter image description here

What is wrong with my understanding/expectation?

Thanks in advance


1 Answer 1


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.

  • $\begingroup$ sorry, I can't make a comment. plz add the filter response. $\endgroup$
    – reply1988
    Nov 26, 2015 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.