# designfilt

Design digital filters

## Syntax

``d = designfilt(resp,Name,Value)``
``designfilt(d)``

## Description

example

````d = designfilt(resp,Name,Value)` designs a `digitalFilter` object, `d`, with response type `resp`. Specify the filter further using a set of `Name,Value` pairs. The allowed specification sets depend on the response type, `resp`, and consist of combinations of the following:Frequency constraints correspond to the frequencies at which a filter exhibits a desired behavior. Examples include `'``PassbandFrequency``'` and `'``CutoffFrequency``'`. (See the complete list under Name-Value Pair Arguments.) You must always specify the frequency constraints.Magnitude constraints describe the filter behavior at particular frequency ranges. Examples include `'``PassbandRipple``'` and `'``StopbandAttenuation``'`. (See the complete list under Name-Value Pair Arguments.) `designfilt` provides default values for magnitude constraints left unspecified. In arbitrary-magnitude designs you must always specify the vectors of desired amplitudes.`'``FilterOrder``'`. Some design methods let you specify the order. Others produce minimum-order designs. That is, they generate the smallest filters that satisfy the specified constraints.`'``DesignMethod``'` is the algorithm used to design the filter. Examples include constrained least squares (`'cls'`) and Kaiser windowing (`'kaiserwin'`). For some specification sets, there are multiple design methods available to choose from. In other cases, you can use only one method to meet the desired specifications.Design options are parameters specific to a given design method. Examples include `'``Window``'` for the `'window'` method and optimization `'``Weights``'` for arbitrary-magnitude equiripple designs. (See the complete list under Name-Value Pair Arguments.) `designfilt` provides default values for design options left unspecified.`'``SampleRate``'` is the frequency at which the filter operates. `designfilt` has a default sample rate of 2 Hz. Using this value is equivalent to working with normalized frequencies. NoteIf you specify an incomplete or inconsistent set of name-value pairs at the command line, `designfilt` offers to open a Filter Design Assistant. The assistant helps you design the filter and pastes the corrected MATLAB® code on the command line.If you call `designfilt` from a script or function with an incorrect set of specifications, `designfilt` issues an error message with a link to open a Filter Design Assistant. The assistant helps you design the filter, comments out the faulty code in the function or script, and pastes the corrected MATLAB code on the next line. Use `filter` in the form `dataOut = filter(d,dataIn)` to filter a signal with a `digitalFilter`, `d`.Use FVTool to visualize a `digitalFilter`, `d`.Type `d.Coefficients` to obtain the coefficients of a `digitalFilter`, `d`. For IIR filters, the coefficients are expressed as second-order sections.See `digitalFilter` for a list of the filtering and analysis functions available for use with `digitalFilter` objects. ```
````designfilt(d)` lets you edit an existing digital filter, `d`. It opens a Filter Design Assistant populated with the filter’s specifications, which you can then modify. This is the only way you can edit a `digitalFilter` object. Its properties are otherwise read-only.```

## Examples

collapse all

Design a minimum-order lowpass FIR filter with normalized passband frequency $0.25\pi$ rad/s, stopband frequency $0.35\pi$ rad/s, passband ripple 0.5 dB, and stopband attenuation 65 dB. Use a Kaiser window to design the filter. Visualize its magnitude response. Use it to filter a vector of random data.

```lpFilt = designfilt('lowpassfir','PassbandFrequency',0.25, ... 'StopbandFrequency',0.35,'PassbandRipple',0.5, ... 'StopbandAttenuation',65,'DesignMethod','kaiserwin'); fvtool(lpFilt)```

```dataIn = rand(1000,1); dataOut = filter(lpFilt,dataIn);```

Design a lowpass IIR filter with order 8, passband frequency 35 kHz, and passband ripple 0.2 dB. Specify a sample rate of 200 kHz. Visualize the magnitude response of the filter.

```lpFilt = designfilt('lowpassiir','FilterOrder',8, ... 'PassbandFrequency',35e3,'PassbandRipple',0.2, ... 'SampleRate',200e3); fvtool(lpFilt)```

Use the filter you designed to filter a 1000-sample random signal.

```dataIn = randn(1000,1); dataOut = filter(lpFilt,dataIn);```

