%% Design FIR Equiripple Lowpass Filters
% Design an FIR equiripple lowpass filter. Specify a passband edge frequency of 0.2π rad/sample and a stopband edge frequency of 0.25π rad/sample. Set the passband ripple to 0.5 dB and the stopband attenuation to 40 dB..

designSpecs = fdesign.lowpass('Fp,Fst,Ap,Ast',0.2,0.25,0.5,40)

%  Use the default Equiripple method to design the filter.

filt = design(designSpecs,'SystemObject',true)

%
% Determine the available design methods by running the designmethods function on the filter design specification object, designSpecs.

designmethods(designSpecs,'SystemObject',true)

% You can also specify the design options used in designing the filter. To see a list of available options, run the designoptions function on designSpecs.

designoptions(designSpecs,'equiripple')

% Design a minimum-phase FIR equiripple filter by setting 'MinPhase' to true.

filtMin = design(designSpecs,'equiripple','MinPhase',true,'SystemObject',true)

% Display pole-zero plots of the default and minimum-phase designs.

fvt = fvtool(filt,filtMin,'Analysis','polezero');
legend(fvt,'Default design','Minimum-phase design')

%
% Redesign the filter using the elliptic method. Determine the available design options for the elliptic method.

designoptions(designSpecs,'ellip')

% Match the passband exactly by setting 'MatchExactly' to 'passband'.

filt = design(designSpecs,'ellip','MatchExactly','passband','SystemObject',true)

%
% You can specify the Pth norm scaling on the second-order sections. Use L-infinity norm scaling in the time domain.

filtL = design(designSpecs,'ellip','MatchExactly','passband','SOSScaleNorm','linf', ...
    'SystemObject',true)

%
% Display the frequency responses of the filters.

fvt = fvtool(filt,filtL);
legend(fvt,'Default scaling','L-infinity norm scaling')

% Copyright 2012 The MathWorks, Inc.