Contenuto principale

Arbitrary Response FIR

Design finite impulse response filter of arbitrary response

Description

An arbitrary response filter preserves or attenuates the energy of an input signal following a specified frequency-dependent amplitude profile. A finite impulse response (FIR) filter computes an output signal as a running weighted average of input samples.

You can specify an arbitrary response in these ways:

  • Arbitrary amplitude — Specify the amplitude of the frequency response in linear units.

  • Arbitrary full response — Specify complete frequency response, either as magnitudes and phases or as complex values.

Signal Processing Toolbox™ provides different ways to design arbitrary response FIR filters:

  • designfilt function — Design an arbitrary response FIR filter at the command line or in a script.

    • To specify arbitrary amplitudes, use "arbmagfir" as the first argument when you call the function.

    • To specify arbitrary full responses in complex-valued form, use "arbmagnphasefir" as the first argument when you call the function. If you have magnitudes and phases, convert them to real and imaginary values or use the Filter Design Assistant. You must have a DSP System Toolbox™ license to use this functionality.

    For an example, see Design Arbitrary Response FIR Filter Using designfilt.

  • Filter Designer app — Design an arbitrary response FIR filter interactively. Export your design to the MATLAB® workspace or to a file.

    • To specify arbitrary amplitudes, navigate to the Response section of the filter parameters panel, and set Response type Amplitudes.

    • To specify arbitrary full responses in the magnitude-and-phase form, navigate to the Response section of the filter parameters panel, and set Response type Magnitudes and phases. You must have a DSP System Toolbox license to use this functionality.

    • To specify arbitrary full responses in the complex-valued form, navigate to the Response section of the filter parameters panel, and set Response type Frequency response. You must have a DSP System Toolbox license to use this functionality.

    For an example, see Design Arbitrary Response FIR Filter Using Filter Designer.

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 arbitrary response FIR filters using MATLAB, see Other Arbitrary Response FIR Filter Design Functions.

Examples

expand all

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

d = designfilt("arbmagfir", ...                      % Response type
    SampleRate=2000, ...                             % Sample rate
    FilterOrder=100, ...                             % Filter Order
    Frequencies=[0:10:200 300 380 ...                % Frequency constraints
        400 550 562 585 600 800:10:1000], ...
    Amplitudes=[(0.5+sin(2*pi*8*(0:0.01:0.2))/4) ... % Magnitude constraints
        1 2 1 1 -0.1 -0.1 1 0.2+20*(0.2:-0.01:0).^2], ...
    DesignMethod="freqsamp", ...                     % Design method
    Window={@kaiser,0.7});                           % Design method options
filterAnalyzer(d)

To design the filter using the Filter Designer app:

  1. In the Response gallery of the Designer tab in the app toolstrip, select Arbitrary Response FIR.

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

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

    • Under Filter Order, specify the Order mode as Specify and the Order as 100.

    • Under Response, specify the Frequencies and Amplitudes with these values:

      Frequencies: [0:10:200 300 380 400 550 562 585 600 800:10:1000] Hz

      Amplitudes: [(0.5+sin(2*pi*8*(0:0.01:0.2))/4) 1 2 1 1 -0.1 -0.1 1 0.2+20*(0.2:-0.01:0).^2].

    • Under Algorithm, select Frequency sampling.

    • Under Algorithm Options, specify the Window as Kaiser and the Window parameter as 0.7.

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

    Hilbert FIR 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 = arbrespfir1filt
    
    designedFilter = designfilt('arbmagfir', ...
        'FilterOrder',100, ...
        'Frequencies',[0:10:200 300 380 400 550 562 585 600 800:10:1000], ...
        'Amplitudes',[(0.5+sin(2*pi*8*(0:0.01:0.2))/4) 1 2 1 1 -0.1 -0.1 ...
        1 0.2+20*(0.2:-0.01:0).^2], ...
        'SampleRate',2000,'Window',{@kaiser,0.7});
    
    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 Parks-McClellan algorithm. Equiripple filters have a frequency response that minimizes the maximum ripple magnitude over all bands.

