MATLAB: Ripple occuring in filtered fft after lower cut off frequency

bandpassfftfilter

Hey, I have been trying to apply a bandpass filter to some data I have to filter out everything below 500 Hz and above 2.5 kHz. I applied an FFT to the original and filtered data and there is a ripple just above 500 Hz – which you can see on the red trace here on the left
The magnitude response on the right seems to be correct so I'm not sure what the problem is.
Can anyone help? Thank you!
The code I have written is:
Fs = 8000; % Sampling Frequency
Fstop1 = 500; % First Stopband Frequency
Fpass1 = 550; % First Passband Frequency
Fpass2 = 2500; % Second Passband Frequency
Fstop2 = 2550; % Second Stopband Frequency
Dstop1 = 1e-4; % First Stopband Attenuation Corresponds to 80 dB stopband attenuation
Dpass = 0.00057565; % Passband Ripple Corresponds to 0.01 dB peak-to-peak ripple
Dstop2 = 1e-4; % Second Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 1 ...
0], [Dstop1 Dpass Dstop2]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);
fvtool(Hd);
bp = filter(Hd,Y);

Best Answer

The problem:
bp = filter(Hd,Y);
The (likely) solution:
bp = filtfilt(Hd,Y);
You’re most likely getting phase distortion or other transient effects. Using the filtfilt function instead should correct those. I don’t have your data to test, so I can’t say for sure.
Related Question