designfilt
Design a digital filter or implement a System object
designfilt
no longer assists in correcting calls to the function
within a script or function. For more information, see Version History.
Description
designs a d
= designfilt(resp
,Name,Value
)digitalFilter
object, d
, 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 on
resp
and consist of combinations of these:
Frequency Constraints correspond to the frequencies at which a filter exhibits a desired behavior. Examples include
'PassbandFrequency'
and'CutoffFrequency'
. You must always specify the frequency constraints.Magnitude Constraints describe the filter behavior at particular frequency ranges. Examples include
'PassbandRipple'
and'StopbandAttenuation'
.designfilt
provides default values for magnitude constraints left unspecified. In arbitrary-magnitude designs you must always specify the vectors of desired amplitudes.Filter Order: 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.
Design Method 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 Method Options are parameters specific to a given design method. Examples include
'Window'
for the'window'
method and optimization'Weights'
for arbitrary-magnitude equiripple designs.designfilt
provides default values for design options left unspecified.Sample Rate 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.Implementation parameters determine how the
designfilt
function implements the filter design. (since R2023b)
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.
If
d
is adigitalFilter
object, use thefilter
function in the form ofdataOut = filter(d,dataIn)
to filter an input signaldataIn
. For IIR filters, thefilter
function uses a direct-form II implementation. You can also use thefiltfilt
andfftfilt
functions withdigitalFilter
objects.If
d
is adsp.FIRFilter
object or adsp.SOSFilter
object, pass the input data to the object and run the object algorithm,filtObj = dsp.FIRFilter; dataOut = filtObj(dataIn)
. (since R2023b)Use Filter Analyzer to visualize the filter
d
.Type
d.Numerator
andd.Denominator
to obtain the numerator and denominator coefficients of adigitalFilter
d
. For IIR filters, the coefficients are expressed as second-order cascaded transfer functions.Type
d.Numerator
to obtain the filter coefficients of adsp.FIRFilter
objectd
. Typed.Numerator
andd.Denominator
to obtain the numerator and denominator coefficients of adsp.SOSFilter
objectd
. (since R2023b)See
digitalFilter
for a list of the filtering and analysis functions you can use with thedigitalFilter
object.See the Object Functions section in the
dsp.FIRFilter
anddsp.SOSFilter
object pages for a list of the filtering and analysis functions you can use with these objects. (since R2023b)
designfilt(
lets you edit an existing digital filter d
)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
Design Lowpass FIR Filter Using designfilt
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 ... ] (1x74 double) InitialConditions: 0 Use get to show all properties
Visualize the magnitude and phase responses of this filter using freqz
.
freqz(lpFIRFilter.Numerator)
Design Highpass IIR Filter Using designfilt
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: [10x3 double] Denominator: [10x3 double] HasScaleValues: true ScaleValues: [0.5812 1 1 1 1 1 1 1 1 1 14.8291] Use get to show all properties
Visualize the frequency response of this filter.
freqz(hpIIRFilter,[],44100)
Input Arguments
resp
— Filter response and type
'lowpassfir'
| 'lowpassiir'
| 'highpassfir'
| 'highpassiir'
| 'bandpassfir'
| 'bandpassiir'
| 'bandstopfir'
| 'bandstopiir'
| 'differentiatorfir'
| 'hilbertfir'
| 'arbmagfir'
Filter response and type, specified as a character vector or string scalar.
'lowpassfir'
— FIR lowpass filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| N/A | ||
| ||||
N/A |
| N/A | ||
N/A |
| |||
| ||||
N/A |
| |||
|
If
you have a DSP System Toolbox™ license, the designfilt
function supports these additional design specifications. (since R2023b)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) (since R2024a) |
| |||
| N/A |
| ||
|
| |||
|
| |||
| N/A | |||
| N/A | |||
| N/A |
'lowpassiir'
— IIR lowpass filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| |||
| ||||
| ||||
| ||||
N/A |
| N/A | ||
| N/A | |||
| N/A | |||
| N/A | |||
N/A |
| N/A |
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2023b)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A |
| |||
N/A |
| |||
| N/A | |||
N/A |
| N/A | ||
| N/A | |||
| N/A | |||
| N/A | |||
N/A |
| N/A |
'highpassfir'
— FIR highpass filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| N/A | ||
| ||||
N/A |
| |||
| ||||
N/A |
| |||
|
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2023b)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) (since R2024a) |
| |||
| N/A |
| ||
|
| |||
|
| |||
| N/A | |||
| N/A | |||
| N/A |
'highpassiir'
— IIR highpass filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| |||
| ||||
| ||||
| ||||
N/A |
| N/A | ||
| N/A | |||
| N/A | |||
| N/A | |||
N/A |
| N/A |
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2023b)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A |
| |||
N/A |
| |||
| N/A | |||
N/A |
| N/A | ||
| N/A | |||
| N/A | |||
| N/A | |||
N/A |
| N/A |
'bandpassfir'
— FIR bandpass filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| N/A | ||
| ||||
N/A |
| |||
| ||||
N/A |
| |||
|
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2024a)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| |||
N/A |
| |||
|
'bandpassiir'
— IIR bandpass filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| |||
| ||||
| ||||
| ||||
N/A |
| N/A | ||
| N/A | |||
| N/A | |||
| N/A |
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2024a)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A |
| |||
| N/A | |||
| N/A | |||
| N/A | |||
| N/A | |||
N/A |
| N/A | ||
N/A |
| N/A |
'bandstopfir'
— FIR bandstop filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| N/A | ||
| ||||
N/A |
| |||
| ||||
N/A |
| |||
|
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2024a)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| |||
N/A |
| |||
|
'bandstopiir'
— IIR bandstop filter
response type
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 omit
'FilterOrder'
(when required), or any of the frequency constraints,designfilt
generates an error.If you omit the magnitude constraints,
designfilt
uses default values.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A (Minimum-order design) |
| |||
| ||||
| ||||
| ||||
N/A |
| N/A | ||
| N/A | |||
| N/A | |||
| N/A |
If
you have a DSP System Toolbox license, the designfilt
function supports these additional design specifications. (since R2024a)
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A |
| |||
| N/A | |||
| N/A | |||
| N/A | |||
| N/A | |||
N/A |
| N/A | ||
N/A |
| N/A |
'differentiatorfir'
— FIR differentiator filter
response type
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 omit
'FilterOrder'
, or any of the frequency constraints when designing a partial-band differentiator,designfilt
generates an error.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A | N/A |
| N/A | |
| N/A | |||
N/A |
| |||
| N/A |
'hilbertfir'
— FIR Hilbert transformer filter
response type
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
If you omit
'FilterOrder'
or'TransitionWidth'
,designfilt
generates an error.If you omit
'DesignMethod'
,designfilt
uses the default design method for Hilbert transformers.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
N/A |
| N/A | ||
| N/A |
'arbmagfir'
— FIR filter of arbitrary magnitude response
response type
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 omit
'FilterOrder'
, or any of the frequency or magnitude constraints,designfilt
generates an error.If you omit
'DesignMethod'
,designfilt
uses the default design method for the specification set.If you omit the design method options,
designfilt
uses the default values for the design method that you have selected.If you omit
'SampleRate'
,designfilt
sets it to 2 Hz.
Filter Order Argument Names | Frequency Constraint Argument Names | Magnitude Constraint Argument Names | 'DesignMethod' Argument Values | Design Option Argument Names |
---|---|---|---|---|
| ||||
| ||||
| ||||
… | … |
| … | |
| … |
Data Types: char
| string
d
— Digital filter
digitalFilter
object
Digital filter, specified as a digitalFilter
object
generated by designfilt
. Use this input to change the
specifications of an existing digitalFilter
.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=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.
SampleRate
— Sample rate
2 (default) | positive scalar
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
FilterOrder
— Filter order
positive integer scalar
Filter order, specified as a positive integer scalar.
Data Types: double
NumeratorOrder
— Numerator order for IIR filters
positive integer
Numerator order for IIR filters, specified as a positive integer.
Data Types: double
DenominatorOrder
— Denominator order for IIR filters
positive integer
Denominator order for IIR filters, specified as a positive integer.
Data Types: double
PassbandFrequency
, PassbandFrequency1
, PassbandFrequency2
— Passband frequency
positive scalar
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
StopbandFrequency
, StopbandFrequency1
, StopbandFrequency2
— Stopband frequency
positive scalar
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
CutoffFrequency
, CutoffFrequency1
, CutoffFrequency2
— 6-dB frequency
positive scalar
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
HalfPowerFrequency
, HalfPowerFrequency1
, HalfPowerFrequency2
— 3-dB frequency
positive scalar
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
PassbandBandwidth
— Passband frequency width
positive scalar
Bandwidth of the filter passband in normalized frequency units,
specified as a positive scalar less than 'HalfPowerFrequency2'
− 'HalfPowerFrequency1'
.
Data Types: double
StopbandBandwidth
— Frequency width between stopband frequencies
positive scalar
Frequency width between the two stopband frequencies, specified as a positive scalar in normalized frequency units.
Data Types: double
TransitionWidth
— Width of transition region
positive scalar
Width of the transition region between passband and stopband for a Hilbert transformer, specified as a positive scalar.
Data Types: double
Frequencies
— Response frequencies
vector
Response frequencies, specified as 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
NumBands
— Number of bands
positive integer scalar
Number of bands in a multiband design, specified as a positive integer scalar not greater than 10.
Data Types: double
BandFrequencies1
, ...
, BandFrequenciesN
— Multiband response frequencies
vectors
Multiband response frequencies, specified as numeric vectors.
'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
PassbandRipple
, PassbandRipple1
, PassbandRipple2
— Passband ripple
1 (default) | positive scalar
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
StopbandAttenuation
, StopbandAttenuation1
, StopbandAttenuation2
— Stopband attenuation
60 (default) | positive scalar
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
Passband1Constrained
, Passband2Constrained
, PassbandConstrained
— Option to constrain passband ripple
false
(default) | true
Since R2024a
Option to constrain passband ripple, specified as a logical value.
Set 'Passband1Constrained'
to
true
to constrain the first passband ripple in
the bandstop FIR filter.
Set 'Passband2Constrained'
to
true
to constrain the second passband ripple in
the bandstop FIR filter.
Set 'PassbandConstrained'
to
true
to constrain the passband ripple in the
bandpass FIR filter.
Data Types: logical
Stopband1Constrained
, Stopband2Constrained
, StopbandConstrained
— Option to constrain stopband attenuation
false
(default) | true
Since R2024a
Option to constrain stopband attenuation, specified as a logical value.
Set 'Stopband1Constrained'
to
true
to constrain the first stopband attenuation
in the bandpass FIR filter.
Set 'Stopband2Constrained'
to
true
to constrain the second stopband attenuation
in the bandpass FIR filter.
Set 'StopbandConstrained'
to
true
to constrain the stopband attenuation in the
bandstop FIR filter.
Data Types: logical
Amplitudes
— Desired response amplitudes
vector
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
BandAmplitudes1
, ...
, BandAmplitudesN
— Multiband response amplitudes
vectors
Multiband response amplitudes, specified as numeric vectors.
'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
DesignMethod
— Design method
'butter'
| 'cheby1'
| 'cheby2'
| 'cls'
| 'ellip'
| 'equiripple'
| 'freqsamp'
| 'kaiserwin'
| 'ls'
| 'maxflat'
| 'window'
| 'lpnorm'
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.
'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.'lpnorm'
designs a least Pth-norm optimal IIR filter using the least-Pth unconstrained optimization algorithm. For more information, see Least Pth-Norm Optimal IIR Filter Design. (since R2023b)'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
MinOrder
— Minimum order parity
'any'
(default) | 'even'
Minimum order parity of a 'kaiserwin'
design,
specified as 'any'
or 'even'
. When
you set 'MinOrder'
to 'even'
,
designfilt
returns a minimum-order filter with
even order. When you set 'MinOrder'
to
'any'
, the returned filter can have even or odd
order, whichever is smaller.
Data Types: char
| string
Window
— Window
numeric vector | window name | function handle | cell array
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 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
MatchExactly
— Band to match exactly
'stopband'
| 'passband'
| 'both'
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
Norm
— L-infinity norm
128
| positive scalar
Since R2023b
L-infinity norm, specified as a positive scalar.
Data Types: double
PassbandOffset
— Passband offset
0 (default) | positive scalar
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
ScalePassband
— Scale passband
true
(default) | false
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
ZeroPhase
— Zero phase
false
(default) | true
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
PhaseConstraint
— Phase constraint
'Linear'
(default) | 'Minimum'
| 'Maximum'
Since R2024a
Phase constraint on the equiripple FIR filter, specified as one of these options:
'Minimum'
–– Design a minimum-phase equiripple FIR filter.'Maximum'
–– Design a maximum-phase equiripple FIR filter.'Linear'
–– Design a linear phase equiripple FIR filter.
Data Types: char
| string
PassbandWeight
, PassbandWeight1
, PassbandWeight2
— Passband optimization weight
1 (default) | positive scalar
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
StopbandWeight
, StopbandWeight1
, StopbandWeight2
— Stopband optimization weight
1 (default) | positive scalar
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
Weights
— Optimization weights
1 (default) | positive scalar | vector
Optimization weights, specified as a positive scalar or a vector of
the same length as 'Amplitudes'
.
Data Types: double
BandWeights1
, ...
, BandWeightsN
— Multiband weights
1 (default) | positive scalar | vectors
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 ith band of a multiband design. If specified as a
vector, 'BandWeightsi'
must have the same length as
'BandAmplitudesi'
.
Data Types: double
SystemObject
— Flag to generate System object™
false
(default) | true
Since R2023b
When you set this property to:
true
–– Thedesignfilt
function generates adsp.FIRFilter
object for the'lowpassfir'
and'highpassfir'
filter responses, and adsp.SOSFilter
object for the'lowpassiir'
and'highpassiir'
filter responses.false
–– Thedesignfilt
function generates adigitalFilter
object.
Data Types: logical
Output Arguments
d
— Digital filter
digitalFilter
object | dsp.FIRFilter
object | dsp.SOSFilter
object
Digital filter, returned as a:
digitalFilter
object.dsp.FIRFilter
object when you choose the lowpass FIR or the highpass FIR design and setSystemObject
totrue
. (since R2023b)dsp.SOSFilter
object when you choose the lowpass IIR or the highpass IIR design and setSystemObject
totrue
. (since R2023b)
More About
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.
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.
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.
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.
filterAnalyzer(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
OK and visualize the resulting filter.
dee = designfilt('lowpassfir','FilterOrder',10, ... 'CutoffFrequency',650,'PassbandRipple',1, ... 'StopbandAttenuation',60,'SampleRate',2000); filterAnalyzer(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); filterAnalyzer(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); filterAnalyzer(dee)
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(Order,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);
N = 5;
sgout = hipassfilt(N,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 OK 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.
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 Do not show this message again 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 havedesignfilt
correct your MATLAB code without asking for confirmation. You can also click Always accept in the confirmation dialog box.Use
setpref('dontshowmeagain','filterDesignAssistantCodeCorrection',true)
to ensure thatdesignfilt
corrects your MATLAB code only when you confirm you want the changes. With this command, you can undo the effect of having clicked Always accept 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 Sections 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, andYou 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 for more information.) For example, this input offers an assistant.This input does not.d = designfilt('lowpassfir','CutoffFrequency',0.6)
myFilterDesigner = @designfilt; d = myFilterDesigner('lowpassfir','CutoffFrequency',0.6)
You are not offered an assistant if you run
designfilt
usingeval
. For example, this input offers an assistant.This input does not.d = designfilt('lowpassfir','CutoffFrequency',0.6)
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.
Version History
Introduced in R2014aR2024a: SystemObject
argument supports bandpass and bandstop filter responses
Starting in R2024a, you can set the SystemObject
argument to
true
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.
R2024a: Lowpass FIR filter and Highpass FIR filter responses support additional filter design specifications
The 'lowpassfir'
and 'highpassfir'
filter responses support these additional filter
design specifications.
'lowpassfir'
Minimum order,
'PassbandFrequency'
,'StopbandFrequency'
,'PassbandRipple'
,'StopbandAttenuation'
'FilterOrder'
,'PassbandFrequency'
,'StopbandFrequency'
'highpassfir'
Minimum order,
'PassbandFrequency'
,'StopbandFrequency'
,'PassbandRipple'
,'StopbandAttenuation'
'FilterOrder'
,'PassbandFrequency'
,'StopbandFrequency'
R2024a: New 'PhaseConstraint'
design method option
Using the 'PhaseConstraint'
design
method option, you can 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.
R2023b: Support for additional features when you install DSP System Toolbox
The designfilt
function enables these features when you
install DSP System Toolbox:
SystemObject
argument –– Set this property totrue
to generate adsp.FIRFilter
object for the'lowpassfir'
and'highpassfir'
filter responses, and adsp.SOSFilter
object for the'lowpassiir'
and'highpassiir'
filter responses.'lpnorm'
design method –– Select this design method for the'lowpassiir'
and'highpassiir'
filter responses.Norm
property –– Specify the L-infinity norm when you select the'lpnorm'
design method.
R2021b: designfilt
function no longer assists in correcting calls to designfilt
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 to
designfilt
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.
See Also
Live Editor Tasks
Apps
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)