Output the filter coefficients, expressed as second-order sections.

`sos = lpFilt.Coefficients`
```sos = 4×6 0.2666 0.5333 0.2666 1.0000 -0.8346 0.9073 0.1943 0.3886 0.1943 1.0000 -0.9586 0.7403 0.1012 0.2023 0.1012 1.0000 -1.1912 0.5983 0.0318 0.0636 0.0318 1.0000 -1.3810 0.5090 ```

Design a minimum-order highpass FIR filter with normalized stopband frequency $0.25\pi$ rad/s, passband frequency $0.35\pi$ rad/s, passband ripple 0.5 dB, and stopband attenuation 65 dB. Use a Kaiser window to design the filter. Visualize its magnitude response. Use it to filter 1000 samples of random data.

```hpFilt = designfilt('highpassfir','StopbandFrequency',0.25, ... 'PassbandFrequency',0.35,'PassbandRipple',0.5, ... 'StopbandAttenuation',65,'DesignMethod','kaiserwin'); fvtool(hpFilt)```

```dataIn = randn(1000,1); dataOut = filter(hpFilt,dataIn);```

Design a highpass IIR filter with order 8, passband frequency 75 kHz, and passband ripple 0.2 dB. Specify a sample rate of 200 kHz. Visualize the filter's magnitude response. Apply the filter to a 1000-sample vector of random data.

```hpFilt = designfilt('highpassiir','FilterOrder',8, ... 'PassbandFrequency',75e3,'PassbandRipple',0.2, ... 'SampleRate',200e3); fvtool(hpFilt)```

```dataIn = randn(1000,1); dataOut = filter(hpFilt,dataIn);```

Design a 20th-order bandpass FIR filter with lower cutoff frequency 500 Hz and higher cutoff frequency 560 Hz. The sample rate is 1500 Hz. Visualize the magnitude response of the filter. Use it to filter a random signal containing 1000 samples.

```bpFilt = designfilt('bandpassfir','FilterOrder',20, ... 'CutoffFrequency1',500,'CutoffFrequency2',560, ... 'SampleRate',1500); fvtool(bpFilt)```

```dataIn = randn(1000,1); dataOut = filter(bpFilt,dataIn);```

Output the filter coefficients.

`b = bpFilt.Coefficients`
```b = 1×21 -0.0113 0.0067 0.0125 -0.0445 0.0504 0.0101 -0.1070 0.1407 -0.0464 -0.1127 0.1913 -0.1127 -0.0464 0.1407 -0.1070 0.0101 0.0504 -0.0445 0.0125 0.0067 -0.0113 ```

Design a 20th-order bandpass IIR filter with lower 3-dB frequency 500 Hz and higher 3-dB frequency 560 Hz. The sample rate is 1500 Hz. Visualize the frequency response of the filter. Use it to filter a 1000-sample random signal.

```bpFilt = designfilt('bandpassiir','FilterOrder',20, ... 'HalfPowerFrequency1',500,'HalfPowerFrequency2',560, ... 'SampleRate',1500); fvtool(bpFilt)```

```dataIn = randn(1000,1); dataOut = filter(bpFilt,dataIn);```

Design a 20th-order bandstop FIR filter with lower cutoff frequency 500 Hz and higher cutoff frequency 560 Hz. The sample rate is 1500 Hz. Visualize the magnitude response of the filter. Use it to filter 1000 samples of random data.

```bsFilt = designfilt('bandstopfir','FilterOrder',20, ... 'CutoffFrequency1',500,'CutoffFrequency2',560, ... 'SampleRate',1500); fvtool(bsFilt)```

```dataIn = randn(1000,1); dataOut = filter(bsFilt,dataIn);```

Design a 20th-order bandstop IIR filter with lower 3-dB frequency 500 Hz and higher 3-dB frequency 560 Hz. The sample rate is 1500 Hz. Visualize the magnitude response of the filter. Use it to filter 1000 samples of random data.

```bsFilt = designfilt('bandstopiir','FilterOrder',20, ... 'HalfPowerFrequency1',500,'HalfPowerFrequency2',560, ... 'SampleRate',1500); fvtool(bsFilt)```

