# IIR Filters

Infinite impulse response (IIR) filters, also known as recursive filters and autoregressive-moving average (ARMA) filters, operate on current and past input values and current and past output values. The impulse response of an IIR filter is the response of the general IIR filter to an impulse, as the following equations define impulse:

x0 = 1 xi = 0 | (A)

for all i ≠ 0.

Theoretically, the impulse response of an IIR filter never reaches zero and is an infinite response.

The following general difference equation characterizes IIR filters.

| (B)

where bj is the set of forward coefficients, Nb is the number of forward coefficients, ak is the set of reverse coefficients, and Na is the number of reverse coefficients.

Equation A describes a filter with an impulse response of theoretically infinite length for nonzero coefficients. However, in practical filter applications, the impulse response of a stable IIR filter decays to near zero in a finite number of samples.

In most IIR filter designs and the LabWindows/CVI IIR filters, coefficient a0 is 1. The output sample at the current sample index i is the sum of scaled current and past inputs and scaled past outputs, as shown by Equation B.

| (C)

where xi is the current input, xi – j is the past inputs, and yi – k is the past outputs.

IIR filters might have ripple in the passband, the stopband, or both. IIR filters have a nonlinear-phase response.

## Cascade Form IIR Filtering

Equation C defines the direct-form transfer function of an IIR filter.

| (D)

A filter implemented by directly using the structure defined by Equation C after converting it to the difference equation in Equation B is a direct-form IIR filter. A direct-form IIR filter often is sensitive to errors introduced by coefficient quantization and by computational precision limits. Also, a filter with an initially stable design can become unstable with increasing coefficient length. The filter order is proportional to the coefficient length. As the coefficient length increases, the filter order increases. As filter order increases, the filter becomes more unstable.

You can lessen the sensitivity of a filter to error by writing Equation C as a ratio of z transforms, which divides the direct-form transfer function into lower order sections, or filter stages.

By factoring Equation C into second-order sections, the transfer function of the filter becomes a product of second-order filter functions, as shown in Equation D.

| (E)

where Ns is the number of stages, Ns = [Na/2] is the largest integer less than or equal to (Na/2), and Na ≥ Nb.

You can describe the filter structure defined by Equation D as a cascade of second-order filters. The following figure illustrates cascade filtering.

| (F)

You can implement each individual filter stage in the previous figure with the direct-form II filter structure. You then can use the direct-form II filter structure to implement each filter stage for the following reasons:

- The direct-form II filter structure requires a minimum number of arithmetic operations.
- The direct-form II filter structure requires a minimum number of delay elements, or internal filter states.
- Each kth stage has one input, one output, and two past internal states, sk[i – 1] and sk[i – 2].

If n is the number of samples in the input sequence, the filtering operation proceeds as shown in the following equations:

y0[i] = x[i] | (G)

sk[i] = yk – 1[i – 1] – a1ksk[i – 1] – a2ksk[i – 2] | (H)

yk[i] = b0ksk[i] + b1ksk[i – 1] + b2ksk[i – 2] | (I)

for each sample i = 0, 1, 2, …, n – 1 and k = 1, 2, …, Ns.

### Second-Order Filtering

For lowpass and highpass filters, which have a single cut-off frequency, you can design second-order filter stages directly. The resulting IIR lowpass or highpass filter contains cascaded second-order filters.

Each second-order filter stage has the following characteristics:

- k = 1, 2, …, Ns, where k is the second-order filter stage number and Ns is the total number of second-order filter stages.
- Each second-order filter stage has two reverse coefficients, (a1k, a2k).
- The total number of reverse coefficients equals 2Ns.
- Each second-order filter stage has three forward coefficients, (b0k, b1k, b2k).
- The total number of forward coefficients equals 3Ns.

For example, an IIR filter with two second-order filter stages must have a total of four reverse coefficients and six forward coefficients, as shown in the following equations.

Total number of reverse coefficients = 2Ns = 2 × 2 = 4

Reverse Coefficients = {a11, a21, a12, a22}

Total number of forward coefficients = 3Ns = 3 × 2 = 6

Forward Coefficients = {b01, b11, b21, b02, b12, b22}

### Fourth-Order Filtering

For bandpass and bandstop filters, which have two cut-off frequencies, fourth-order filter stages are a more direct form of filter design than second-order filter stages. IIR bandpass or bandstop filters resulting from fourth-order filter design contain cascaded fourth-order filters.

Each fourth-order filter stage has the following characteristics:

- k = 1, 2, …, Ns, where k is the fourth-order filter stage number and Ns is the total number of fourth-order filter stages.
- Ns = [(Na + 1)/4]
- Each fourth-order filter stage has four reverse coefficients, (a1k, a2k, a3k, a4k).
- The total number of reverse coefficients equals 4Ns.
- Each fourth-order filter stage has five forward coefficients, (b0k, b1k, b2k, b3k, b4k).
- The total number of forward coefficients equals 5Ns.

You implement cascade stages in fourth-order filtering in the same manner as in second-order filtering. The following equations show how the filtering operation for fourth-order stages proceeds.

y0[i] = x[i] | (J)

sk[i] = yk – 1[i – 1] – a1ksk[i – 1] – a2ksk[i – 2] – a3ksk[i – 3] – a4ksk[i – 4] | (K)

yk[i] = b0ksk[i] + b1ksk[i – 1] + b2ksk[i – 2] – b3ksk[i – 3] – b4ksk[i – 4] | (L)

where k = 1, 2, …, Ns.

## IIR Filter Types

Digital IIR filter designs come from the classical analog designs and include the following filter types:

- Butterworth filters
- Chebyshev filters
- Chebyshev II filters, also known as inverse Chebyshev and Type II Chebyshev filters
- Elliptic filters, also known as Cauer filters
- Bessel filters

