Reputation: 19333
I am currently using a MATLAB example on generating a Kaiser window finite impulse response (FIR) filter according to pre-determined filter requirements.
Kaiser Window Filter Design
Design a lowpass filter with passband defined from 0 to 1 kHz and stopband defined from 1500 Hz to 4 kHz. Specify a passband ripple of 5% and a stopband attenuation of 40 dB.
fsamp = 8000;
fcuts = [1000 1500];
mags = [1 0];
devs = [0.05 0.01];
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
freqz(hh)
In my case, I'm expecting at least 40dB of signal attenuation by the time we hit the 4kHz mark in the frequency spectrum (ie: end of the transition band, beginning of the stop band). However, I have an additional requirement: that the filter also provides at least 20dB of attenuation by the mid-way point of the transition band (i: the 1250Hz mark). The filter I designed with the code above does not achieve both requirements, because the Kaiser FIR implementation has a slow initial roll-off.
Is there a direct method for forcing multiple constraints on the filter from the get-go, ie:
Design a lowpass filter with passband defined from 0 to 1 kHz and stopband defined from 1500 Hz to 4 kHz. Specify a passband ripple of 5% and a stopband attenuation of 40 dB, and at least 20dB attenuation by 1250Hz.
So far, the only such solution that comes to mind is to generate the same Kaiser window as I do above (once), but then loop through multiple iterations and increment the filter order, n
, each iteration until my requirements are satisfied. Is there a more elaborate or direct method, or is my iterative approach the only approach at this time?
I tried just making a filter with 20dB attenuation by 1250Hz, but then the filter doesn't seem to provide much more attenuation further on (ie: only 22dB stopband attenuation by 1500Hz).
Thanks!
Upvotes: 0
Views: 189
Reputation: 1270
The Kaiser window filter designer does not support automatically solving for that sort of constraint. Looking through the source for kaiserord
it looks like it supports low- and high-pass, bandpass, bandstop, and mulitple band pass/stop as long as the pass/stop bands are all of the same amplitude.
The simplest solution to your problem is to define the stopband as starting at 1250Hz with 40dB attenuation. This will ensure that the 1500Hz is also at or below 40dB, but obviously may result in a higher order filter than you actually require.
The attenuation in the sidelobes is directly related to the beta value, which means the only effect of increasing the order should be an increase in the steepness of the rolloff, so your approach seems like the simplest and most direct method supported by MATLAB's filter design tools. Unfortunately, it won't work in practice.
The way the filter builder implements a cuttoff filter with pass and stop band ripple/attenuation constraints is to set the cutoff point to exactly halfway between the end of the pass constraint and beginning of the stop constraint. The cutoff point is always constrained to -6dB. So no matter how high of a filter order you use, 1250Hz will always be -6dB.
I recommend defining the stopband at 1250Hz/-40dB like I described above, and then reducing your filter order until you no longer meet the constraints. My testing while writing this up gave an order of 47, but I didn't check it rigorously.
Minimum order filter with 1250Hz -40dB:
[n, Wn, beta, ftype] = kaiserord([1000, 1250], [1, 0], [.05, db2mag(-40)], 8000);
hh = fir1(n, Wn, ftype, kaiser(n+1, beta), 'noscale');
freqz(hh)
n = 72
Same filter, order reduced to 47:
hh = fir1(n-25, Wn, ftype, kaiser(n-25+1, beta), 'noscale');
freqz(hh)
Upvotes: 1