Digital Filter Design

The Wolfram Language provides a comprehensive set of methods for designing digital filters.

Digital Filter Design Methods

LeastSquaresFilterKernelcreate an FIR filter using the least-squares method
FrequencySamplingFilterKernelcreate an FIR filter using frequency sampling
EquirippleFilterKernelcreate an FIR filter using the equiripple method
ToDiscreteTimeModelcreate an IIR digital filter from an analog prototype

Digital filter design methods.

Least-Squares Method

This method obtains a finite impulse response (FIR) from a given prototype filter specification in the frequency domain by means of the inverse discrete-time Fourier transform.

Define a zero-phase ideal lowpass filter with a cutoff frequency of 1.2 radians per sample.

H(ⅇ^( j omega))={1, |omega| <= omega_c; 0, otherwise

The impulse response is obtained by taking the inverse discrete-time Fourier transform of the filter specification.
In[90]:=
Click for copyable input
Out[90]=

Evaluating this expression for integer values of from to will return a filter of length .

Create a lowpass FIR filter of length 15 with a cutoff frequency of 1.2 radians per sample.
In[107]:=
Click for copyable input
Out[107]=
This method minimizes the mean-squared error between the ideal specification and the resulting FIR filter.
In[73]:=
Click for copyable input
Out[73]=

The least-squares method is also known as the window-based method. The mean-squared error can be diminished by applying a smoothing window to the FIR returned by LeastSquaresFilterKernel.

Create a Hann window of length 15.
In[114]:=
Click for copyable input
Out[114]=
Apply the window to the lowpass FIR filter h.
In[115]:=
Click for copyable input
Out[116]=

Different windows return different attenuations. Select a window type by the degree of the desired attenuation.

Compare attenuation levels of four selected windows
In[130]:=
Click for copyable input
Out[130]=

Frequency Sampling Method

Frequency sampling allows the creation of an FIR filter by specifying the filter's amplitude spectrum on the interval 0<= omega<= pi at a finite number of uniformly spaced frequency locations.

Sample an ideal lowpass filter at for from 0 to 5.
In[137]:=
Click for copyable input
Out[137]=
In[138]:=
Click for copyable input
Out[138]=
Create an odd-length, even-symmetry lowpass filter.
In[139]:=
Click for copyable input
Out[140]=
Show the ideal lowpass filter, amplitude samples, and the resulting filter.
In[142]:=
Click for copyable input
Out[142]=

Equiripple Method

The ParksMcClellanRabiner (1979) algorithm is one of the most popular methods of designing linear-phase FIR filters. It minimizes the maximum deviation from the desired ideal frequency response and results in filters with equal ripples in each of the bands of the filter.

Create a multiband filter of length 55.
In[207]:=
Click for copyable input
Out[207]=
Plot the magnitude response of an equiripple multiband filter.
In[208]:=
Click for copyable input
Out[208]=

Create a Digital Filter from an Analog Prototype

A popular method of creating digital filters is to transform analog prototypes to their digital equivalents using the bilinear transformation. The result is an infinite impulse response (IIR) filter, represented as a TransferFunctionModel.

ToDiscreteTimeModeldiscrete-time approximation of an analog filter

Create an IIR filter from an analog prototype.

Create an analog lowpass filter of Chebyshev type with a cutoff frequency at radians per second.
In[131]:=
Click for copyable input
Out[131]=
Transform the analog filter to a digital filter using bilinear transformation.
In[132]:=
Click for copyable input
Out[132]=
Show the frequency response of the resulting IIR filter.
In[133]:=
Click for copyable input
Out[133]=

Poles and Zeros of Digital Filters

TransferFunctionPolesextract poles of analog filters
TransferFunctionZerosextract zeros of analog filters

Poles and zeros of analog filters.

Compute and show zeros of a lowpass filter.
In[141]:=
Click for copyable input
Out[142]=
In[143]:=
Click for copyable input
Out[143]=
In[150]:=
Click for copyable input
Out[150]=
In[156]:=
Click for copyable input
Out[156]=

Output ResponseDigital Filtering of Signals

FIR Filters

ListConvolveconvolve an FIR filter with data
ImageConvolveconvolve an FIR filter with image
DiscreteConvolvesymbolic convolution of two signals

Apply FIR filters to signals.

Create a lowpass equiripple filter.
In[266]:=
Click for copyable input
Out[267]=
Import and filter an audio signal.
In[268]:=
Click for copyable input
Out[268]=
In[270]:=
Click for copyable input
Out[271]=
Lowpass filtering of a scanline of the red channel of an image.
In[272]:=
Click for copyable input
Out[274]=
Lowpass filtering of an image.
In[275]:=
Click for copyable input
Out[275]=

IIR Filters

RecurrenceFilterfilter a signal with an IIR filter
RecurrenceTableresponse of a filter obtained by solving recurrence equations
OutputResponseoutput response of a filter
DiscreteConvolvesymbolic convolution of two signals

Apply FIR filters to signals.

Define a transfer function of a digital Butterworth filter.
In[92]:=
Click for copyable input
Compute the impulse response of the IIR filter.
In[97]:=
Click for copyable input
Out[98]=
Compute the impulse response by using the coefficients of the transfer function model.
In[101]:=
Click for copyable input
Out[101]=
Compute the impulse response using OutputResponse.
In[99]:=
Click for copyable input
Out[99]=
Compute the impulse response by solving the corresponding recurrence equation model of the filter using RecurrenceTable.
In[100]:=
Click for copyable input
Out[100]=
Lowpass filtering of a scanline of the red channel of an image.
In[102]:=
Click for copyable input
Out[104]=
Lowpass filtering of an image.
In[105]:=
Click for copyable input
Out[105]=