Contenuto principale

Differentiator FIR

Design differentiator finite impulse response filter

Description

A differentiator filter computes the time derivative of an input signal by applying the properties of the Fourier transform. A finite impulse response (FIR) filter computes an output signal as a running weighted average of input samples.

Signal Processing Toolbox™ provides different ways to design differentiator FIR 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 differentiator FIR filters using MATLAB, see Other Differentiator FIR Filter Design Functions.

Examples

expand all

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

d = designfilt("differentiatorfir", ... % Response type
    SampleRate=2000, ...                % Sample rate
    FilterOrder=42, ...                 % Filter order
    PassbandFrequency=400, ...          % Frequency constraints
    StopbandFrequency=550, ...
    DesignMethod="ls");                 % Design method
filterAnalyzer(d)

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

  1. Specify the filter:

    • Under Select filter response, select Differentiator FIR.

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

    • Under Specify filter order, specify Order Mode as Specify and Order as 42.

    • Under Specify frequency parameters, specify a passband frequency of 400 Hz and a stopband frequency of 550 Hz.

    • Under Specify algorithm, select FIR least-squares.

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

    Differentiator FIR 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 Differentiator FIR.

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

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

    • Under Filter Order, specify Order Mode as Specify and Order as 42.

    • Under Frequency Specifications, specify a passband frequency of 400 Hz and a stopband frequency of 550 Hz.

    • Under Algorithm, select FIR least-squares.

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

    Differentiator 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 = differentiatorfir1filt
    
    designedFilter = designfilt('differentiatorfir', ...
        'FilterOrder',42,'PassbandFrequency',400, ...
        'StopbandFrequency',550,'SampleRate',2000, ...
        'DesignMethod','ls');
    
    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 FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="equiripple".

In the Specify algorithm section of the task, set Design method to 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

N/AN/AN/A 

N/A

 
N/A

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 FunctionDesign Filter Live Editor TaskFilter Designer App

Specify DesignMethod="ls".

In the Specify algorithm section of the task, set Design method to FIR least-squares.

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.

Filter OrderFrequency SpecificationsMagnitude SpecificationsDesign Method OptionsDSP System Toolbox License Required

N/AN/AN/A 

N/AN/A 

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 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 passband frequency is the highest frequency 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 PassbandFrequency name-value argument. Input the value as a positive scalar.

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

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

Specify the 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 stopband frequency is the lowest frequency for which the magnitude response of the filter is at least Stopband Attenuation dB lower than the reference value, usually 0 dB.

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

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

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

Magnitude Specifications

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

Passband optimization weight, 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.

Stopband optimization weight, 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 stopband weight, you can increase the stopband attenuation 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 StopbandWeight name-value argument. Input the value as a positive scalar.

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

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

Advanced Options

Density of the frequency grid used by the Equiripple 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

More About

expand all