%% Design Equiripple FIR Bandpass Filter
% Design a constrained-band FIR equiripple filter of order 100 with a passband of [1, 1.4] kHz. Both stopband attenuation values are constrained to 60 dB. The sample rate is 10 kHz.
% Create a bandpass filter design specification object using the fdesign.bandpass function and specify these design parameters.

bandpassSpecs = fdesign.bandpass('N,Fst1,Fp1,Fp2,Fst2,C',100,800,1e3,1.4e3,1.6e3,1e4);

% Constrain the two stopbands with a stopband attenuation of 60 dB.

bandpassSpecs.Stopband1Constrained = true;
bandpassSpecs.Astop1 = 60;
bandpassSpecs.Stopband2Constrained = true;
bandpassSpecs.Astop2 = 60;

% Design the bandpass filter using the design function. The resulting filter is a dsp.FIRFilter System object™. For details on how to apply this filter on streaming data, refer to dsp.FIRFilter.

bandpassFilt = design(bandpassSpecs,'Systemobject',true)

%
% Visualize the frequency response of the designed filter using fvtool.

fvtool(bandpassFilt)

% Measure the frequency response characteristics of the filter using measure. The passband ripple is slightly over 2 dB. Because the design constrains both stopbands, you cannot constrain the passband ripple.

measure(bandpassFilt)

%
% Copyright 2012 The MathWorks, Inc.