11.3. Common IIR filters#

In the last section, we were introduced to the Butterworth filter, which is one of the earliest and most commonly used IIR filters. In this section, we’ll meet a few more types of IIR filter. None of them are necessarily better or worse than the others: they each have benefits and drawbacks. Having a sense of the various trade-offs made by each type of filter is important if you plan to apply these in practice.

11.3.1. Chebyshev filters#

The next family of filters that we’ll see are known as Chebyshev filters, named for the mathematician Pafnuty Chebyshev, who initially developed the underlying family of polynomial functions upon which the filters are based. There are two types of Chebyshev filters, not-so-conveniently named Type 1 and Type 2.

11.3.1.1. Type 1#

Type-1 Chebyshev filters have a steeper transition than Butterworth filters, at the expense of introducing ripple in the pass-band. They are constructed by the function scipy.signal.cheby1, which has as its key parameters:

  • the order of the filter, which can be derived by scipy.signal.cheby1ord,

  • the maximum amount of passband ripple we’ll allow, and

  • the cutoff frequency.

Continuing our example from the previous section, a 500 Hz low-pass filter could be constructed as follows:

fs = 44100  # Sampling rate
fc = 500  # Cutoff frequency
fstop = 1000  # stop-band at 1000

ripple = 3  # we'll allow 3 dB ripple in the passband
attenuation = 60  # we'll require 60 dB attenuation in the stop band

# Get the order and discard the second output (natural frequency)
order, _  = scipy.signal.cheb1ord(fc, fstop, ripple, attenuation, fs=fs)

# Build the filter
b, a = scipy.signal.cheby1(order, ripple, fc, fs=fs)

Fig. 11.6 illustrates the results of applying this filter to an impulse \(x\), and how it compares to a Butterworth filter.

Illustration of type-1 Chebyshev filter

