Contenuto principale

Bandpass IIR

Design bandpass infinite impulse response filter

Description

A bandpass filter attenuates the energy of an input signal outside a specified frequency range. An infinite impulse response (IIR) filter computes an output signal as a running weighted average of input samples and previous output values.

Signal Processing Toolbox™ provides different ways to design bandpass IIR filters:

All of these methods return digitalFilter objects. If you have a DSP System Toolbox™ license, you can generate your design as a filter System object™ and include additional Design Method Options.

For other ways to design bandpass IIR filters using MATLAB, see Other Bandpass IIR Filter Design Functions.

Examples

expand all

To design the filter at the command line or in a script, use the designfilt function with "bandpassiir" as first argument. Use name-value arguments to specify your design further.

d = designfilt("bandpassiir", ...  % Response type
    SampleRate=2000, ...           % Sample rate
    StopbandFrequency1=50, ...     % Frequency constraints
    PassbandFrequency1=100, ...
    PassbandFrequency2=300, ...
    StopbandFrequency2=450, ...
    StopbandAttenuation1=70, ...   % Magnitude constraints
    PassbandRipple=1, ...
    StopbandAttenuation2=70, ...
    DesignMethod="ellip", ...      % Design method
    MatchExactly="passband");      % Design method options
filterAnalyzer(d)

To design the filter using the Design Filter Live Editor task:

  1. Specify the filter:

    • Under Select filter response, select Bandpass IIR.

    • Under Sample Rate, specify Frequency units as Hz and Input sample rate (Hz) as 2000.

    • Under Specify filter order, set Order mode to Minimum.

    • Under Specify frequency parameters, specify:

      • Stopband frequency 1 as 50 Hz

      • Passband frequency 1 as 100 Hz

      • Passband frequency 2 as 300 Hz

      • Stopband frequency 2 as 450 Hz

    • Under Specify magnitude parameters, specify:

      • Stopband attenuation 1 as 70 dB

      • Passband ripple as 1 dB

      • Stopband attenuation 2 as 70 dB

    • Under Specify algorithm, select Elliptic. Under Specify algorithm options, specify that the design match the Passband exactly.

  2. The Live Editor task updates the filter automatically by default.

    Bandpass IIR filter design using Live Editor task

To design the filter using the Filter Designer app:

  1. In the Response gallery of the Designer tab in the app toolstrip, select Bandpass IIR.

  2. Specify the filter using the options in the Filter Parameters table:

    • In Design by, select Specification.

    • In Sample Rate, specify Frequency units as Hz and Input sample rate (Hz) as 2000.

    • Under Filter Order, set Order mode to Minimum.

    • Under Frequency Specifications, specify:

      • Stopband frequency 1 as 50 Hz

      • Passband frequency 1 as 100 Hz

      • Passband frequency 2 as 300 Hz

      • Stopband frequency 2 as 450 Hz

    • Under Magnitude Specifications, specify:

      • Stopband attenuation 1 as 70 dB

      • Passband ripple as 1 dB

      • Stopband attenuation 2 as 70 dB

    • Under Algorithm, select Elliptic. Under Algorithm Options, specify that the design match the Passband exactly.

  3. In the Filter section of the Designer tab, click Update Filter.

    Bandpass IIR filter design using Filter Designer app

  4. Export code to create your digital filter. On the toolstrip, click Export and select Generate MATLAB function > Digital Filter Object. The code appears in the editor.

    function designedFilter = bandpassiir1filt
    
    designedFilter = designfilt('bandpassiir', ...
        'StopbandFrequency1',50,'PassbandFrequency1',100, ...
        'PassbandFrequency2',300,'StopbandFrequency2',450, ...
        'StopbandAttenuation1',70,'PassbandRipple',1, ...
        'StopbandAttenuation2',70,'SampleRate',2000, ...
        'DesignMethod','ellip','MatchExactly','passband');
    
    end

Parameters

expand all

Design Method

Specify the algorithm to design the filter. The available design methods correlate with the set of design specifications that you choose.

Design the filter using the Butterworth algorithm. Butterworth filters have a smooth monotonic frequency response that is maximally flat in the passband. They trade rolloff steepness for flatness.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="butter".

In the Specify algorithm section of the task, set Design method to Butterworth.

In the Algorithm section of the filter parameters panel, set Design method to Butterworth.

The Butterworth design method supports these design parameter combinations.

