Clear Filters
Clear Filters

Bandpass Filter Not Filtering Signal

10 views (last 30 days)
Hi, I've currently designed a bandpass filter to filter a signal between 1 and 30 Hz, but when plotting it, my signal still has a random spike at 60 Hz when plotted through an absolute value squared fft, despite the filter properly being set up to cap at 30.
My code is as follows:
y = data;
data2 = double(y);
fs = 2000
samples = length(y);
yfilt = bandpass(data2, [1,30], fs);
y1 = fft(data2);
power1 = abs(y1).^2/samples;
y5 = fft(yfilt);
power5 = abs(y5).^2/samples;
which results in this large spike for the filtered data
can anyone explain what's causing this?

Accepted Answer

Cris LaPierre
Cris LaPierre on 20 Apr 2023
Edited: Cris LaPierre on 20 Apr 2023
Filters have transition regions. The likely reason is that your filter steepness is not high enough to both pass a 30 Hz signal and attenuate to 60 dB a 60 Hz signal. You can read more about it here, where the description is accompanied by this figure.
For your case:
  • Steepness, or s is 0.85
From that, you can determine the value of to be 145.5 Hz, which means your bandpass filter does not fully attenuate higher frequencies until 30+145.5 Hz, or 175.5 Hz. This is why you still see 60 Hz in your filtered signal.
You would need to increase your steepness to at least 0.97 to fully attenuate a 60 Hz signal.
  2 Comments
Mathieu NOE
Mathieu NOE on 20 Apr 2023
hello
this is basically the example given in the doc of bandpass
was surprised to see that the filter will always exhibit sharp and brickwall characteristics even with 0.5 steepness factor
that will probably generate a very long transient response, that could be an issue with short signals
nevertheless we should have a 60 dB attenuation at 60 Hz , but that is true once you are out of the transient
that's the only explanation I can see for not having the expected attenuation
=> we need a fast transient bandpass filter (would recommend to use the good old butter command and use filtfilt)
that's why I asked the OP to share its data if possible
Fs = 2000;
x = randn(5000,1);
[y1, D1] = bandpass(x,[1,30],Fs,'Steepness',0.5);
[y2, D2] = bandpass(x,[1,30],Fs,'Steepness',0.8);
[y3, D3] = bandpass(x,[1,30],Fs,'Steepness',0.95);
pspectrum([y1 y2 y3], Fs)
legend('Steepness = 0.5','Steepness = 0.8','Steepness = 0.95')
fvt = fvtool(D1,D2,D3);
legend(fvt,'Steepness = 0.5','Steepness = 0.8','Steepness = 0.95')
Cris LaPierre
Cris LaPierre on 20 Apr 2023
Edited: Cris LaPierre on 20 Apr 2023
Here is how I came up the values I presented. From the bandpass doc page
  • Computes the upper transition width as
fny = 1000;
fpu = 30;
s = 0.85;
Wu = (1-s)*(fny-fpu)
Wu = 145.5000
fsu = fpu + Wu
fsu = 175.5000
It does seem that the examples you and Star Strider have shared show a much narrower transition region.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!