I have a simple FIR filter that should eliminate all lower frequencies:

H = zeros(60,1); H(30:end) = 1+1i; H = [H;conj(flipud(H(2:end)))]; % double sided h= ifft(H);

Then I assign a sample time to generate a time vector:

dT = 0.002; Tspan = dT*length(h); dF = 1/Tspan; Here my nyquist is 250Hz. So the filter should eliminate everything below 125Hz.

I generate a signal at 15Hz, and convolve it with the filter coefficients.

t = 0:dT:5;
x = cos(2*pi*15*t);

But, I get an output signal that clearly does not have the 15Hz eliminated:

Input signal above, response signal below Input signal above, response signal below

Below is the FIR filter (plotted single sided): filter

Does it look like my convolution algorithm is incorrect? Or am I misunderstanding something?

Any help is appreciated!



1 Answer 1


You can solve your problem by an fftshift of the impulse response, as this line shows:

h = fftshift( real( ifft(H)) );

now it should work.

NOTE that there will be a transient of length about $60$ samples (half the linear phase FIR filter length) at the beginning of the convolution output, after which the steady state result emerges...

  • $\begingroup$ fftshift is usually applied to frequency domain FFTs...it gets applied to an impulse response here? Thanks,Raman $\endgroup$ May 27, 2019 at 0:30
  • 1
    $\begingroup$ @ramansridharan in this example all I wanted to do was to circulate the impulse response so that its peak comes to the middle (to its supposed place). So I used (or abused) fftshift for that purpose... it's similar to adding phase to the frequency samples. $\endgroup$
    – Fat32
    May 27, 2019 at 1:59
  • $\begingroup$ @ramansridharan the frequency domain equivalent would be: h = real( ifft( exp(-j*(2*pi/119)*59*[0:118]').*H2 )) $\endgroup$
    – Fat32
    May 27, 2019 at 2:31
  • $\begingroup$ Why would adding a phase shift change the amplitude response of the filter? $\endgroup$ May 27, 2019 at 5:24
  • $\begingroup$ @ramansridharan because time- and frequency domain are linked: what you call "phase shift" is actually a modulation with a complex sinusoid, and corresponds to a cyclic time shift, exactly as Fat32 said. It's the same thing! $\endgroup$ May 27, 2019 at 7:09

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.