Design the filter using the Chebyshev type I algorithm. 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.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="cheby1".

In the Specify algorithm section of the task, set Design method to Chebyshev type I.

In the Algorithm section of the filter parameters panel, set Design method to Chebyshev type I.

The Chebyshev type I design method supports these design parameter combinations.

Design the filter using the Chebyshev type II algorithm. Chebyshev type II filters have a frequency response that is maximally flat in the passband and equiripple in the stopband.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="cheby2".

In the Specify algorithm section of the task, set Design method to Chebyshev type II.

In the Algorithm section of the filter parameters panel, set Design method to Chebyshev type II.

The Chebyshev type II design method supports these design parameter combinations.

Design the filter using the elliptic algorithm. Elliptic filters have a frequency response that is equiripple in both passband and stopband.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="ellip".

In the Specify algorithm section of the task, set Design method to Elliptic.

In the Algorithm section of the filter parameters panel, set Design method to Elliptic.

The elliptic design method supports these design parameter combinations.

Design the filter using the least Pth-norm unconstrained optimization algorithm.

You must have a DSP System Toolbox license to use this design method.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="lpnorm".

In the Specify algorithm section of the task, set Design method to IIR least p-norm.

In the Algorithm section of the filter parameters panel, set Design method to IIR least p-norm.

The least Pth-norm method supports these design parameter combinations.

Sample Rate

Specify the filter sample rate as a positive scalar expressed in hertz.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • To specify a sample rate, use the SampleRate name-value argument and input a value in hertz.

  • To work with normalized frequencies, omit the sample rate.

In the Sample Rate section of the task:

  • To specify a sample rate, set Frequency units to Hz and type a value for Input sample rate (Hz).

  • To work with normalized frequencies, set Frequency units to Normalized.

In the Sample Rate section of the filter parameters panel:

  • To specify a sample rate, set Frequency units to Hz and type a value for Input sample rate (Hz).

  • To work with normalized frequencies, set Frequency units to Normalized.

Filter Order

Specify the filter order N as a positive integer. Some design methods let you specify the order. Others generate minimum-order designs, which are the shortest filters that satisfy the specified constraints.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App

  • To specify a filter order, use the FilterOrder name-value argument and input a positive integer.

  • To use a minimum-order design, specify frequency and magnitude constraints accordingly.

In the Specify Filter Order section of the task:

  • To specify a filter order, set Order mode to Specify and enter a value for Order.

  • To use a minimum-order design, set Order mode to Minimum.

In the Filter Order section of the filter parameters panel:

  • To specify a filter order, set Order mode to Specify and enter a value for Order.

  • To use a minimum-order design, set Order mode to Minimum.

Frequency Specifications

Specify the lower stopband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.

The lower stopband frequency is the highest frequency in the lower stopband for which the magnitude response of the filter is at least Stopband Attenuation 1 dB lower than the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandFrequency1 name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Stopband frequency 1 and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Stopband frequency 1 and enter a positive scalar as the value.

Specify the lower half-power frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.

The lower half-power frequency is the lowest frequency at which the magnitude response of the filter is pow2db(1/2)= 10 log10½ = –3.01 dB below the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the HalfPowerFrequency1 name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Half power (3dB) frequency 1 and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Half power (3dB) frequency 1 and enter a positive scalar as the value.

Specify the lower passband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.

The lower passband frequency is the lowest frequency in the passband for which the magnitude response of the filter is within an interval of width Passband Ripple about the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the PassbandFrequency1 name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Passband frequency 1 and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Passband frequency 1 and enter a positive scalar as the value.

Specify the higher passband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.

The higher passband frequency is the highest frequency in the passband for which the magnitude response of the filter is within an interval of width Passband Ripple from the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the PassbandFrequency2 name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Passband frequency 2 and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Passband frequency 2 and enter a positive scalar as the value.

Specify the higher half-power frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.

The higher half-power frequency is the highest frequency at which the magnitude response of the filter is pow2db(1/2)= 10 log10½ = –3.01 dB below the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the HalfPowerFrequency2 name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Half power (3dB) frequency 2 and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Half power (3dB) frequency 2 and enter a positive scalar as the value.

Specify the higher stopband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.

The higher stopband frequency is the lowest frequency in the higher stopband for which the magnitude response of the filter is at least Stopband Attenuation 2 dB lower than the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandFrequency2 name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Stopband frequency 2 and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Stopband frequency 2 and enter a positive scalar as the value.

