designfilt - Design digital filter - MATLAB (original) (raw)

designfilt no longer assists in correcting calls to the function within a script or function. For more information, see Version History.

Syntax

Description

[d](designfilt.html#bt61003-d-dup1) = designfilt([resp](#bt61003-resp),[Name,Value](#namevaluepairarguments)) designs a digitalFilter object or a filter System object™ with response type resp. Examples of resp are'lowpassfir' and 'bandstopiir'. Specify the filter further using a set of Name-Value Arguments. The allowed specification sets depend onresp and consist of combinations of these:

Note

If you specify an incomplete or inconsistent set of name-value arguments 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 to 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 and pastes the corrected MATLAB code on the command line. The designed filter is saved to the workspace.

example

designfilt([d](designfilt.html#bt61003-d)) lets you edit an existing digital filter d. It opens a Filter Design Assistant populated with the filter 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

Since R2023b

Design a lowpass FIR filter using the designfilt function.

The filter is a minimum order filter with a passband frequency of 0.45 and a stopband frequency of 0.55 in normalized frequency units. The passband ripple is 1 dB and the stopband attenuation is 60 dB. Use the Kaiser window design method and set the SystemObject argument to true.

With these specifications, the designfilt function generates a dsp.FIRFilter System object™.

lpFIRFilter = designfilt("lowpassfir", ... PassbandFrequency=0.45,StopbandFrequency=0.55, ... PassbandRipple=1,StopbandAttenuation=60, ... DesignMethod="kaiserwin",SystemObject=true)

lpFIRFilter = dsp.FIRFilter with properties:

        Structure: 'Direct form'
  NumeratorSource: 'Property'
        Numerator: [1.2573e-04 -1.9141e-04 -2.7282e-04 3.7207e-04 4.9141e-04 -6.3325e-04 -8.0016e-04 9.9490e-04 0.0012 -0.0015 -0.0018 0.0021 0.0025 -0.0029 -0.0034 0.0040 0.0046 -0.0053 -0.0060 0.0069 0.0079 -0.0090 -0.0102 0.0116 … ] (1×74 double)
InitialConditions: 0

Show all properties

Visualize the magnitude and phase responses of this filter using freqz.

freqz(lpFIRFilter.Numerator)

Figure contains 2 axes objects. Axes object 1 with title Phase, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Phase (degrees) contains an object of type line. Axes object 2 with title Magnitude, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Magnitude (dB) contains an object of type line.

Since R2023b

Design a highpass IIR filter using the designfilt function.

The filter is a 20th order highpass IIR filter with a sample rate of 44.1 kHz. The stopband frequency of the filter is 3 kHz and the passband frequency is 8 kHz. Use the IIR least p-norm design method and set the _L_-infinity norm to 120. Set the SystemObject argument to true.

With these specifications, the designfilt function generates a dsp.SOSFilter System object™.

hpIIRFilter = designfilt('highpassiir', ... FilterOrder=20,StopbandFrequency=3000, ... PassbandFrequency=8000,SampleRate=44100, ... Norm=120,SystemObject=true)

hpIIRFilter = dsp.SOSFilter with properties:

        Structure: 'Direct form II'
CoefficientSource: 'Property'
        Numerator: [10×3 double]
      Denominator: [10×3 double]
   HasScaleValues: true
      ScaleValues: [0.5812 1 1 1 1 1 1 1 1 1 14.8291]

Show all properties

Visualize the frequency response of this filter.

freqz(hpIIRFilter,[],44100)

Figure contains 2 axes objects. Axes object 1 with title Phase, xlabel Frequency (kHz), ylabel Phase (degrees) contains an object of type line. Axes object 2 with title Magnitude, xlabel Frequency (kHz), ylabel Magnitude (dB) contains an object of type line.

Input Arguments

collapse all

Filter response and type, specified as a character vector or string scalar.

Select this option to design a finite impulse response (FIR) lowpass filter. This example uses the fifth specification set from the table.

d = designfilt('lowpassfir', ... % Response type 'FilterOrder',25, ... % Filter order 'PassbandFrequency',400, ... % Frequency constraints 'StopbandFrequency',550, ... 'DesignMethod','ls', ... % Design method 'PassbandWeight',1, ... % Design method options 'StopbandWeight',2, ... 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2023b)

Select this option to design an infinite impulse response (IIR) lowpass filter. This example uses the first specification set from the table.

d = designfilt('lowpassiir', ... % Response type 'PassbandFrequency',400, ... % Frequency constraints 'StopbandFrequency',550, ... 'PassbandRipple',4, ... % Magnitude constraints 'StopbandAttenuation',55, ... 'DesignMethod','ellip', ... % Design method 'MatchExactly','passband', ... % Design method options 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2023b)

Since R2025a

Select this option to design an inverse sinc lowpass finite impulse response (FIR) filter. This example uses the first specification set from the table.

d = designfilt('isinclpfir', ... % Response type 'PassbandFrequency',0.45, ... % Frequency constraints 'StopbandFrequency',0.55 , ... 'PassbandRipple',1, ... 'StopbandAttenuation',60, ... 'DesignMethod','equiripple', ... % Design method 'DensityFactor',16, ... % Design options 'MinOrder','any', ... 'StopbandShape','flat', ... 'SincFrequencyFactor',0.5, ... 'SincPower',1, ... 'PhaseConstraint','linear',... 'SystemObject',true)

Select this option to design a finite impulse response (FIR) highpass filter. This example uses the first specification set from the table.

d = designfilt('highpassfir', ... % Response type 'StopbandFrequency',400, ... % Frequency constraints 'PassbandFrequency',550, ... 'StopbandAttenuation',55, ... % Magnitude constraints 'PassbandRipple',4, ... 'DesignMethod','kaiserwin', ... % Design method 'ScalePassband',false, ... % Design method options 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2023b)

Select this option to design an infinite impulse response (IIR) highpass filter. This example uses the first specification set from the table.

d = designfilt('highpassiir', ... % Response type 'StopbandFrequency',400, ... % Frequency constraints 'PassbandFrequency',550, ... 'StopbandAttenuation',55, ... % Magnitude constraints 'PassbandRipple',4, ... 'DesignMethod','cheby1', ... % Design method 'MatchExactly','stopband', ... % Design method options 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2023b)

Since R2025a

Select this option to design an inverse sinc highpass finite impulse response (FIR) filter. This example uses the first specification set from the table.

d = designfilt('isinchpfir', ... % Response type 'StopbandFrequency',0.45 , ... % Frequency constraints 'PassbandFrequency',0.55, ...
'PassbandRipple',1, ... % Magnitude constraints 'StopbandAttenuation',60, ... 'DesignMethod','equiripple', ... % Design method 'DensityFactor',16, ... % Design options 'MinOrder','any', ... 'StopbandShape','flat', ... 'SincFrequencyFactor',0.5, ... 'SincPower',1, ... 'PhaseConstraint','linear',... 'SystemObject',true)

Select this option to design a finite impulse response (FIR) bandpass filter. This example uses the fourth specification set from the table.

d = designfilt('bandpassfir', ... % Response type 'FilterOrder',86, ... % Filter order 'StopbandFrequency1',400, ... % Frequency constraints 'PassbandFrequency1',450, ... 'PassbandFrequency2',600, ... 'StopbandFrequency2',650, ... 'DesignMethod','ls', ... % Design method 'StopbandWeight1',1, ... % Design method options 'PassbandWeight', 2, ... 'StopbandWeight2',3, ... 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2024a)

Select this option to design an infinite impulse response (IIR) bandpass filter. This example uses the first specification set from the table.

d = designfilt('bandpassiir', ... % Response type 'StopbandFrequency1',400, ... % Frequency constraints 'PassbandFrequency1',450, ... 'PassbandFrequency2',600, ... 'StopbandFrequency2',650, ... 'StopbandAttenuation1',40, ... % Magnitude constraints 'PassbandRipple',1, ... 'StopbandAttenuation2',50, ... 'DesignMethod','ellip', ... % Design method 'MatchExactly','passband', ... % Design method options 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2024a)

Select this option to design a finite impulse response (FIR) bandstop filter. This example uses the fourth specification set from the table.

d = designfilt('bandstopfir', ... % Response type 'FilterOrder',32, ... % Filter order 'PassbandFrequency1',400, ... % Frequency constraints 'StopbandFrequency1',500, ... 'StopbandFrequency2',700, ... 'PassbandFrequency2',850, ... 'DesignMethod','ls', ... % Design method 'PassbandWeight1',1, ... % Design method options 'StopbandWeight', 3, ... 'PassbandWeight2',5, ... 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2024a)

Select this option to design an infinite impulse response (IIR) bandstop filter. This example uses the first specification set from the table.

d = designfilt('bandstopiir', ... % Response type 'PassbandFrequency1',400, ... % Frequency constraints 'StopbandFrequency1',500, ... 'StopbandFrequency2',700, ... 'PassbandFrequency2',850, ... 'PassbandRipple1',1, ... % Magnitude constraints 'StopbandAttenuation',55, ... 'PassbandRipple2',1, ... 'DesignMethod','ellip', ... % Design method 'MatchExactly','both', ... % Design method options 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2024a)

Since R2025a

Select this option to design a multi-notch IIR filter. This example uses the second specification set from the table.

d = designfilt('notchiir', ... 'FilterOrder',[6 6],'CenterFrequency',[2.5 7.5], ... 'QualityFactor',[2.5 7.5],'PassbandRipple',1, ... 'SampleRate',20,'SystemObject',true);

Here is an example that designs a notching comb filter.

d = designfilt('notchiir', ... 'NumNotches',10,'NotchLocations','Harmonic',... 'Bandwidth',0.125,'BandwidthGain',-3,... 'ShelvingFilterOrder',1,'SystemObject',true);

Since R2025a

Select this option to design a multi-peak IIR filter. This example uses the second specification set from the table.

d = designfilt('peakiir', ... 'FilterOrder',[6 6],'CenterFrequency',[2.5 7.5], ... 'QualityFactor',[2.5 7.5],'PassbandRipple',1, ... 'SampleRate',20,'SystemObject',true);

Here is an example that designs a peaking comb filter.

d = designfilt('peakiir', ... 'NumPeaks',10,'PeakLocations','Harmonic',... 'Bandwidth',0.125,'BandwidthGain',-3,... 'ShelvingFilterOrder',1,'SystemObject',true);

Select this option to design a finite impulse response (FIR) differentiator filter. This example uses the second specification set from the table.

d = designfilt('differentiatorfir', ... % Response type 'FilterOrder',42, ... % Filter order 'PassbandFrequency',400, ... % Frequency constraints 'StopbandFrequency',500, ... 'DesignMethod','equiripple', ... % Design method 'PassbandWeight',1, ... % Design method options 'StopbandWeight',4, ... 'SampleRate',2000) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2025a)

Select this option to design a finite impulse response (FIR) Hilbert transformer filter. This example uses the specification set from the table.

d = designfilt('hilbertfir', ... % Response type 'FilterOrder',12, ... % Filter order 'TransitionWidth',400, ... % Frequency constraints 'DesignMethod','ls', ... % Design method 'SampleRate',2000) % Sample rate

Filter Order Argument Names Frequency Constraint Argument Names Magnitude Constraint Argument Names 'DesignMethod' Argument Values Design Option Argument Names
'FilterOrder' 'TransitionWidth' N/A 'equiripple' (default) N/A
'ls' N/A

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2025a)

Select this option to design a finite impulse response (FIR) filter of arbitrary magnitude response. This example uses the second specification set from the table.

d = designfilt('arbmagfir', ... % Response type 'FilterOrder',88, ... % Filter order 'NumBands',4, ... % Frequency constraints 'BandFrequencies1',[0 20], ... 'BandFrequencies2',[25 40], ... 'BandFrequencies3',[45 65], ... 'BandFrequencies4',[70 100], ... 'BandAmplitudes1',[2 2], ... % Magnitude constraints 'BandAmplitudes2',[0 0], ... 'BandAmplitudes3',[1 1], ... 'BandAmplitudes4',[0 0], ... 'DesignMethod','ls', ... % Design method 'BandWeights1',[1 1]/10, ... % Design method options 'BandWeights2',[3 1], ... 'BandWeights3',[2 4], ... 'BandWeights4',[5 1], ... 'SampleRate',200) % Sample rate

If you have a DSP System Toolbox license, the designfilt function supports these additional design specifications. (since R2025a)

Since R2025a

Select this option to design an infinite impulse response (IIR) filter of arbitrary magnitude response. This example uses the first specification set from the table.

d = designfilt('arbmagiir', ... 'FilterOrder',20,'Frequencies',linspace(0,1,30),... 'Amplitudes',[ones(1,7) zeros(1,8) ones(1,8) zeros(1,7)],... 'SystemObject',true);

Since R2025a

Select this option to design a finite impulse response (FIR) filter of arbitrary magnitude and phase responses. This example uses the second specification set from the table.

d = designfilt('arbmagnphasefir', ... 'FilterOrder',20,'NumBands',2, ... 'BandFrequencies1',[0 0.25],... 'BandFrequencyResponse1',exp(-12jpilinspace(0,... 1,2)),'BandFrequencies2',[0.5 0.75], ... 'BandFrequencyResponse2',exp(-12jpilinspace(0,1,2)), ... 'SystemObject',true);

Since R2025a

Select this option to design an infinite impulse response (IIR) filter of arbitrary magnitude and phase responses. This example uses the specification set from the table.

d = designfilt('arbmagnphaseiir', ... 'FilterOrder',20,... 'Frequencies',[0 0.25 1],... 'FrequencyResponse',[complex(1,2) complex(3,4) complex(5,6)],... 'DesignMethod','ls',... 'SystemObject',true)

Since R2025a

Select this option to design an infinite impulse response (IIR) filter of arbitrary group delay. This example uses the first specification set from the table.

d = designfilt('arbgrpdelayiir', ... 'FilterOrder',20,'Frequencies',linspace(0,1,30),... 'GroupDelayResponse',[10*ones(1,15) linspace(10,1,15)],... 'SystemObject',true);

Since R2025a

Select this option to design a fractional delay FIR filter.

d = designfilt('fracdelayfir', ... 'FilterOrder',45,'FractionalDelay',0.6,... 'SampleRate',20,'SystemObject',true);

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 Arguments

expand all

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

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

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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

Not all name-value combinations are valid. The valid combinations depend on the filter response that you need and on the frequency and magnitude constraints of your design.

Sample Rate

expand all

Sample rate, specified as a positive scalar expressed in hertz. To work with normalized frequencies, set 'SampleRate' to 2, or simply omit it.

Data Types: double

Filter Order

expand all

Filter order, N, specified as a positive integer.

Data Types: double

Numerator order for IIR filters, specified as a positive integer.

Data Types: double

Denominator order for IIR filters, specified as a positive integer.

Data Types: double

Since R2025a

Source of notch frequencies, specified as one of these:

Dependencies

This property applies only when you set the filter response to'notchiir'.

Data Types: double

Since R2025a

Number of harmonic notches in the two-sided spectrum, specified as a positive integer. The function uses this value to determine the number of harmonically related notch frequencies in the comb filter.

Dependencies

This property applies only when you set the filter response to'notchiir' andNotchLocations to'Harmonic'.

Data Types: double

Since R2025a

Source of peak frequencies, specified as one of these:

Dependencies

This property applies only when you set the filter response to'peakiir'.

Data Types: double

Since R2025a

Number of harmonic peaks in the two-sided spectrum, specified as a positive integer. The function uses this value to determine the number of harmonically related peak frequencies in the comb filter.

Dependencies

This property applies only when you set the filter response to'peakiir' andPeakLocations to'Harmonic'.

Data Types: double

Since R2025a

Shelving filter order _N_sh, specified as a positive integer. The shelving filter order determines the sharpness of the peaks or notches. The greater the value of the shelving filter order, the steeper the slope of the peak or notch. The order of the notching or peaking filter is given by_L_×_N_sh, where L is the number of notches or peaks you specify using NumNotches orNumPeaks.

Dependencies

This property applies only when you set:

Data Types: double

Frequency Constraints

expand all

Passband frequency, specified as 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 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 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 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

Bandwidth of the filter passband in normalized frequency units, specified as a positive scalar less than the difference between'HalfPowerFrequency2' and 'HalfPowerFrequency1'.

Dependencies

This property applies only if you set the filter response to'bandpassiir' or'bandstopiir'.

Data Types: double

Frequency width between the two stopband frequencies, specified as a positive scalar.

Dependencies

This property applies only if you set the filter response to'bandpassiir' or'bandstopiir'.

Data Types: double

Width of the transition region between passband and stopband for a Hilbert transformer, specified as a positive scalar.

Data Types: double

Response frequencies, specified as a vector. Use this variable to list the frequencies at which a filter of arbitrary magnitude and phase responses has desired amplitudes and phase values. The frequencies must be monotonically increasing and lie within the Nyquist range. The first element of the vector must be either 0 or –_f_s/2, where _f_s is the sample rate, and its last element must be _f_s/2. If you do not specify a sample rate,designfilt uses the default value of 2 Hz.

Data Types: double

Since R2025a

Frequency response values, specified as a vector. Use this variable to specify the arbitrary magnitude and phase response values at the frequencies you specify in the 'Frequencies' argument. The length of this vector must equal the length of the'Frequencies' vector.

Data Types: double
Complex Number Support: Yes

Since R2025a

Group delay response values, specified as a vector. Use this variable to specify the group delay response values at the frequencies you specify in the 'Frequencies' argument. The length of this vector must equal the length of the'Frequencies' vector.

Data Types: double

Number of bands in a multiband design, specified as a positive integer scalar not greater than 10.

Data Types: double

Multiband response frequencies, specified as numeric vectors.'BandFrequenciesi', where i runs from 1 through 'NumBands', is a vector containing the frequencies at which the _i_th band of a multiband design has the desired values,'BandAmplitudesi','BandFrequencyResponsei','BandGroupDelayResponsei'.'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

Since R2025a

Multiband frequency response values, specified as numeric vectors.'BandFrequencyResponsei', where i runs from 1 through 'NumBands', is a vector containing the frequency response values in the _i_th band specified at the frequency values given by'BandFrequenciesi'.'NumBands' can be at most 10.

Data Types: double
Complex Number Support: Yes

Since R2025a

Multiband group delay response values, specified as numeric vectors.'BandGroupDelayResponsei', where i runs from 1 through 'NumBands', is a vector containing the group delay response values in the _i_th band specified at the frequency values given by'BandFrequenciesi'.'NumBands' can be at most 10.

Data Types: double

Since R2025a

Center frequency _f_0 of the notch or peak IIR filter, specified as a scalar or a vector. The center frequency values must be in the range 0 <_f_0 <_f_s/2.

When specified as a vector, the length of this argument must be equal to the length of the FilterOrder andQualityFactor arguments. If you specify the input sample rate through the SampleRate property, then specify the value of the center frequency in Hz.

Dependencies

This property applies only when you set the filter response to'notchiir' or'peakiir'.

Data Types: double

Since R2025a

Quality factor q of the notch or peak IIR filter, specified as a positive scalar or a vector. When specified as a vector, the length of this argument must be equal to the length of theCenterFrequency argument.

Quality factor of the filter is defined as the ratio of the lowest center frequency of the peak or notch_f_0 (not including DC) to the 3 dB bandwidth BW calculated at the −3 dB point, and is given by q =_f_0/BW.

Dependencies

This property applies only when you set the filter response to'notchiir' or'peakiir'.

Data Types: double

Since R2025a

3-dB bandwidth BW of the notch or peak IIR filter, specified as a scalar or a vector.

When you set NotchLocations orPeakLocations to:

By default, the function calculates the bandwidth at the point –3 dB from the center frequency of the peak or notch. For example, setting_BW_ to 0.01 specifies that the –3 dB point will be +/− 0.005 (in normalized frequency) from the center of the notch or peak.

Dependencies

This property applies only when you set the filter response to'notchiir' or'peakiir'.

Data Types: double

Since R2025a

Target combined bandwidth, specified as a positive scalar less than 0.999×_f_s/2, where_f_s is the input sample rate. This is the value of the combined bandwidth that the design must satisfy. Combined bandwidth is defined as the minimum of the gain bandwidth and the group delay bandwidth.

Specifying both filter length and target combined bandwidth results in an overdetermined design. The filter design does not support specifying both values. When you specify the target combined bandwidth, the algorithm determines the corresponding filter length and designs the filter accordingly.

Specify a higher target combined bandwidth for a longer filter. For example, setting the bandwidth to 0.9 ×_f_s/2 yields a filter of length of 52, while increasing the bandwidth to 0.99 ×_f_s/2 yields a length of 724, which is more than 10 times longer. As bandwidth tends towards_f_s/2, the filter length theoretically tends towards infinity.

Dependencies

This property applies only when you set the filter response to'fracdelayfir'.

Data Types: double

Magnitude Constraints

expand all

Passband ripple, specified as 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 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

Since R2024a

Option to constrain passband ripple, specified as a logical value.

Set 'Passband1Constrained' totrue to constrain the first passband ripple in the bandstop FIR filter.

Set 'Passband2Constrained' totrue to constrain the second passband ripple in the bandstop FIR filter.

Set 'PassbandConstrained' totrue to constrain the passband ripple in the bandpass FIR filter.

Data Types: logical

Since R2024a

Option to constrain stopband attenuation, specified as a logical value.

Set 'Stopband1Constrained' totrue to constrain the first stopband attenuation in the bandpass FIR filter.

Set 'Stopband2Constrained' totrue to constrain the second stopband attenuation in the bandpass FIR filter.

Set 'StopbandConstrained' totrue to constrain the stopband attenuation in the bandstop FIR filter.

Data Types: logical

Desired response amplitudes of an arbitrary magnitude response filter, specified as 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 numeric vectors.'BandAmplitudesi', where i runs from 1 through 'NumBands', is a vector containing the desired amplitudes in the _i_th 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

Since R2025a

Multiband constrained flag, specified as logical vectors. This property enables you to constrain the passband ripple in your multiband design. You cannot constrain the passband ripple in all bands simultaneously. 'BandConstrainedi', where i runs from 1 through 'NumBands', is a vector that specifies if the corresponding _i_th band of a multiband design is constrained or not.'NumBands' can be at most 10.'BandConstrainedi' must have the same length as'BandAmplitudesi' and'BandFrequenciesi'.

Data Types: logical

Since R2025a

Multiband response passband ripples, specified as sets of positive scalars or of vectors. 'BandRipplei', where i runs from 1 through 'NumBands', is a scalar or vector containing the desired passband ripple of the _i_th band of a multiband design.'NumBands' can be at most 10. If specified as a vector, 'BandRipplei' must have the same length as'BandAmplitudesi' and'BandFrequenciesi'.

Data Types: double

Since R2025a

Gain at which the bandwidth is measured, specified as a scalar. This property allows you specify the bandwidth of the notch or peak at a gain different from the –3 dB default.

Dependencies

This property applies only when you set:

Data Types: double

Design Method

expand all

Design method, specified as a character vector or string scalar. The choice of design method depends on the set of frequency and magnitude constraints that you specify.

Data Types: char | string

Design Method Options

expand all

Since R2025a

Type of the linear-phase FIR filter, specified as one of these:

Dependencies

This property applies only when you set the filter response to'hilbertfir'.

Data Types: char | string

Minimum order parity of a 'kaiserwin' design or an'equiripple' design, specified as'any', 'even', or'odd'.

When you set 'MinOrder' to:

Data Types: char | string

Window, specified as 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 orderN.

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 '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

Since R2023b

_L_-infinity norm, specified as a positive scalar.

Dependencies

This property applies only when you setDesignMethod to'lpnorm'.

Data Types: double

Since R2025a

Density of the frequency grid, specified as a positive scalar ≥ 10. The frequency grid has roughly (DensityFactor ×FilterOrder)/(2 ×Passbandfrequency) frequency points. Increasing the density factor results in filters that more exactly match an equiripple filter, but that take longer to compute.

Data Types: double

Since R2025a

Maximum pole radius, specified as a scalar in the range (0,1]. This value indicates the maximum radius of each pole in the pole/zero plot of the designed filter.

Dependencies

This property applies only when you setDesignMethod to'lpnorm'.

Data Types: double

Since R2025a

Initial _P_th norm used by the'lpnorm' algorithm, specified as a positive scalar. Starting the optimization with a smaller initial value aids in the convergence of the algorithm. For more information, see Least Pth-Norm Optimal IIR Filter Design.

Dependencies

This property applies only when you setDesignMethod to'lpnorm'.

Data Types: double

Since R2025a

Initial estimate of the filter order, specified as a positive integer.

Dependencies

This property applies only when you specify the filter response to'arbmagfir'.

Data Types: double

Since R2025a

Initial estimate of the filter numerator coefficients, specified as a vector of size (N+1)-by-1, where N is the filter order that you specify in theFilterOrder argument.

Dependencies

This property applies only when you setDesignMethod to'lpnorm'.

Data Types: double

Since R2025a

Initial estimate of the filter denominator coefficients, specified as a vector of size (N+1)-by-1, where_N_ is the filter order that you specify in theFilterOrder argument.

Dependencies

This property applies only when you setDesignMethod to'lpnorm'.

Data Types: double

Since R2025a

Interpolation factor used by the interpolated FIR filter design algorithm, specified as a positive integer ≥ 1.

Dependencies

This property applies only when you setDesignMethod to'ifir'.

Data Types: double

Since R2025a

Set this property to true to enable both design speed and filter order optimization.

Dependencies

This property applies only when you setDesignMethod to'ifir'.

Data Types: logical

Passband offset, specified as 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 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 Filter Analyzer and zoom in.

Data Types: logical

Zero phase, specified as 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

Since R2025a

Shape of the stopband of the equiripple FIR filter, specified as one of these options:

decay is the value you specify in theStopbandDecay property.

Data Types: char | string

Since R2025a

Stopband decay, specified as a real scalar. When theStopbandShape property is set to one of these options:

Data Types: double

Since R2025a

Sinc frequency factor, specified as a positive scalar. The magnitude response of the equiripple FIR filter has the shape of an inverse sinc function, 1/sinc(C ×π ×F)P.

The inverse sinc shape compensates for the sinc-like responses in the frequency domain such as the effect of the zero-order hold in a D/A converter. The amount of compensation in the passband is controlled by the C and P arguments.

Data Types: double

Since R2025a

Sinc power P, specified as a positive scalar. This value specifies the power to which the inverse sinc function is raised.

The magnitude response of the equiripple FIR filter is given by 1/sinc(C ×π ×F)P

where,

Data Types: double

Since R2024a

Phase constraint on the equiripple FIR filter, specified as one of these options:

Data Types: char | string

Passband optimization weight, specified as 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 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 a positive scalar or a vector of the same length as 'Amplitudes'.

Data Types: double

Multiband weights, specified as sets 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 _i_th band of a multiband design. If specified as a vector, 'BandWeightsi' must have the same length as'BandAmplitudesi'.

Data Types: double

Since R2025a

Force the magnitude response at specified frequencies in the multiband design to 0 dB, specified as sets of positive scalars or vectors.'BandForcedFrequencyPointsi', where i runs from 1 through 'NumBands', is a scalar or a vector containing the frequencies in each band at which to force the magnitude response to 0 dB. If specified as a vector,'BandForcedFrequencyPointsi' must have the same length as 'BandWeightsi'.

Data Types: double

Since R2025a

Option to specify the frequency grid as uniform in the equiripple filter design, specified as a logical scalar. When you set this property to true, the function spaces the frequency grid points uniformly in the frequency bands of interest. The density of the uniform grid is controlled by the DensityFactor argument

Data Types: logical

Since R2025a

Fractional delay of the filter in samples, specified as a real scalar in the range [0,1].

When you set FractionalDelay to0 or 1, the designed filter has a full bandwidth.

Dependencies

This property applies only when you set the filter response to'fracdelayfir'.

Data Types: double

Implementation

expand all

Since R2023b

When you set this property to:

Data Types: logical

Output Arguments

collapse all

Digital filter, returned as one of these:

More About

collapse all

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. You type this code at the MATLAB command line.

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

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

Filter Design Assistant dialog window

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

Filter Design Assistant dialog for lowpass FIR design

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

designfilt("lowpassfir",FilterOrder=10, ... CutoffFrequency=Fctff,SampleRate=2000);

You invoke Filter Analyzer and get a frequency response plot.

Magnitude response plot using Filter Analyzer

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.

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

dee = designfilt('lowpassfir','FilterOrder',10, ... 'CutoffFrequency',650,'PassbandRipple',1, ... 'StopbandAttenuation',60,'SampleRate',2000); filterAnalyzer(dee)

Magnitude response with passband ripple and stopband attenuation using Filter Analyzer

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.

The assistant reappears.

Filter Design Assistant dialog for modified lowpass FIR design

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); filterAnalyzer(dee)