designfilt FunctionFilter Designer App

Specify DesignMethod="equiripple"

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

The equiripple design method supports these design parameter combinations.

Filter OrderFrequency SpecificationsMagnitude SpecificationsDesign Method OptionsDSP System Toolbox License Required
Arbitrary amplitudes

 

 
N/A

Arbitrary full responses in the magnitude-and-phase form

Arbitrary full responses in the complex-valued form

Design the filter using the frequency-sampling algorithm. The method designs the filter by sampling the frequency response uniformly and taking the inverse Fourier transform.

designfilt FunctionFilter Designer App

Specify DesignMethod="freqsamp"

In the Algorithm section of the filter parameters panel, set Design method to Frequency sampling

The frequency-sampling design method supports these design parameter combinations.

Filter OrderFrequency SpecificationsMagnitude SpecificationsDesign Method OptionsDSP System Toolbox License Required
Arbitrary amplitudes

 
Arbitrary full responses in the magnitude-and-phase form

Arbitrary full responses in the complex-valued form

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 FunctionFilter Designer App

Specify DesignMethod="lpnorm"

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

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

Filter OrderFrequency SpecificationsMagnitude SpecificationsDesign Method OptionsDSP System Toolbox License Required
Arbitrary amplitudes

Design the filter using the least-squares algorithm. The method minimizes the discrepancy between a specified arbitrary piecewise-linear function and the filter’s magnitude response.

designfilt FunctionFilter Designer App

Specify DesignMethod="ls"

In the Algorithm section of the filter parameters panel, set Design method to FIR least-squares

The least-squares design method supports these design parameter combinations.

Sample Rate

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

designfilt FunctionFilter 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 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 FunctionFilter 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 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.

Specify the number of frequency bands as a positive integer not greater than 10. To design a multiband filter, set the number of bands to at least 2.

designfilt FunctionFilter Designer App
  • Use the NumBands name-value argument. Input the value as a positive integer not greater than 10.

  • In the Response section of the filter parameters panel, set Number of bands by entering a positive integer not greater than 10 as the value.

Frequency Specifications

Specify the frequencies associated with the arbitrary response as a vector. Use this specification to list the frequencies so that the filter response has the desired values.

  • If you specify a sample rate F s, the Nyquist frequency is Fs/2.

  • If you work with normalized frequencies, the Nyquist frequency is 1.

  • 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, and its last element must be Fs/2.

designfilt FunctionFilter Designer App
  • Use the Frequencies name-value argument. Input the value as a vector.

  • In the Response section of the filter parameters panel, set the Frequencies column by entering a vector.

Specify the multiband frequencies associated with the arbitrary response as vectors. For each frequency band, use this specification to list the frequencies so that the filter response has the desired values.

  • If you specify a sample rate F s, the Nyquist frequency is Fs/2.

  • If you work with normalized frequencies, the Nyquist frequency is 1.

  • 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, and its last element must be Fs/2.

designfilt FunctionFilter Designer App
  • Use the BandFrequencies1, …, BandFrequenciesN name-value arguments. Input the value in each argument as a vector.

  • Use as many name-value arguments as bands specified in NumBands.

  • In the Response section of the filter parameters panel, set each row of the Frequencies column by entering a vector.

Magnitude Specifications

Specify the amplitudes associated with the arbitrary response as a vector with the same size of Frequencies. Use this specification to list the amplitudes (in linear units) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
  • Use the Amplitudes name-value argument. Input the value as a vector.

  • In the Response section of the filter parameters panel, set the Amplitudes column by entering a vector.

Specify the multiband amplitudes associated with the arbitrary response as vectors with the same size of Band Frequencies 1, ..., Band Frequencies N. For each frequency band, use this specification to list the amplitudes (in linear units) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
  • Use the BandAmplitudes1, …, BandAmplitudesN name-value arguments. Input the value in each argument as a vector.

  • Use as many name-value arguments as bands specified in NumBands.

  • In the Response section of the filter parameters panel, set each row of the Amplitudes column by entering a vector.

