Main Content

**Note**

The process flow diagram shown in the following figure lists the steps and shows the order of the filter design process.

The first four steps of the filter design process relate to the filter Specifications Object, while the last two steps involve the filter Implementation Object. Both of these objects are discussed in more detail in the following sections. Step 5 - the design of the filter, is the transition step from the filter Specifications Object to the Implementation object. The analysis and verification step is completely optional. It provides methods for the filter designer to ensure that the filter complies with all design criteria. Depending on the results of this verification, you can loop back to steps 3 and 4, to either choose a different algorithm, or to customize the current one. You may also wish to go back to steps 3 or 4 after you filter the input data with the designed filter (step 7), and find that you wish to tweak the filter or change it further.

The diagram shows the help command for each step. Enter the help line at the MATLAB^{®} command prompt to receive instructions and further
documentation links for the particular step. Not all of the steps have to be executed
explicitly. For example, you could go from step 1 directly to step 5, and the interim three
steps are done for you by the software.

The following are the details for each of the steps shown above.

If you type:

`help fdesign/responses`

You must select a response to initiate the filter. In this example, a bandpass filter Specifications Object is created by typing the following:

d = fdesign.bandpass

A *specification* is an array of design parameters for a given
filter. The specification is a property of the Specifications Object.

**Note**

A specification is not the same as the Specifications Object. A Specifications Object contains a specification as one of its properties.

When you select a filter response, there are a number of different specifications available. Each one contains a different combination of design parameters. After you create a filter Specifications Object, you can query the available specifications for that response. Specifications marked with an asterisk require the DSP System Toolbox™.

d = fdesign.bandpass; % step 1 - choose the response set (d, 'specification')

ans = 16×1 cell array 'Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2' 'N,F3dB1,F3dB2' 'N,F3dB1,F3dB2,Ap' 'N,F3dB1,F3dB2,Ast' 'N,F3dB1,F3dB2,Ast1,Ap,Ast2' 'N,F3dB1,F3dB2,BWp' 'N,F3dB1,F3dB2,BWst' 'N,Fc1,Fc2' 'N,Fc1,Fc2,Ast1,Ap,Ast2' 'N,Fp1,Fp2,Ap' 'N,Fp1,Fp2,Ast1,Ap,Ast2' 'N,Fst1,Fp1,Fp2,Fst2' 'N,Fst1,Fp1,Fp2,Fst2,C' 'N,Fst1,Fp1,Fp2,Fst2,Ap' 'N,Fst1,Fst2,Ast' 'Nb,Na,Fst1,Fp1,Fp2,Fst2'

```
d = fdesign.arbmag;
set(d,'specification')
```

ans = 7×1 cell array 'N,F,A' 'F,A,R' 'Nb,Na,F,A' 'N,B,F,A' 'N,B,F,A,C' 'B,F,A,R' 'Nb,Na,B,F,A'

The `set`

command can be used to select one of the available
specifications as
follows:

d = fdesign.lowpass; % step 1: get a list of available specifications set (d, 'specification')

ans = 18×1 cell array 'Fp,Fst,Ap,Ast' 'N,F3dB' 'Nb,Na,F3dB' 'N,F3dB,Ap' 'N,F3dB,Ap,Ast' 'N,F3dB,Ast' 'N,F3dB,Fst' 'N,Fc' 'N,Fc,Ap,Ast' 'N,Fp,Ap' 'N,Fp,Ap,Ast' 'N,Fp,F3dB' 'N,Fp,Fst' 'N,Fp,Fst,Ap' 'N,Fp,Fst,Ast' 'N,Fst,Ap,Ast' 'N,Fst,Ast' 'Nb,Na,Fp,Fst'

% step 2: set the required specification set (d, 'specification', 'N,Fc')

`fdesign`

returns the default
specification for the response you chose in Select a Response, and provides default values for all design parameters
included in the specification. The availability of algorithms depends the chosen filter response, the design
parameters, and the availability of the DSP System Toolbox. In other words, for the same lowpass filter, changing the specification entry
also changes the available algorithms. In the following example, for a lowpass filter and a
specification of `'N, Fc'`

, only one algorithm is
available—`window`

.

