Main Content

designLowpassIIR

Design and implement lowpass IIR filter

Since R2023b

Description

[B,A] = designLowpassIIR designs a lowpass IIR filter with the filter order of 10 and half-power frequency of 0.25. When you use this syntax, the function designs the IIR filter using the "default" window design method and does not compute the scale values.

B and A are the second-order section matrices of the size P-by-3, where P is the number of filter sections.

The System object™ argument is false by default. To implement the filter, assign the filter coefficients to a dsp.SOSFilter object.

example

[B,A] = designLowpassIIR(Name=Value) specifies options using one or more name-value arguments.

For example, [B,A] = designLowpassIIR(FilterOrder=30,HalfPowerFrequency=0.4,DesignMethod="cheby1") designs a lowpass IIR filter with the filter order of 30 and half-power frequency of 0.4 by using the Chebyshev Type I window design method.

When you specify only a partial list of filter parameters, the function designs the filter by setting the other design parameters to their default values.

The function supports three design methods. Each design method supports a specific set of design combinations. For more information, see DesignMethod.

[B,A,SV] = designLowpassIIR(Name=Value) also returns scale values when you specify the HasScaleValues argument. SV is a vector of 1s when you set the argument to false and a vector of scale values when you set it to true.

example

filtObj = designLowpassIIR(Name=Value) designs a lowpass IIR filter and implements a dsp.SOSFilter System object.

This syntax applies when you set the SystemObject argument to true.

Examples

collapse all

Create a dsp.SOSFilter object, and set the CoefficientSource property to 'Input port' so that you can vary the coefficients of the SOS filter coefficients through the input port during simulation.

sosFilt = dsp.SOSFilter(CoefficientSource="Input port")
sosFilt = 
  dsp.SOSFilter with properties:

            Structure: 'Direct form II transposed'
    CoefficientSource: 'Input port'
       HasScaleValues: false

  Use get to show all properties

Create a spectrumAnalyzer object to visualize the spectra of the input and output signals.

spectrumScope = spectrumAnalyzer(SampleRate=96000,PlotAsTwoSidedSpectrum=false,...
    ChannelNames=["Input Signal","Filtered Signal"]);

Create a dsp.DynamicFilterVisualizer object to visualize the magnitude response of the varying filter.

filterViz = dsp.DynamicFilterVisualizer(NormalizedFrequency=true);

Stream in random data and filter the signal using the dsp.SOSFilter object. Use the designLowpassIIR function to design the filter coefficients. By default, this function returns a P-by-3 matrix of numerator coefficients and a P-by-3 matrix of denominator coefficients. Assign these coefficients to the dsp.SOSFilter object.

Vary the 3-dB cutoff frequency of the filter during simulation. The designLowpassIIR function redesigns the coefficients based on the updated filter specifications. Pass these updated coefficients to the SOS filter. Visualize the spectra of the input and filtered signals using the spectrum analyzer.

F3dB = 0.5;
for idx = 1:500
    [b,a] = designLowpassIIR(FilterOrder=30,HalfPowerFrequency=F3dB,DesignMethod="butter");
    x = randn(1024,1);
    y = sosFilt(x,b,a);
    spectrumScope(x,y);
    filterViz(b,a);
    F3dB = F3dB + 0.0005;
end

Design and implement a lowpass IIR filter object using the designLowpassIIR function. The function returns a dsp.SOSFilter object when you set the SystemObject argument to true.

sosFilt = designLowpassIIR(FilterOrder=30,HalfPowerFrequency=0.5,DesignMethod="butter",...
        SystemObject=true)
sosFilt = 
  dsp.SOSFilter with properties:

            Structure: 'Direct form II transposed'
    CoefficientSource: 'Property'
            Numerator: [15x3 double]
          Denominator: [15x3 double]
       HasScaleValues: false

  Use get to show all properties

Create a dsp.DynamicFilterVisualizer object to visualize the magnitude response of the filter.

filterViz = dsp.DynamicFilterVisualizer(NormalizedFrequency=true,YLimits=[-80 20]);
filterViz(sosFilt)

