Designfilt and bandstopfir adds +320dB for some reason
3 views (last 30 days)
Show older comments
Good evening!
I am trying to create a set of FIR filters (using designfilt) to apply to some audio signals, and I'm having an issue.
When I try to use a 'bandstopfir', for some reason the whole signal is amplified around +320dB (while 'bandpassfir', 'lowpassfir' and 'highpassfir' are working correctly)
Here's a quick example of the code I'm using, and I added the resulting images of each of these cases showing the issue:
clear
filterObject1 = designfilt('bandstopfir','FilterOrder',301,...
'CutoffFrequency1',2000,'CutoffFrequency2',4000,'SampleRate',48000);
filterObject2 = designfilt('bandpassfir','FilterOrder',301,...
'CutoffFrequency1',2000,'CutoffFrequency2',4000,'SampleRate',48000);
Here are images using fvtool to show both filter responses:
Bandstop (incorrect behaviour):
Bandpass (expected behaviour):
Is this a bug, is the installation I'm using somehow broken, or am I doing something wrong?
0 Comments
Accepted Answer
Paul
on 10 Jun 2024
Hi Andres,
I don't have a complete answer, just an observation. Here's the original design with order 301
filterObject1 = designfilt('bandstopfir','FilterOrder',301,...
'CutoffFrequency1',2000,'CutoffFrequency2',4000,'SampleRate',48000);
figure
freqz(filterObject1,0:5000,48000)
xlim([0 5])
We see the undesired result, and we see see that something peculiar is happening with the response at very low frequency.
Try again, but use an even filter order
filterObject1 = designfilt('bandstopfir','FilterOrder',300,...
'CutoffFrequency1',2000,'CutoffFrequency2',4000,'SampleRate',48000);
figure
freqz(filterObject1,0:5000,48000)
xlim([0 5])
If you experiment, you'll see that bandstopfir doesn't like an odd filter order (in combination with the other designfilt parameters and defaults). I'm not sure why that is the case, but maybe this observation can help you move forward.
3 Comments
Paul
on 11 Jun 2024
Edited: Paul
on 11 Jun 2024
I'm not sure the low frequency response is wrong.
I suspect that a bandstop, FIR filter has particular symmetry requirements on its zeros, which can be met when there's an even number of zeros. When the filter order is odd, we have an extra, lonely, real zero, and that zero ends up z = 1 (at least for this set of design parameters) which governs the low frequency response. In fact, H(j*0) = 0 in theory, so that scaling you see from the ScalePassBand parameter to 320 dB is just numerical error because H(j*0) doesn't evaluate exactly to zero.
For a bandpass filter, that extra zero for the odd order case ends up at z = -1, so only has an effect on the high frequency response, which is very small anyway. It also wouldn't matter (much) if the extra zero is at z = 1 for for the same reason.
At present, I don't know why the extra zero is at z = 1 for bandstop and z = -1 for bandpass, or if that depends on the particular design method.
More Answers (0)
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!