```dataIn = randn(1000,1); dataOut = filter(bsFilt,dataIn);```

Design a full-band differentiator filter of order 7. Display its zero-phase response. Use it to filter a 1000-sample vector of random data.

```dFilt = designfilt('differentiatorfir','FilterOrder',7); fvtool(dFilt,'MagnitudeDisplay','Zero-phase')```

```dataIn = randn(1000,1); dataOut = filter(dFilt,dataIn);```

Design a Hilbert transformer of order 18. Specify a normalized transition width of $0.25\pi$ rad/s. Display in linear units the magnitude response of the filter. Use it to filter a 1000-sample vector of random data.

```hFilt = designfilt('hilbertfir','FilterOrder',18,'TransitionWidth',0.25); fvtool(hFilt,'MagnitudeDisplay','magnitude')```

```dataIn = randn(1000,1); dataOut = filter(hFilt,dataIn);```

You are given a signal sampled at 1 kHz. Design a filter that stops frequencies between 100 Hz and 350 Hz and frequencies greater than 400 Hz. Specify a filter order of 60. Visualize the frequency response of the filter. Use it to filter a 1000-sample random signal.

```mbFilt = designfilt('arbmagfir','FilterOrder',60, ... 'Frequencies',0:50:500,'Amplitudes',[1 1 1 0 0 0 0 1 1 0 0], ... 'SampleRate',1000); fvtool(mbFilt)```

```dataIn = randn(1000,1); dataOut = filter(mbFilt,dataIn);```

## Input Arguments

collapse all

Filter response and type, specified as a character vector or string scalar. Click one of the possible values of `resp` to expand a table of allowed specification sets.

Data Types: `char` | `string`

Digital filter, specified as a `digitalFilter` object generated by `designfilt`. Use this input to change the specifications of an existing `digitalFilter`.

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `'FilterOrder',20,'CutoffFrequency',0.4` suffices to specify a lowpass FIR filter.

Not all combinations of `Name,Value` pairs are valid. The valid combinations depend on the filter response that you need and on the frequency and magnitude constraints of your design.

#### Filter Order

collapse all

Filter order, specified as the comma-separated pair consisting of `'FilterOrder'` and a positive integer scalar.

Data Types: `double`

Numerator order of an IIR design, specified as the comma-separated pair consisting of `'NumeratorOrder'` and a positive integer scalar.

Data Types: `double`

Denominator order of an IIR design, specified as the comma-separated pair consisting of `'DenominatorOrder'` and a positive integer scalar.

Data Types: `double`

#### Frequency Constraints

collapse all

Passband frequency, specified as the comma-separated pair consisting of `'PassbandFrequency'` and a positive scalar. The frequency value must be within the Nyquist range.

`'PassbandFrequency1'` is the lower passband frequency for a bandpass or bandstop design.

`'PassbandFrequency2'` is the higher passband frequency for a bandpass or bandstop design.

Data Types: `double`

Stopband frequency, specified as the comma-separated pair consisting of `'StopbandFrequency'` and a positive scalar. The frequency value must be within the Nyquist range.

`'StopbandFrequency1'` is the lower stopband frequency for a bandpass or bandstop design

`'StopbandFrequency2'` is the higher stopband frequency for a bandpass or bandstop design.

Data Types: `double`

6-dB frequency, specified as the comma-separated pair consisting of `'CutoffFrequency'` and a positive scalar. The frequency value must be within the Nyquist range.

`'CutoffFrequency1'` is the lower 6-dB frequency for a bandpass or bandstop design.

`'CutoffFrequency2'` is the higher 6-dB frequency for a bandpass or bandstop design.

Data Types: `double`

3-dB frequency, specified as the comma-separated pair consisting of `'HalfPowerFrequency'` and a positive scalar. The frequency value must be within the Nyquist range.

`'HalfPowerFrequency1'` is the lower 3-dB frequency for a bandpass or bandstop design.

`'HalfPowerFrequency2'` is the higher 3-dB frequency for a bandpass or bandstop design.

Data Types: `double`

Width of the transition region between passband and stopband for a Hilbert transformer, specified as the comma-separated pair consisting of `'TransitionWidth'` and a positive scalar.

Data Types: `double`