Specify the passband bandwidth as a positive scalar smaller than the difference between Half-Power Frequency 2 and Half-Power Frequency 1.

If you specify this parameter, the algorithm sets the lower and upper stopband frequencies to the corresponding half-power frequencies and adjusts the passband frequencies so that their difference is the passband bandwidth.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the PassbandBandwidth name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Passband width and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Passband width and enter a positive scalar as the value.

Specify the stopband bandwidth as a positive scalar greater than the difference between Half-Power Frequency 2 and Half-Power Frequency 1.

If you specify this parameter, the algorithm sets the lower and upper passband frequencies to the corresponding half-power frequencies and adjusts the stopband frequencies so that their difference is the stopband bandwidth.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandBandwidth name-value argument. Input the value as a positive scalar.

  • In the Specify Frequency Parameters section of the task, select a set of Frequency Constraints containing Stopband width and enter a positive scalar as the value.

  • In the Frequency Specifications section of the filter parameters panel, select a set of Frequency Constraints containing Stopband width and enter a positive scalar as the value.

Magnitude Specifications

Specify the lower stopband attenuation as a positive scalar in decibels.

The lower stopband attenuation measures the extent by which the filter gain in the lower stopband is decreased in comparison to the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandAttenuation1 name-value argument. Input the value as a positive scalar in decibels.

  • In the Specify Magnitude Parameters section of the task, select a set of Magnitude Constraints containing Stopband attenuation 1 (dB) and enter a positive scalar in decibels as the value.

  • In the Magnitude Specifications section of the filter parameters panel, select a set of Magnitude Constraints containing Stopband attenuation 1 (dB) and enter a positive scalar in decibels as the value.

Specify the passband ripple as a positive scalar in decibels.

The passband ripple measures the fluctuation of the passband gain of the filter about the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the PassbandRipple name-value argument. Input the value as a positive scalar in decibels.

  • In the Specify Magnitude Parameters section of the task, select a set of Magnitude Constraints containing Passband ripple (dB) and enter a positive scalar in decibels as the value.

  • In the Magnitude Specifications section of the filter parameters panel, select a set of Magnitude Constraints containing Passband ripple (dB) and enter a positive scalar in decibels as the value.

Specify the higher stopband attenuation as a positive scalar in decibels.

The higher stopband attenuation measures the extent by which the filter gain in the higher stopband is decreased in comparison to the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandAttenuation2 name-value argument. Input the value as a positive scalar in decibels.

  • In the Specify Magnitude Parameters section of the task, select a set of Magnitude Constraints containing Stopband attenuation 2 (dB) and enter a positive scalar in decibels as the value.

  • In the Magnitude Specifications section of the filter parameters panel, select a set of Magnitude Constraints containing Stopband attenuation 2 (dB) and enter a positive scalar in decibels as the value.

Specify the stopband attenuation as a positive scalar in decibels.

The stopband attenuation measures the extent by which the filter gain in the stopband is decreased in comparison to the reference value, usually 0 dB.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandAttenuation name-value argument. Input the value as a positive scalar in decibels.

  • In the Specify Magnitude Parameters section of the task, select a set of Magnitude Constraints containing Stopband attenuation (dB) and enter a positive scalar in decibels as the value.

  • In the Magnitude Specifications section of the filter parameters panel, select a set of Magnitude Constraints containing Stopband attenuation (dB) and enter a positive scalar in decibels as the value.

Design Method Options

Basic Options

Specify the band that the design must match exactly.

  • By default, the Butterworth and Chebyshev type II algorithms match the stopband exactly.

  • By default, the Chebyshev type I algorithm matches the passband exactly.

  • By default, the elliptic algorithm matches both the passband and the stopband exactly. This option is available only for the elliptic design method.

Advanced Options

Density of the frequency grid used by the Least Pth-Norm algorithm, specified as a positive scalar ≥ 10. The frequency grid has roughly (Density Factor × Filter Order)/(2 × Passband Frequency) frequency points. Increasing the density factor results in filters that more closely approximate an equiripple filter but take longer to compute.

You must have a DSP System Toolbox license to use this option. This parameter is available only in the designfilt function.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the DensityFactor name-value argument. Input the value as a positive scalar greater than 10.

N/A

N/A

Initial estimate of the filter denominator coefficients for the Least Pth-Norm algorithm, specified as a vector of size (N+1)-by-1, where N is the Filter Order that you specify.

