# FIR filter not eliminating out of band noise?

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

Below is the FIR filter (plotted single sided):

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

Any help is appreciated!

Thanks

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...

• fftshift is usually applied to frequency domain FFTs...it gets applied to an impulse response here? Thanks,Raman – raman sridharan May 27 at 0:30
• @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. – Fat32 May 27 at 1:59
• @ramansridharan the frequency domain equivalent would be: h = real( ifft( exp(-j*(2*pi/119)*59*[0:118]').*H2 )) – Fat32 May 27 at 2:31
• Why would adding a phase shift change the amplitude response of the filter? – raman sridharan May 27 at 5:24
• @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! – Marcus Müller May 27 at 7:09