Response frequencies, specified as the comma-separated pair consisting of `'Frequencies'` and a vector. Use this variable to list the frequencies at which a filter of arbitrary magnitude response has desired amplitudes. The frequencies must be monotonically increasing and lie within the Nyquist range. The first element of the vector must be either 0 or fs/2, where fs is the sample rate, and its last element must be fs/2. If you do not specify a sample rate, `designfilt` uses the default value of 2 Hz.

Data Types: `double`

Number of bands in a multiband design, specified as the comma-separated pair consisting of `'NumBands'` and a positive integer scalar not greater than 10.

Data Types: `double`

Multiband response frequencies, specified as comma-separated pairs consisting of `'BandFrequenciesi'` and a numeric vector. `'BandFrequenciesi'`, where i runs from 1 through `NumBands`, is a vector containing the frequencies at which the ith band of a multiband design has the desired values, `'BandAmplitudesi'`. `NumBands` can be at most 10. The frequencies must lie within the Nyquist range and must be specified in monotonically increasing order. Adjacent frequency bands must have the same amplitude at their junction.

Data Types: `double`

#### Magnitude Constraints

collapse all

Passband ripple, specified as the comma-separated pair consisting of `'PassbandRipple'` and a positive scalar expressed in decibels.

`'PassbandRipple1'` is the lower-band passband ripple for a bandstop design.

`'PassbandRipple2'` is the higher-band passband ripple for a bandstop design.

Data Types: `double`

Stopband attenuation, specified as the comma-separated pair consisting of `'StopbandAttenuation'` and a positive scalar expressed in decibels.

`'StopbandAttenuation1'` is the lower-band stopband attenuation for a bandpass design.

`'StopbandAttenuation2'` is the higher-band stopband attenuation for a bandpass design.

Data Types: `double`

Desired response amplitudes of an arbitrary magnitude response filter, specified as the comma-separated pair consisting of `'Amplitudes'` and a vector. Express the amplitudes in linear units. The vector must have the same length as `'Frequencies'`.

Data Types: `double`

Multiband response amplitudes, specified as comma-separated pairs consisting of `'BandAmplitudesi'` and a numeric vector. `'BandAmplitudesi'`, where i runs from 1 through `NumBands`, is a vector containing the desired amplitudes in the ith band of a multiband design. `NumBands` can be at most 10. Express the amplitudes in linear units. `'BandAmplitudesi'` must have the same length as `'BandFrequenciesi'`. Adjacent frequency bands must have the same amplitude at their junction.

Data Types: `double`

#### Design Method

collapse all

Design method, specified as the comma-separated pair consisting of `'DesignMethod'` and a character vector or string scalar. The choice of design method depends on the set of frequency and magnitude constraints that you specify.

• `'butter'` designs a Butterworth IIR filter. Butterworth filters have a smooth monotonic frequency response that is maximally flat in the passband. They sacrifice rolloff steepness for flatness.

• `'cheby1'` designs a Chebyshev type I IIR filter. Chebyshev type I filters have a frequency response that is equiripple in the passband and maximally flat in the stopband. Their passband ripple increases with increasing rolloff steepness.

• `'cheby2'` designs a Chebyshev type II IIR filter. Chebyshev type II filters have a frequency response that is maximally flat in the passband and equiripple in the stopband.

• `'cls'` designs an FIR filter using constrained least squares. The method minimizes the discrepancy between a specified arbitrary piecewise-linear function and the filter’s magnitude response. At the same time, it lets you set constraints on the passband ripple and stopband attenuation.

• `'ellip'` designs an elliptic IIR filter. Elliptic filters have a frequency response that is equiripple in both passband and stopband.

• `'equiripple'` designs an equiripple FIR filter using the Parks-McClellan algorithm. Equiripple filters have a frequency response that minimizes the maximum ripple magnitude over all bands.

• `'freqsamp'` designs an FIR filter of arbitrary magnitude response by sampling the frequency response uniformly and taking the inverse Fourier transform.

• `'kaiserwin'` designs an FIR filter using the Kaiser window method. The method truncates the impulse response of an ideal filter and uses a Kaiser window to attenuate the resulting truncation oscillations.