Create a spectrumAnalyzer object to visualize the spectra of the input and output signals.

spectrumScope = spectrumAnalyzer(SampleRate=44100,PlotAsTwoSidedSpectrum=false,...
    ChannelNames=["Input Signal","Filtered Signal"]);

Stream in random data and filter the signal using the dsp.SOSFilter object. Visualize the spectra of the input and filtered signals using the spectrum analyzer.

for idx = 1:50
    x = randn(1024,1);
    y = sosFilt(x);
    spectrumScope(x,y);
end

Input Arguments

collapse all

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: designLowpassIIR(FilterOrder=30,HalfPowerFrequency=0.5,SystemObject=true)

Order of the lowpass IIR filter, N, specified as a nonnegative integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

3-dB cutoff frequency of the lowpass IIR filter, F3dB, specified as a normalized scalar in the range (0,1].

Data Types: single | double

Window design method, specified as one of these options:

  • "default" –– The function designs the lowpass IIR filter using one of these methods:

    • Chebyshev Type I method when you specify the PassBandRipple (APASS) argument

    • Chebyshev Type II method when you specify the StopbandAttenuation (ASTOP) argument

    • Butterworth method when you do not specify the PassBandRipple (APASS) and the StopbandAttenuation (ASTOP) arguments

  • "butter" –– The function designs the lowpass IIR filter using the Butterworth design method. You can use this method when you specify one of these design specification combinations:

  • "cheby1" –– The function designs the lowpass IIR filter using the Chebyshev Type I design method. You can use this method when you specify the FilterOrder (N), HalfPowerFrequency (F3dB), and the PassBandRipple (APASS) arguments.

  • "cheby2" –– The function designs the lowpass IIR filter using the Chebyshev Type II design method. You can use this method when you specify the FilterOrder (N), HalfPowerFrequency (F3dB), and the StopbandAttenuation (ASTOP) arguments.

Data Types: char | string

Passband ripple of the IIR filter, APASS, specified as a positive scalar.

To specify the PassbandRipple argument, set DesignMethod to "default" or "cheby1".

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Stopband attenuation of the IIR filter, ASTOP, specified as a positive scalar.

To specify the StopbandAttenuation argument, set DesignMethod to "default" or "cheby2".

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Option to compute the scale values, SV, specified as true or false.

Data Types: logical

Option to create System object, specified as one of these:

  • false –– The function returns second-order section matrices.

  • true –– The function returns a dsp.SOSFilter object.

Data Types: logical

Option to print the entire function call in MATLAB, specified as one of these:

  • false –– The function does not print the function call.

  • true –– The function prints the entire function call including the default values of the Name=Value arguments that you did not specify when calling the function.

    Use this argument to view all the values used by the function to design and implement the filter.

Data Types: logical

Output Arguments

collapse all

Numerator coefficients of the lowpass IIR filter in the second-order section form, returned as a P-by-3 matrix, where P is the number of filter sections and equals ceil(FilterOrder/2).

If you specify single-precision values in any of the input arguments, the function designs single-precision filter coefficients. (since R2024a)

Data Types: single | double

Denominator coefficients of the lowpass IIR filter in the second-order section form, returned as a P-by-3 matrix, where P is the number of filter sections and equals ceil(FilterOrder/2).

The leading denominator coefficient is always 1.

If you specify single-precision values in any of the input arguments, the function designs single-precision filter coefficients. (since R2024a)

Data Types: single | double

Scale values for each section, returned as a (P+1)-by-1 vector, where P is the number of filter sections and equals ceil(FilterOrder/2).

If you set HasScaleValues to false, SV is a vector of 1s of size (P+1)-by-1.

If you specify single-precision values in any of the input arguments, the function outputs the scale values in single precision. (since R2024a)

Data Types: single | double

Lowpass IIR filter object, returned as a dsp.SOSFilter System object.

The function returns this output when you set the SystemObject argument to true.

Extended Capabilities

Version History

Introduced in R2023b

expand all