Specify the multiband amplitudes associated with the arbitrary response as logical scalars. For each frequency band, use this specification to list whether to constrain the passband ripple of the filter response within the desired magnitude.

  • You can constrain up to NB – 1 bands, where NB is the Number of Bands of the filter. For each band that you constrain, you must specify a band ripple using Band Ripple 1, ..., Band Ripple N.

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

designfilt FunctionFilter Designer App
  • Use the BandConstrained1, …, BandConstrainedN name-value arguments. Input the value in each argument as a logical scalar.

  • In the Response section of the filter parameters panel, check a box in each row of the Constraint column.

Specify the multiband responses as vectors with the same size of Band Frequencies 1, ..., Band Frequencies N. For each frequency band, use this specification to list the frequency responses (complex values) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
  • Use the BandFrequencyResponse1, …, BandFrequencyResponseN name-value arguments. Input the value in each argument as a vector.

  • Use as many name-value arguments as bands specified in NumBands.

  • In the Response section of the filter parameters panel, set each row of the Amplitudes column by entering a vector.

Specify the multiband magnitudes associated with the arbitrary response as vectors with the same size of Band Frequencies 1, ..., Band Frequencies N. For each frequency band, use this specification to list the magnitudes (in linear units) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
N/A

  • In the Response section of the filter parameters panel, set each row of the Magnitudes column by entering a vector.

Specify the multiband phases associated with the arbitrary response as vectors with the same size of Band Frequencies 1, ..., Band Frequencies N. For each frequency band, use this specification to list the phases (in radians) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
N/A

  • In the Response section of the filter parameters panel, set each row of the Phases column by entering a vector.

Specify the multiband response passband ripples as positive scalars. For each constrained frequency band, use this specification to list the passband ripple (in linear units) up to which the amplitude response can fluctuate around the desired values.

  • You must specify as many passband ripples as constrained bands. To enable passband ripple constraint, use Band Constrained 1, ..., Band Constrained N.

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

designfilt FunctionFilter Designer App
  • Use the BandRipple1, …, BandRippleN name-value arguments. Input the value in each argument as a vector.

  • Use as many name-value arguments as constrained bands specified in BandConstrained1, …, BandConstrainedN.

  • In the Response section of the filter parameters panel, set each row of the Amplitudes column by entering a vector.

Specify the frequency response as a vector with the same size of Frequencies. Use this specification to list the frequency response (complex values) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
  • Use the FrequencyResponse name-value argument. Input the value as a vector.

  • In the Response section of the filter parameters panel, set the Frequency Response column by entering a vector.

Specify the magnitudes associated with the arbitrary response as a vector with the same size of Frequencies. Use this specification to list the magnitudes (complex absolute values in linear units) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
N/A

  • In the Response section of the filter parameters panel, set the Magnitudes column by entering a vector.

Specify the phases associated with the arbitrary response as a vector with the same size of Frequencies. Use this specification to list the phases (in radians) so that the filter response has the desired values.

designfilt FunctionFilter Designer App
N/A

  • In the Response section of the filter parameters panel, set the Phases column by entering a vector.

Design Method Options

Basic Options

Specify the optimization weights as a positive scalar or as a vector with the same size of Frequencies.

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 FunctionFilter Designer App
  • Use the Weights name-value argument. Input the value as a vector.

  • In the Algorithm Options section of the filter parameters panel, set the Weights column by entering a vector.

  • This option is not available with the Frequency sampling design method.

Specify the multiband optimization weights as positive scalars or as vectors with the same size of Band Frequencies 1, ..., Band Frequencies N.

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 FunctionFilter Designer App
  • Use the BandWeights1, …, BandWeightsN name-value arguments. Input the value in each argument as a vector.

  • Use as many name-value arguments as bands specified in NumBands.

  • In the Algorithm Options section of the filter parameters panel, set each row of the Weights column by entering a positive scalar or a vector.

  • This option is not available with the Frequency sampling design method.