• `'ls'` designs an FIR filter using least squares. The method minimizes the discrepancy between a specified arbitrary piecewise-linear function and the filter’s magnitude response.

• `'maxflat'` designs a maximally flat FIR filter. These filters have a smooth monotonic frequency response that is maximally flat in the passband.

• `'window'` uses a least-squares approximation to compute the filter coefficients and then smooths the impulse response with `'``Window``'`.

Data Types: `char` | `string`

#### Design Method Options

collapse all

Window, specified as the comma-separated pair consisting of `'Window'` and a vector of length N + 1, where N is the filter order. `'Window'` can also be paired with a window name or function handle that specifies the function used to generate the window. Any such function must take N + 1 as first input. Additional inputs can be passed by specifying a cell array. By default, `'Window'` is an empty vector for the `'freqsamp'` design method and `@hamming` for the `'window'` design method.

For a list of available windows, see Windows.

Example: `'Window',hann(N+1)` and `'Window',(1-cos(2*pi*(0:N)'/N))/2` both specify a Hann window to use with a filter of order `N`.

Example: `'Window','hamming'` specifies a Hamming window of the required order.

Example: `'Window',@mywindow` lets you define your own window function.

Example: `'Window',{@kaiser,0.5}` specifies a Kaiser window of the required order with shape parameter 0.5.

Data Types: `double` | `char` | `string` | `function_handle` | `cell`

Band to match exactly, specified as the comma-separated pair consisting of `'MatchExactly'` and either `'stopband'`, `'passband'`, or `'both'`. `'both'` is available only for the elliptic design method, where it is the default. `'stopband'` is the default for the `'butter'` and `'cheby2'` methods. `'passband'` is the default for `'cheby1'`.

Data Types: `char` | `string`

Passband offset, specified as the comma-separated pair consisting of `'PassbandOffset'` and a positive scalar expressed in decibels. `'PassbandOffset'` specifies the filter gain in the passband.

Example: `'PassbandOffset',0` results in a filter with unit gain in the passband.

Example: `'PassbandOffset',2` results in a filter with a passband gain of 2 dB or 1.259.

Data Types: `double`

Scale passband, specified as the comma-separated pair consisting of `'ScalePassband'` and a logical scalar. When you set `'ScalePassband'` to `true`, the passband is scaled, after windowing, so that the filter has unit gain at zero frequency.

Example: `'Window',{@kaiser,0.1},'ScalePassband',true` help specify a filter whose magnitude response at zero frequency is exactly 0 dB. This is not the case when you specify `'ScalePassband',false`. To verify, visualize the filter with `fvtool` and zoom in.

Data Types: `logical`

Zero phase, specified as the comma-separated pair consisting of `'ZeroPhase'` and a logical scalar. When you set `'ZeroPhase'` to `true`, the zero-phase response of the resulting filter is always positive. This lets you perform spectral factorization on the result and obtain a minimum-phase filter from it.

Data Types: `logical`

Passband optimization weight, specified as the comma-separated pair consisting of `'PassbandWeight'` and a positive scalar.

`'PassbandWeight1'` is the lower-band passband optimization weight for a bandstop FIR design.

`'PassbandWeight2'` is the higher-band passband optimization weight for a bandstop FIR design.

Data Types: `double`

Stopband optimization weight, specified as the comma-separated pair consisting of `'StopbandWeight'` and a positive scalar.

`'StopbandWeight1'` is the lower-band stopband optimization weight for a bandpass FIR design.

`'StopbandWeight2'` is the higher-band stopband optimization weight for a bandpass FIR design.

Data Types: `double`

Optimization weights, specified as the comma-separated pair consisting of `'Weights'` and a positive scalar or a vector of the same length as `'Amplitudes'`.

Data Types: `double`

Multiband weights, specified as comma-separated pairs consisting of `'BandWeightsi'` and a set of positive scalars or of vectors. `'BandWeightsi'`, where i runs from 1 through `NumBands`, is a scalar or vector containing the optimization weights of the ith band of a multiband design. If specified as a vector, `'BandWeightsi'` must have the same length as `'BandAmplitudesi'`.

Data Types: `double`

#### Sample Rate

collapse all