% step 2: set the required specification set (d, 'specification', 'N,Fc') % step 3: get available algorithms designmethods (d,'Systemobject',true)

Design Methods that support System objects for class fdesign.lowpass (N,Fc): window

`'Fp,Fst,Ap,Ast'`

, a number of algorithms are
available.
set (d, 'specification', 'Fp,Fst,Ap,Ast') designmethods(d,'Systemobject',true)

Design Methods that support System objects for class fdesign.lowpass (Fp,Fst,Ap,Ast): butter cheby1 cheby2 ellip equiripple ifir kaiserwin multistage

`design`

function.
filt = design(d,'butter','Systemobject',true)

filt = dsp.BiquadFilter with properties: Structure: 'Direct form II' SOSMatrixSource: 'Property' SOSMatrix: [13×6 double] ScaleValues: [14×1 double] InitialConditions: 0 OptimizeUnityScaleValues: true Show all properties

`filt`

is the filter
Implementation Object. This concept is discussed further in the next step.If you do not perform this step explicitly, `design`

automatically selects the optimum algorithm for the chosen response and
specification.

The customization options available for any given algorithm depend not only on the algorithm itself, selected in Select an Algorithm, but also on the specification selected in Select a Specification. To explore all the available options, type the following at the MATLAB command prompt:

help (d, 'algorithm-name')

`d`

is the Filter Specification Object, and `algorithm-name`

is the name of the
algorithm in single quotes, such as `'butter'`

or
`'cheby1'`

. The application of these customization options takes place while Design the Filter, because these options are the properties of the filter Implementation Object, not the Specification Object.

If you do not perform this step explicitly, the optimum algorithm structure is selected.

To create a filter, use the `design`

command:

% Design filter without specifying the algorithm filt = design(d,'Systemobject',true);

`filt`

is the filter object and `d`

is the
Specifications Object. This code creates a filter without specifying the algorithm. When the
algorithm is not specified, the software selects the best available one. To apply the algorithm chosen in Select an Algorithm, use the same
`design`

command, but specify the algorithm as
follows:

filt = design(d,'butter','Systemobject',true)

`filt`

is the new filter object, and `d`

is the
specifications object.To obtain help and see all the available options, type:

`help fdesign/design`

`design`

command itself,
but also options that pertain to the method or the algorithm. If you are customizing the
algorithm, you apply these options in this step. In the following example, you design a
bandpass filter, and then modify the filter
structure:filt = design(d, 'butter', 'filterstructure', 'df2sos','Systemobject',true)

filt = dsp.BiquadFilter with properties: Structure: 'Direct form II' SOSMatrixSource: 'Property' SOSMatrix: [13×6 double] ScaleValues: [14×1 double] InitialConditions: 0 OptimizeUnityScaleValues: true Show all properties

The filter design step, just like the first task of choosing a response, must be
performed explicitly. A filter object is created only when `design`

is
called.

After the filter is designed, you may wish to analyze it to determine if the filter satisfies the design criteria. Filter analysis is broken into these main sections:

Frequency domain analysis — Includes the frequency response, group delay, pole-zero plots, and phase response through the functions

`freqz`

,`grpdelay`

,`zplane`

, and`phasez`

.Time domain analysis — Includes impulse and step response through the functions

`impz`

and`stepz`

.Implementation analysis — Includes cost estimate for implementing the filter, power spectral density of the filter output due to roundoff noise, and frequency response estimate of the filter through the functions

`cost`

,`noisepsd`

, and`freqrespest`

.

For a list of analysis methods for a discrete-time filter, enter the following in the MATLAB command prompt:

dsp.<sysobjName>.helpFilterAnalysis

Replace * <sysobjName>* with the name of
the System object™. Alternatively, you can see the list of analysis methods under the Filter Analysis category.

To analyze your filter, you must explicitly perform this step.

After the filter is designed and optimized, it can be used to filter actual input data.

y = filt(x)

**Note**

`y = filt(x)`

runs only in R2016b or later. If you are using an
earlier release, replace `y = filt(x)`

with ```
y =
step(filt,x)
```

.

**Note**

If you have Simulink^{®}, you have the option of exporting this filter to a Simulink block using the `realizemdl`

command. To get help on this
command, type:

`help realizemdl`