Fig. 11.6 A type-1 Chebyshev filter with 3dB passband ripple, cutoff frequency of \(f_c=500\), and stop-band starting at 1000 Hz is applied to an impulse \(\blue{x}\) to produce the impulse response \(y\), measured for 2000 samples (at \(f_s=44100\)). For comparison purposes, a Butterworth filter with the same cutoff and order is also computed. Top: the impulse, and impulse response. Middle: the DFT magnitude \(|Y|\) measured in decibels. Bottom: the unwrapped phase spectrum \(\phi'\).#

As Fig. 11.6 illustrates, the frequency response drops much more rapidly after \(f_c\) than that of the Butterworth filter. The cost of this is two-fold:

  1. There is ripple in the pass-band: \(|Y|\) is not constant for frequencies below \(f_c\).

  2. There is more phase distortion: \(\phi'\) deviates significantly from linear phase (plotted as a straight line).

11.3.1.2. Type 2#

Type-2 Chebyshev filters are similar to type-1, except the pass-band remains flat and ripple is allowed in the stop-band. Type-2 filters are constructed by scipy.signal.cheby2, which is similar to the cheby1 function above, but with two key differences:

  1. The stop-band attenuation is provided, instead of the pass-band ripple, and

  2. The end of the transition region is provided, rather than the cutoff frequency \(f_c\).

Similarly, the order of the filter is computed by scipy.signal.cheb2ord, which takes all the same parameters as cheb1ord.

# Get the order and discard the second output (natural frequency)
order2, _  = scipy.signal.cheb2ord(fc, fstop, ripple, attenuation, fs=fs)

# Build the filter
b2, a2 = scipy.signal.cheby2(order2, attenuation, fstop, fs=fs)

Fig. 11.7 illustrates the behavior of the type-2 filter, compared to the type-1 filter with similar constraints.

Comparison of type-1 and type-2 Chebyshev filters

Fig. 11.7 A type-2 Chebyshev filter with 60dB stop-band attenuation, cutoff frequency of \(f_c=500\), and stop-band starting at 1000 Hz.. The type-1 filter from Fig. 11.6 is included for comparison purposes. Top: the impulse, and impulse response. Middle: the DFT magnitude \(|Y|\) measured in decibels. Bottom: the unwrapped phase spectrum \(\phi'\).#

Compared to the type-1 filter, Fig. 11.7 shows that the type-2 filter has a shallower transition, though it is still steeper than that of the Butterworth filter. Note that the pass-band frequency response has no ripple, and the phase is much closer to linear. We should therefore expect better preservation of the low-frequency content with the type-2 filter than with the type-1 filter. The main cost is that the transition region has less attenuation, so the filter will not be as sharp, and frequencies above \(f_c\) will propagate through slightly more with the type-2 filter.

11.3.2. Elliptic filters#

So far, we’ve seen:

  • the Butterworth filter, which has no ripple in either the pass-band or the stop-band;

  • the type-1 Chebyshev filter, which has pass-band ripple but no stop-band ripple; and

  • the type-2 Chebyshev filter, which has stop-band ripple but no pass-band ripple.

If we allow ripple in both the pass- and stop-bands, we get what are known as elliptic filters. The main benefit of elliptic filters is that they can have extremely steep transitions.

Elliptic filters are provided by scipy.signal.ellip (and with order helper scipy.signal.ellipord). The ellip function can be thought of as generalizing both cheby1 and cheby2, so it requires all of the parameters of either individual function:

  • the order of the filter;

  • the pass-band ripple;

  • the stop-band attenuation; and

  • the cutoff frequency (like in cheby1, not the end of the transition like in cheby2!)

The ellipord helper function works just like cheby1 and cheby2, and the following code can be used to construct an elliptic low-pass filter:

# Get the order and discard the second output (natural frequency)
order_ell, _  = scipy.signal.ellipord(fc, fstop, ripple, attenuation, fs=fs)

# Build the filter
b_ell, a_ell = scipy.signal.ellip(order_ell, ripple, attenuation, fc, fs=fs)
An elliptic filter compared to Chebyshev filters

Fig. 11.8 An elliptic filter with 3dB pass-band ripple, 60dB stop-band attenuation, cutoff frequency of \(f_c=500\), and stop-band starting at 1000 Hz. Chebyshev filters are included for comparison purposes. Top: the impulse, and impulse response. Middle: the DFT magnitude \(|Y|\) measured in decibels. Bottom: the unwrapped phase spectrum \(\phi'\).#

Fig. 11.8 shows that allowing ripple in both the pass- and stop-bands allows the Elliptic filter to achieve a much steeper transition than either type-1 or type-2 Chebyshev filters. Note, however, that this also results in quite a bit of phase distortion in the Elliptic filter.

11.3.3. Summary#

The examples above are not exhaustive, and merely illustrate a few features of each of the filters in question. Notably, we did not vary the ripple, attenuation, or transition region constraints here, and these parameters have enormous influence on the behavior of the filters. For example, allowing more ripple (type-1 or elliptic) can provide a steeper transition.

Compared to FIR filters, IIR filters can be more efficient, achieving comparable performance (e.g., stop-band attenuation) at a fraction of the computational cost dictated by the order. This makes IIR filters an attractive choice for real-time processing applications, where computational efficiency and latency are critical. However, we’ve also seen that IIR filters can have non-linear phase response, which may not be desirable depending on the application.

So which filter should you use? It depends! (I know, not so helpful of an answer.)

A few things to keep in mind:

  1. If you do not want any attenuation of pass-band frequencies, stick to Butterworth or Type-2 Chebyshev.

  2. How much phase distortion can you tolerate? Or can you compensate for it by using bidirectional filtering?

  3. If you need steep transitions, Elliptic might be the best option.

The table below summarizes the properties of the four filter types we’ve seen.

Filter type

Pass-band ripple

Stop-band ripple

Transition

Phase distortion

Butterworth

Slow

Small

Chebyshev (Type-1)

Medium

Medium

Chebyshev (Type-2)

Medium

Small

Elliptic

Fast

Large