%% Design Butterworth Filter
% Design a butterworth filter with lowpass and highpass frequency responses. The filter design procedure is:
% Specify the filter design specifications using a fdesign function.
% Pick a design method provided by the designmethods function.
% To determine the available design options to choose from, use the designoptions function.
% Design the filter using the design function.
%
%% Lowpass Filter
% Construct a default lowpass filter design specification object using fdesign.lowpass.

designSpecs = fdesign.lowpass

% Determine the available design methods using the designmethods function. To design a butterworth filter, pick butter.

designmethods(designSpecs,'SystemObject',true)

% While designing the filter, you can specify additional design options. View a list of the options using the designoptions function. This function also shows the default design options the filter uses.

designoptions(designSpecs,'butter','SystemObject',true)

% Use the design function to design the filter. Pass 'butter' and the specifications given by variable designSpecs, as input arguments. Specify the 'matchexactly' design option to 'passband'.

lpFilter = design(designSpecs,'butter','matchexactly','passband','SystemObject',true);

% Visualize the frequency response of the designed filter.

fvtool(lpFilter)

%
%% Highpass Filter
% Construct a highpass filter design specification object using fdesign.highpass. Specify the order to be 7 and the 3 dB frequency to be 0\ldotp 6\pi radians/sample.

designSpecs = fdesign.highpass('N,F3dB',7,.6); 

% Determine the available design methods. To design a butterworth filter, pick butter.

designmethods(designSpecs,'SystemObject',true)

% While designing the filter, you can specify additional design options. View a list of the options using the designoptions function. This function also shows the default design options the filter uses.

designoptions(designSpecs,'butter','SystemObject',true)

% To design the butterworth filter, use the design function and specify 'butter' as an input. Set 'FilterStructure' to 'cascadeallpass'.

hpFilter = design(designSpecs,'butter','FilterStructure','cascadeallpass','SystemObject',true);

% Visualize the highpass frequency response.

fvtool(hpFilter)

% Copyright 2012 The MathWorks, Inc.