Sample rate, specified as the comma-separated pair consisting of `'SampleRate'` and a positive scalar expressed in hertz. To work with normalized frequencies, set `'SampleRate'` to 2, or simply omit it.

Data Types: `double`

## Output Arguments

collapse all

Digital filter, returned as a `digitalFilter` object.

collapse all

### Filter Design Assistant

If you specify an incomplete or inconsistent set of design parameters, `designfilt` offers to open a Filter Design Assistant.

(In the argument description for `resp` there is a complete list of valid specification sets for all available response types.)

The assistant behaves differently if you call `designfilt` at the command line or within a script or function.

#### Filter Design Assistant at the Command Line

You are given a signal sampled at 2 kHz. You are asked to design a lowpass FIR filter that suppresses frequency components higher than 650 Hz. The “cutoff frequency” sounds like a good candidate for a specification parameter. At the MATLAB command line, you type the following.

```Fsamp = 2e3; Fctff = 650; dee = designfilt('lowpassfir','CutoffFrequency',Fctff, ... 'SampleRate',Fsamp);```

Something seems to be amiss because this dialog box appears on your screen.

You click and get a new dialog box that offers to generate code. You see that the variables you defined before have been inserted where expected.

After exploring some of the options offered, you decide to test the corrected filter. You click and get the following code on the command line.

```dee = designfilt('lowpassfir', 'FilterOrder', 10, ... 'CutoffFrequency', Fctff, 'SampleRate', Fsamp);```

Typing the name of the filter reiterates the information from the dialog box.

```dee ```
```dee = digitalFilter with properties: Coefficients: [1x11 double] Specifications: FrequencyResponse: 'lowpass' ImpulseResponse: 'fir' SampleRate: 2000 FilterOrder: 10 CutoffFrequency: 650 DesignMethod: 'window' Use fvtool to visualize filter Use filter function to filter data```

You invoke FVTool and get a plot of `dee`’s frequency response.

`fvtool(dee)`

The cutoff does not look particularly sharp. The response is above 40 dB for most frequencies. You remember that the assistant had an option to set up a “magnitude constraint” called the “stopband attenuation”. Open the assistant by calling `designfilt` with the filter name as input.

`designfilt(dee)`

Click the `Magnitude constraints` drop-down menu and select `Passband ripple and stopband attenuation`. You see that the design method has changed from `Window` to ```FIR constrained least-squares```. The default value for the attenuation is 60 dB, which is higher than 40. Click and visualize the resulting filter.

```dee = designfilt('lowpassfir', 'FilterOrder', 10, ... 'CutoffFrequency', Fctff, ... 'PassbandRipple', 1, 'StopbandAttenuation', 60, ... 'SampleRate', Fsamp); fvtool(dee)```

The cutoff still does not look sharp. The attenuation is indeed 60 dB, but for frequencies above 900 Hz.

Again invoke `designfilt` with your filter as input.

`designfilt(dee)`

The assistant reappears.

To narrow the distinction between accepted and rejected frequencies, increase the order of the filter or change ```Frequency constraints``` from `Cutoff (6dB) frequency` to ```Passband and stopband frequencies```. If you change the filter order from 10 to 50, you get a sharper filter.

```dee = designfilt('lowpassfir', 'FilterOrder', 50, ... 'CutoffFrequency', 650, ... 'PassbandRipple', 1, 'StopbandAttenuation', 60, ... 'SampleRate', 2000); fvtool(dee)```

A little experimentation shows that you can obtain a similar filter by setting the passband and stopband frequencies respectively to 600 Hz and 700 Hz.

```dee = designfilt('lowpassfir', 'PassbandFrequency', 600, ... 'StopbandFrequency', 700, ... 'PassbandRipple', 1, 'StopbandAttenuation', 60, ... 'SampleRate', 2000); fvtool(dee)```

#### Filter Design Assistant in a Script or Function

You are given a signal sampled at 2 kHz. You are asked to design a highpass filter that stops frequencies below 700 Hz. You don’t care about the phase of the signal, and you need to work with a low-order filter. Thus an IIR filter seems adequate. You are not sure what filter order is best, so you write a function that accepts the order as input. Open the MATLAB Editor and create the file.