Magnitude response with increased filter order using Filter Analyzer

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','FilterOrder',50,... 'PassbandFrequency',600,'StopbandFrequency',700,... 'PassbandRipple',1,'StopbandAttenuation',60,... 'SampleRate',2000); filterAnalyzer(dee)

Magnitude response with modified passband and stopband frequencies using Filter Analyzer

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 fifth-order filter seems reasonable as an initial guess. Create a script calleddriveHPfilt.m.

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

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

Error message display for

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.

Filter Design Assistant dialog for highpass IIR design

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 specifyFrequency units as Hz,Input Fs equal to 2000 Hz, Frequency constraints to Passband frequency, andPassband frequency to 700 Hz. The Design method changes from Butterworth toChebyshev type I. You clickOK and get this on the command line.

hp = designfilt('highpassiir','FilterOrder',N, ... 'PassbandFrequency',700,'PassbandRipple',1, ... 'SampleRate',2000);

The new digitalFilter object hp is saved to the workspace. Depending on your design constraints, you can change your specification set.

Filter Design Assistant Settings

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

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

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.

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.

Version History

Introduced in R2014a

expand all

If you have a DSP System Toolbox license, the designfilt function supports additional filter design specifications in these filter responses:

Filter Design Assistant now supports all the filter design settings which are available with a DSP System Toolbox license.

Starting in R2024a, if you have a DSP System Toolbox license, you can set the SystemObject argument totrue to generate a dsp.FIRFilter object for the 'bandpassfir' and'bandstopfir' filter responses, and a dsp.SOSFilter object for the 'bandpassiir' and'bandstopiir' filter responses.

If you have a DSP System Toolbox license, the 'lowpassfir' and 'highpassfir' filter responses support these additional filter design specifications.

If you have a DSP System Toolbox license, you can use the new 'PhaseConstraint' design method option to design a linear-phase, minimum-phase, or maximum-phase equiripple FIR filter. For more information on when you can use this design method option, see the description for 'lowpassfir', 'highpassfir', 'bandpassfir', and 'bandstopfir' filter responses.

The designfilt function enables these features when you install DSP System Toolbox:

Starting in R2021b, the designfilt function no longer assists in correcting calls to designfilt within a script or function. In previous releases, the function automatically corrected and executed code on the command line.

You do not need to make any changes to your code. If the call todesignfilt contains an error, the function issues an error with a link to open the Filter Design Assistant. You can use the assistant to generate a filter and display the corresponding code on the command line. The generated filter object is saved to the workspace.