The IIR filter designs differ in the sharpness of the transition between the passband and the stopband and where they exhibit their various characteristics—in the passband or the stopband.

### Minimizing Peak Error

The Chebyshev, Chebyshev II, and elliptic filters minimize peak error by accounting for the maximum tolerable error in their frequency response. The maximum tolerable error is the maximum absolute value of the difference between the ideal filter frequency response and the actual filter frequency response. The amount of ripple, in dB, allowed in the frequency response of the filter determines the maximum tolerable error. Depending on the type, the filter minimizes peak error in the passband, stopband, or both.

### Butterworth Filters

Butterworth filters have the following characteristics:

- Smooth response at all frequencies
- Monotonic decrease from the specified cut-off frequencies
- Maximal flatness, with the ideal response of unity in the passband and zero in the stopband
- Half-power frequency, or 3 dB down frequency, that corresponds to the specified cut-off frequencies

The advantage of Butterworth filters is their smooth, monotonically decreasing frequency response. The following figure shows the frequency response of a lowpass Butterworth filter.

As shown in the previous figure, after you specify the cut-off frequency of a Butterworth filter, LabWindows/CVI sets the steepness of the transition proportional to the filter order. Higher order Butterworth filters approach the ideal lowpass filter response.

Butterworth filters do not always provide a good approximation of the ideal filter response because of the slow rolloff between the passband and the stopband.

### Chebyshev Filters

Chebyshev filters have the following characteristics:

- Minimization of peak error in the passband
- Equiripple magnitude response in the passband
- Monotonically decreasing magnitude response in the stopband
- Sharper rolloff than Butterworth filters

Compared to a Butterworth filter, a Chebyshev filter can achieve a sharper transition between the passband and the stopband with a lower order filter. The sharp transition between the passband and the stopband of a Chebyshev filter produces smaller absolute errors and faster execution speeds than a Butterworth filter.

The following figure shows the frequency response of a lowpass Chebyshev filter.

In the previous figure, the maximum tolerable error constrains the equiripple response in the passband. Also, the sharp rolloff appears in the stopband.

### Chebyshev II Filters

Chebyshev II filters have the following characteristics:

- Minimization of peak error in the stopband
- Equiripple magnitude response in the stopband
- Monotonically decreasing magnitude response in the passband
- Sharper rolloff than Butterworth filters

Chebyshev II filters are similar to Chebyshev filters. However, Chebyshev II filters differ from Chebyshev filters in the following ways:

- Chebyshev II filters minimize peak error in the stopband instead of the passband. Minimizing peak error in the stopband instead of the passband is an advantage of Chebyshev II filters over Chebyshev filters.
- Chebyshev II filters have an equiripple magnitude response in the stopband instead of the passband.
- Chebyshev II filters have a monotonically decreasing magnitude response in the passband instead of the stopband.

The following figure shows the frequency response of a lowpass Chebyshev II filter.

In the previous figure, the maximum tolerable error constrains the equiripple response in the stopband. Also, the smooth monotonic rolloff appears in the stopband.

Chebyshev II filters have the same advantage over Butterworth filters that Chebyshev filters have—a sharper transition between the passband and the stopband with a lower order filter, resulting in a smaller absolute error and faster execution speed.

### Elliptic Filters

Elliptic filters have the following characteristics:

- Minimization of peak error in the passband and the stopband
- Equiripples in the passband and the stopband

Compared with the same order Butterworth or Chebyshev filters, the elliptic filters provide the sharpest transition between the passband and the stopband, which accounts for their widespread use.

The following figure shows the frequency response of a lowpass elliptic filter.

In the previous figure, the same maximum tolerable error constrains the ripple in both the passband and the stopband. Also, even low-order elliptic filters have a sharp transition edge.

### Bessel Filters

Bessel filters have the following characteristics:

- Maximally flat response in both magnitude and phase
- Nearly linear-phase response in the passband

You can use Bessel filters to reduce nonlinear-phase distortion inherent in all IIR filters. High-order IIR filters and IIR filters with a steep rolloff have a pronounced nonlinear-phase distortion, especially in the transition regions of the filters. You also can obtain linear-phase response with FIR filters.

The following figure shows the magnitude and phase responses of a lowpass Bessel filter.

In the previous figure, the magnitude is smooth and monotonically decreasing at all frequencies.

The following figure shows the phase response of a lowpass Bessel filter.

The previous figure shows the nearly linear phase in the passband. Also, the phase monotonically decreases at all frequencies.

Like Butterworth filters, Bessel filters require high-order filters to minimize peak error, which accounts for their limited use.

## Designing IIR Filters

When choosing an IIR filter for an application, you must know the response of the filter. The following figure shows the magnitude and the phase responses of a bandpass elliptic IIR filter.

In the previous figure, the phase information is clearly nonlinear. When deciding whether to use an IIR or FIR filter to process data, remember that IIR filters provide nonlinear phase information.

### IIR Filter Characteristics in LabWindows/CVI

IIR filters in LabWindows/CVI have the following characteristics:

- IIRFiltering interprets values at negative indexes in Equation A as zero the first time you call the function.
- A transient response, or delay, proportional to the filter order occurs before the filter reaches a steady state.
- The number of elements in the filtered sequence equals the number of elements in the input sequence.
- The filter retains the internal filter state values when the filtering process finishes.

### Transient Response

The transient response occurs because the initial filter state is zero or has values at negative indexes. The duration of the transient response depends on the filter type.

The duration of the transient response for lowpass and highpass filters equals the filter order.

delay = order

The duration of the transient response for bandpass and bandstop filters equals twice the filter order.

delay = 2 × order

You can eliminate the transient response on successive calls to IIRFiltering by enabling state memory.

The following figure shows the transient response and the steady state for an IIR filter.