%% Kaiser Windows in FIR Design
% There are two design formulas that can help you design FIR filters to meet a set of filter specifications using a Kaiser window. To achieve a relative sidelobe attenuation of –α dB, the β (beta) parameter is
% \beta =\left\lbrace \begin{array}{cc}
% 0\ldotp 1102\left(\alpha -8\ldotp 7\right), & \alpha >50,\\
% 0\ldotp 5842{\left(\alpha -21\right)}^{0\ldotp 4} +0\ldotp 7886\left(\alpha -21\right), & 50\ge \alpha \ge 21,\\
% 0, & \alpha <21\ldotp
% \end{array}\right.
% For a transition width of \Delta \omega rad/sample, use the length
% n=\frac{\alpha-8}{2.285\Delta\omega}+1.
% Filters designed using these heuristics will meet the specifications approximately, but you should verify this. To design a lowpass filter with cutoff frequency 0.5\pi rad/sample, transition width 0.2\pi rad/sample, and 40 dB of attenuation in the stopband, try

[n,wn,beta] = kaiserord([0.4 0.6]*pi,[1 0],[0.01 0.01],2*pi);
h = fir1(n,wn,kaiser(n+1,beta),'noscale');

%
% The kaiserord function estimates the filter order, cutoff frequency, and Kaiser window beta parameter needed to meet a given set of frequency domain specifications.
% The ripple in the passband is roughly the same as the ripple in the stopband. As you can see from the frequency response, this filter nearly meets the specifications:

fvtool(h,1)

% Copyright 2012 The MathWorks, Inc.