# IIR Filters

LabVIEW 2011 Help

Edition Date: June 2011

Part Number: 371361H-01

»View Product Info

Infinite impulse response (IIR) filters, also known as recursive 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:

 x 0 = 1 x i = 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 b j is the set of forward coefficients, N b is the number of forward coefficients, a k is the set of reverse coefficients, and N a 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 all of the LabVIEW IIR filters, coefficient a 0 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 C.

 (C)

where x i is the current input, x i j is the past inputs, and y i k is the past outputs.

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

 Note  If you plan to use the LabVIEW Digital Filter Design Toolkit to design digital filters, first refer to the Digital Filter Design Basics book for more information about the fundamentals of filter design.

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

 (D)

A filter implemented by directly using the structure defined by Equation D after converting it to the difference equation in Equation C 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 D as a ratio of z transforms, which divides the direct-form transfer function into lower order sections, or filter stages.

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

 (E)

where N s is the number of stages, N s = [N a/2] is the largest integer less than or equal to (N a/2), and N aN b.

You can describe the filter structure defined by Equation E as a cascade of second-order filters. The following illustration shows cascade filtering.

 (F)

You can implement each individual filter stage in the previous illustration 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 k th stage has one input, one output, and two past internal states, s k[i – 1] and s k[i – 2].

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

 y 0[i] = x[i] (G)
 s k[i] = y k – 1[i] – a 1 k s k[i – 1] – a 2 k s k[i – 2] (H)
 y k[i] = b 0 k s k[i] + b 1 k s k[i – 1] + b 2 k s k[i – 2] (I)

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

### 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, …, N s, where k is the second-order filter stage number and N s is the total number of second-order filter stages.
• Each second-order filter stage has two reverse coefficients, (a 1 k, a 2 k).
• The total number of reverse coefficients equals 2N s.
• Each second-order filter stage has three forward coefficients, (b 0 k, b 1 k, b 2 k).
• The total number of forward coefficients equals 3N s.

In Signal Processing VIs with Reverse Coefficients and Forward Coefficients parameters, the Reverse Coefficients and the Forward Coefficients arrays contain the coefficients for one second-order filter stage, followed by the coefficients for the next second-order filter stage, and so on.

 Note  You can use the Signal Processing VIs only in the LabVIEW Full and Professional Development Systems.

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 = 2N s = 2 × 2 = 4

Reverse Coefficients = {a 11, a 21, a 12, a 22}

Total number of forward coefficients = 3N s = 3 × 2 = 6

Forward Coefficients = {b 01, b 11, b 21, b 02, b 12, b 22}

### 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, …, N s, where k is the fourth-order filter stage number and N s is the total number of fourth-order filter stages.
• N s = [(N a + 1)/4]
• Each fourth-order filter stage has four reverse coefficients, (a 1 k, a 2 k, a 3 k, a 4 k).
• The total number of reverse coefficients equals 4N s.
• Each fourth-order filter stage has five forward coefficients, (b 0 k, b 1 k, b 2 k, b 3 k, b 4 k).
• The total number of forward coefficients equals 5N s.

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.

 y 0[i] = x[i] (J)
 s k[i] = y k – 1[i – 1] – a 1 k s k[i – 1] – a 2 k s k[i – 2] – a 3 k s k[i – 3] – a 4 k s k[i – 4] (K)
 y k[i] = b 0 k s k[i] + b 1 k s k[i – 1] + b 2 k s k[i – 2] + b 3 k s k[i – 3] + b 4 k s k[i – 4] (L)

where k = 1, 2, …, N s.

## IIR Filter Types

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

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 front panel shows the frequency response of a lowpass Butterworth filter.

As shown on the previous front panel, after you specify the cut-off frequency of a Butterworth filter, LabVIEW 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 roll-off 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 roll-off 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 front panel shows the frequency response of a lowpass Chebyshev filter.

In the previous front panel, the maximum tolerable error constrains the equiripple response in the passband. Also, the sharp roll-off 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 roll-off 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 front panel shows the frequency response of a lowpass Chebyshev II filter.

In the previous front panel, the maximum tolerable error constrains the equiripple response in the stopband. Also, the smooth monotonic roll-off 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 front panel shows the frequency response of a lowpass elliptic filter.

In the previous front panel, 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 roll-off 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 front panel shows the magnitude and phase responses of a lowpass Bessel filter.

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

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

The previous front panel 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 block diagram belongs to a VI that returns the frequency response of an IIR filter.

Because the same mathematical theory applies to designing IIR and FIR filters, the previous block diagram of a VI that returns the frequency response of an IIR filter and the block diagram of a VI that returns the frequency response of an FIR filter share common design elements. The main difference between the two VIs is that the Case structure on the left side of the previous block diagram specifies the IIR filter design and filter type instead of specifying only the filter type. The previous block diagram belongs to a VI that computes the frequency response of an IIR filter by following the same steps outlined for designing FIR filters.

The following front panel shows the magnitude and the phase responses of a bandpass elliptic IIR filter.

In the previous front panel, 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 LabVIEW

IIR filters in LabVIEW have the following characteristics:

• The IIR Filter VI interprets values at negative indexes in Equation A as zero the first time you call the VI.
• 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 an IIR Filter VI by enabling state memory. To enable state memory for continuous filtering, wire a value of TRUE to the init/cont input of the IIR Filter VI.

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

Your Feedback!  Poor  |  Excellent    Yes No
 Document Quality?