```function dataOut = hipassfilt(N,dataIn) hpFilter = designfilt('highpassiir','FilterOrder',N); dataOut = filter(hpFilter,dataIn); end```

To test your function, create a signal composed of two sinusoids with frequencies 500 and 800 Hz and generate samples for 0.1 s. A 5th-order filter seems reasonable as an initial guess. Create a script called `driveHPfilt.m`.

```% script driveHPfilt.m Fsamp = 2e3; Fsm = 500; Fbg = 800; t = 0:1/Fsamp:0.1; sgin = sin(2*pi*Fsm*t)+sin(2*pi*Fbg*t); Order = 5; sgout = hipassfilt(Order,sgin);```

When you run the script at the command line, you get an error message.

The error message gives you the choice of opening an assistant to correct the MATLAB code. Click `Click here` to get the Filter Design Assistant on your screen.

You see the problem: You did not specify the frequency constraint. You also forgot to set a sample rate. After experimenting, you find that you can specify Frequency units as `Hz`, Passband frequency equal to 700 Hz, and Input Fs equal to 2000 Hz. The Design method changes from `Butterworth` to ```Chebyshev type I```. You click and get the following.

The assistant has correctly identified the file where you call `designfilt`. Click to accept the change. The function has the corrected MATLAB code.

```function dataOut = hipassfilt(N,dataIn) % hpFilter = designfilt('highpassiir','FilterOrder',N); hpFilter = designfilt('highpassiir', 'FilterOrder', N, ... 'PassbandFrequency', 700, 'PassbandRipple', 1, ... 'SampleRate', 2000); dataOut = filter(hpFilter,dataIn); end```

You can now run the script with different values of the filter order. Depending on your design constraints, you can change your specification set.

#### Filter Design Assistant Preferences

You can set `designfilt` to never offer the Filter Design Assistant. This action sets a MATLAB preference that can be unset with `setpref`:

• Use `setpref('dontshowmeagain','filterDesignAssistant',false)` to be offered the assistant every time. With this command, you can get the assistant again after having disabled it.

• Use `setpref('dontshowmeagain','filterDesignAssistant',true)` to disable the assistant permanently. You can also click in the initial dialog box.

You can set `designfilt` to always correct faulty specifications without asking. This action sets a MATLAB preference that can be unset by using `setpref`:

• Use `setpref('dontshowmeagain','filterDesignAssistantCodeCorrection',false)` to have `designfilt` correct your MATLAB code without asking for confirmation. You can also click in the confirmation dialog box.

• Use `setpref('dontshowmeagain','filterDesignAssistantCodeCorrection',true)` to ensure that `designfilt` corrects your MATLAB code only when you confirm you want the changes. With this command, you can undo the effect of having clicked in the confirmation dialog box.

### Troubleshooting

There are some instances in which, given an invalid set of specifications, `designfilt` does not offer a Filter Design Assistant, either through a dialog box or through a link in an error message.

• You are not offered an assistant if you use code-section evaluation, either from the MATLAB Toolstrip or by pressing Ctrl+Enter. (See Divide Your File into Code Sections (MATLAB) for more information.)

• You are not offered an assistant if your code has multiple calls to `designfilt`, at least one of those calls is incorrect, and

• You paste the code on the command line and execute it by pressing Enter.

• You select the code in the Editor and execute it by pressing F9.

• You are not offered an assistant if you run `designfilt` using an anonymous function. (See Anonymous Functions (MATLAB) for more information.) For example, this input offers an assistant.

`d = designfilt('lowpassfir','CutoffFrequency',0.6)`
This input does not.
```myFilterDesigner = @designfilt; d = myFilterDesigner('lowpassfir','CutoffFrequency',0.6)```

• You are not offered an assistant if you run `designfilt` using `eval`. For example, this input offers an assistant.

`d = designfilt('lowpassfir','CutoffFrequency',0.6)`
This input does not.
```myFilterDesigner = ... sprintf('designfilt(''%s'',''CutoffFrequency'',%f)', ... 'lowpassfir',0.6); d = eval(myFilterDesigner)```

The Filter Design Assistant requires Java® software and the MATLAB desktop to run. It is not supported if you run MATLAB with the `-nojvm`, `-nodisplay`, or `-nodesktop` options.