You must have a DSP System Toolbox license to use this option. This parameter is available only in the designfilt function.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the InitialDenominator name-value argument. Input the value as a vector of size (N+1)-by-1, where N is the filter order.

N/A

N/A

Initial Pth norm used by the Least Pth-Norm 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 (DSP System Toolbox).

You must have a DSP System Toolbox license to use this option. This parameter is available only in the designfilt function.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the InitialNorm name-value argument. Input the value as a positive scalar.

N/A

N/A

Initial estimate of the filter numerator coefficients for the Least Pth-Norm algorithm, specified as a vector of size (N+1)-by-1, where N is the Filter Order that you specify.

You must have a DSP System Toolbox license to use this option. This parameter is available only in the designfilt function.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the InitialNumerator name-value argument. Input the value as a vector of size (N+1)-by-1, where N is the filter order.

N/A

N/A

Maximum pole radius used by the Least Pth-Norm algorithm, 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.

You must have a DSP System Toolbox license to use this option. This parameter is available only in the designfilt function.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the MaxPoleRadius name-value argument. Input the value as a positive scalar less than or equal to 1

  • In the Specify Algorithm Options section of the task, specify Max pole radius as a positive scalar less than or equal to 1.

  • In the Algorithm Options section of the filter parameters panel, specify Max pole radius as a positive scalar less than or equal to 1.

L-infinity norm used by the Least Pth-Norm algorithm, specified as a positive scalar.

You must have a DSP System Toolbox license to use this option.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the Norm name-value argument. Input the value as a positive scalar.

  • In the Specify Algorithm Options section of the task, specify Norm as a positive scalar.

  • In the Algorithm Options section of the filter parameters panel, specify Norm as a positive scalar.

Lower stopband optimization weight for a Least Pth-Norm design, specified as a positive scalar.

Weights are a way of specifying the relative importance of the passband ripple and the stopband attenuation in a filter design. By default, the passband and the stopbands are equally weighted, each with unit weight. By increasing a stopband weight, you can increase the attenuation of a stopband at the expense of increasing the passband ripple.

You must have a DSP System Toolbox license to use this option with some syntaxes.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandWeight1 name-value argument. Input the value as a positive scalar.

  • In the Specify Algorithm Options section of the task, specify Stopband Weight 1 as a positive scalar.

  • In the Algorithm Options section of the filter parameters panel, specify Stopband Weight 1 as a positive scalar.

Passband optimization weight for a Least Pth-Norm design, specified as a positive scalar.

Weights are a way of specifying the relative importance of the passband ripple and the stopband attenuation in a filter design. By default, the passband and the stopband are equally weighted, each with unit weight. By increasing the passband weight, you can increase the passband ripple at the expense of increasing the stopband attenuation.

You must have a DSP System Toolbox license to use this option with some syntaxes.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the PassbandWeight name-value argument. Input the value as a positive scalar.

  • In the Specify Algorithm Options section of the task, specify Passband Weight as a positive scalar.

  • In the Algorithm Options section of the filter parameters panel, specify Passband Weight as a positive scalar.

Higher stopband optimization weight for a Least Pth-Norm design, specified as a positive scalar.

Weights are a way of specifying the relative importance of the passband ripple and the stopband attenuation in a filter design. By default, the passband and the stopbands are equally weighted, each with unit weight. By increasing a stopband weight, you can increase the attenuation of a stopband at the expense of increasing the passband ripple.

You must have a DSP System Toolbox license to use this option with some syntaxes.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the StopbandWeight2 name-value argument. Input the value as a positive scalar.

  • In the Specify Algorithm Options section of the task, specify Stopband Weight 2 as a positive scalar.

  • In the Algorithm Options section of the filter parameters panel, specify Stopband Weight 2 as a positive scalar.

Option to scale the filter coefficients representing second-order sections (SOS), specified as a logical scalar. When you set this parameter to true, the SOS coefficients are scaled using L-infinity norm scaling, so that the filter has unit gain at zero frequency.

You must have a DSP System Toolbox license to use this option.

designfilt FunctionDesign Filter Live Editor TaskFilter Designer App
  • Use the ScaleSOS name-value argument. Input the value as true or false.

  • In the Specify Algorithm Options section of the task, select the Scale SOS coefficients box.

  • In the Algorithm Options section of the filter parameters panel, select the Scale SOS coefficients box.

More About

expand all