[n, Wn, beta, ftype] =
kaiserord (f, m, dev)
¶[…] =
kaiserord (f, m, dev, fs)
¶Return the parameters needed to produce a filter of the desired specification from a Kaiser window. The vector f contains pairs of frequency band edges in the range [0,1]. The vector m specifies the magnitude response for each band. The values of m must be zero for all stop bands and must have the same magnitude for all pass bands. The deviation of the filter dev can be specified as a scalar or a vector of the same length as m. The optional sampling rate fs can be used to indicate that f is in Hz in the range [0,fs/2].
The returned value n is the required order of the filter (the length
of the filter minus 1). The vector Wn contains the band edges of
the filter suitable for passing to fir1
. The value beta is
the parameter of the Kaiser window of length n+1 to shape the filter.
The string ftype contains the type of filter to specify to
fir1
.
The Kaiser window parameters n and beta are computed from the relation between ripple (A=-20*log10(dev)) and transition width (dw in radians) discovered empirically by Kaiser:
/ 0.1102(A-8.7) A > 50 beta = |0.5842(A-21)^0.4 + 0.07886(A-21) 21 <= A <= 50 \ 0.0 A < 21 n = (A-8)/(2.285 dw)
Example:
[n, w, beta, ftype] = kaiserord ([1000, 1200], [1, 0], [0.05, 0.05], 11025); b = fir1 (n, w, kaiser (n+1, beta), ftype, "noscale"); freqz (b, 1, [], 11025);
See also: fir1, kaiser.
The following code
Fs = 11025; for i=1:4 if i==1, subplot(221); bands=[1200, 1500]; mag=[1, 0]; dev=[0.1, 0.1]; elseif i==2 subplot(222); bands=[1000, 1500]; mag=[0, 1]; dev=[0.1, 0.1]; elseif i==3 subplot(223); bands=[1000, 1200, 3000, 3500]; mag=[0, 1, 0]; dev=0.1; elseif i==4 subplot(224); bands=100*[10, 13, 15, 20, 30, 33, 35, 40]; mag=[1, 0, 1, 0, 1]; dev=0.05; endif [n, w, beta, ftype] = kaiserord(bands, mag, dev, Fs); d=max(1,fix(n/10)); if mag(length(mag))==1 && rem(d,2)==1, d=d+1; endif [h, f] = freqz(fir1(n,w,ftype,kaiser(n+1,beta),'noscale'),1,[],Fs); hm = freqz(fir1(n-d,w,ftype,kaiser(n-d+1,beta),'noscale'),1,[],Fs); plot(f,abs(hm),sprintf("r;order %d;",n-d), ... f,abs(h), sprintf("b;order %d;",n)); b = [0, bands, Fs/2]; hold on; for i=2:2:length(b), hi=mag(i/2)+dev(1); lo=max(mag(i/2)-dev(1),0); plot([b(i-1), b(i), b(i), b(i-1), b(i-1)],[hi, hi, lo, lo, hi],"c;;"); endfor; hold off; endfor %-------------------------------------------------------------- % A filter meets the specifications if its frequency response % passes through the ends of the criteria boxes, and fails if % it passes through the top or the bottom. The criteria are % met precisely if the frequency response only passes through % the corners of the boxes. The blue line is the filter order % returned by kaiserord, and the red line is some lower filter % order. Confirm that the blue filter meets the criteria and % the red line fails.
Produces the following figure
Figure 1 |
---|
Package: signal