Window used by the Frequency sampling algorithm, specified as one of these:

  • Hamming (@hamming)

  • Hann (@hann)

  • Kaiser (@kaiser) — Specify the shape factor as a positive real scalar.

  • Rectangular (@rectwin)

  • Chebyshev (@chebwin) — Specify the sidelobe magnitude factor as a positive scalar in decibels.

  • Bartlett (@bartlett)

  • Blackman (@blackman)

  • Flat top (@flattopwin)

  • Gaussian (@gausswin) — To use a Gaussian window with a width factor α ≠ 2.5 in the Filter Designer app or the Design Filter Live Editor task, specify it as a custom window.

  • Nuttall (@nuttallwin)

  • Triangular (@triang)

  • Custom — Specify a custom window as a vector of length N + 1, where N is the Filter Order. You can also specify the custom window as a function name or a function handle with N + 1 as first input. Additional inputs can be passed by specifying a cell array.

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

Example: "hamming" specifies a Hamming window of the required order.

Example: @hann specifies a Hann window of the required order.

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

designfilt FunctionFilter Designer App
  • Use the Window name-value argument. Input the value as a numeric vector, a window name, a function handle, or a cell array if you need to specify additional window parameter values.

  • In the Algorithm Options section of the filter parameters panel, specify a value from the Window drop-down list and enter additional window parameter values if needed.

Advanced Options

Multiband frequency points to force magnitude response to 0 dB for the Equiripple algorithm, specified as [], positive scalars, or vectors. For each unconstrained frequency band, use this design method option to list the frequency points at which to force the magnitude response to 0 dB.

  • If you specify a sample rate F s , the Nyquist frequency is F s/2.

  • If you work with normalized frequencies, the Nyquist frequency is 1.

  • 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, and its last element must be Fs/2.

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

designfilt FunctionFilter Designer App
  • Use the BandForcedFrequenciesyPoints1, …, BandForcedFrequenciesyPointsN name-value arguments. Input the value in each argument as a positive scalar or a vector.

  • Do not specify these name-value arguments for the bands specified in BandConstrained1, …, BandConstrainedN.

  • In the Algorithm Options section of the filter parameters panel, set each row of the Forced frequency points column by entering a positive scalar or a vector.

Density of the frequency grid used by the Equiripple, Frequency sampling, and Least Squares algorithms, specified as a positive scalar ≥ 10. The frequency grid has roughly (Density Factor × Filter Order) 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 FunctionFilter Designer App
  • Use the DensityFactor name-value argument. Input the value as a positive scalar greater than 10.

N/A

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

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

designfilt FunctionFilter Designer App
  • Use the InitialOrder name-value argument. Input the value as a positive integer.

  • In the Algorithm Options section of the filter parameters panel, set Initial order estimate to a positive integer.

Minimum order parity of an Equiripple design, specified as one of these options:

  • Any — The returned filter can have even or odd order, whichever is smaller.

  • Even — The returned filter has the smallest possible even order.

  • Odd — The returned filter has the smallest possible odd order. This option is available only for equiripple designs.

You must have a DSP System Toolbox license to use this option with the equiripple method.

designfilt FunctionFilter Designer App
  • Use the MinOrder name-value argument. Input the value as "any", "even", or "odd".

  • In the Algorithm Options section of the filter parameters panel, set Minimum order to Any or Even.

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

  • Linear — Design a linear-phase equiripple FIR filter.

  • Minimum — Design a minimum-phase equiripple FIR filter.

  • Maximum — Design a maximum-phase equiripple FIR filter.

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

designfilt FunctionFilter Designer App
  • Use the PhaseConstraint name-value argument. Input the value as "linear", "minimum", or "maximum".

  • In the Algorithm Options section of the filter parameters panel, set Phase constraint to Linear, Minimum, or Maximum.

Option to set frequency grid as uniform for the Equiripple algorithm, specified as true or false. Set this argument to true to space the frequency grid points uniformly in the frequency bands of interest. Control the density of the uniform grid with the Density Factor option.

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

designfilt FunctionFilter Designer App
  • Use the UniformGrid name-value argument. Input the value as true or false.

N/A

More About

expand all