Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 38 ยท Filters: IIR

IIR Filters and Recursion

Learn how infinite impulse response filters use feedback, how to write their difference equations, and how to compare your own loop with scipy.signal.lfilter.

A finite impulse response (FIR) filter computes each output from a window of recent inputs. An infinite impulse response (IIR) filter also feeds past outputs back into the calculation. That feedback is called recursion, and it is the reason IIR filters can achieve a sharp frequency response with only a handful of coefficients, where an FIR filter might need hundreds.

The price is that a recursive filter can become unstable, its phase is not linear, and its impulse response never exactly reaches zero. In this chapter you learn how to build, analyze and design IIR filters; this lesson starts with the difference equation and the transfer function.

The general difference equation

An IIR filter of order N is described by

y[n] = b0 x[n] + b1 x[n-1] + ... + bM x[n-M] - a1 y[n-1] - ... - aN y[n-N]

The b coefficients weight the current and past inputs (the feed-forward part). The a coefficients weight past outputs (the feedback part). Notice the minus signs: that is the convention used by scipy.signal.lfilter, MATLAB and most textbooks, where a0 is normalized to 1.

If every a is zero you are back to an FIR filter. If at least one a is nonzero the filter is recursive and, in general, its impulse response lasts forever.

FIR versus IIR

FIR Uses only inputs
IIR Uses inputs and past outputs
Trade-off IIR is cheaper, FIR is easier

Both are LTI systems; they differ in structure and cost.

1 / 2

The simplest IIR filter: a leaky integrator

Take one feedback term: y[n] = (1 - p) x[n] + p y[n-1] with 0 < p < 1. This is an exponential moving average, also called a one-pole low-pass filter. A larger p remembers more of the past and smooths more strongly. Written with the convention above, b = [1 - p] and a = [1, -p].

Python One-pole smoother from scratch

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The impulse response is (1-p) p^n: a decaying geometric sequence. It gets tiny but never becomes exactly zero, which is what "infinite" means. In practice you can truncate it once it falls below your tolerance.

Transfer function and poles

Apply the z-transform to the difference equation and divide output by input. The result is the transfer function

H(z) = (b0 + b1 z^-1 + ... + bM z^-M) / (1 + a1 z^-1 + ... + aN z^-N)

The roots of the numerator are the zeros; the roots of the denominator are the poles. Poles near the unit circle create resonances (peaks in the frequency response); zeros near the unit circle create notches. For our smoother, H(z) = (1-p) / (1 - p z^-1) has one pole at z = p.

A causal filter is stable when every pole lies strictly inside the unit circle, |z| < 1. See stability and second-order sections for what happens when this fails and how to protect your designs.

A second-order section

A biquad has two poles and two zeros: b = [b0, b1, b2], a = [1, a1, a2]. It is the building block of almost every practical IIR filter, because high-order filters are split into cascades of biquads.

Python A resonator and its frequency response

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The gain peaks at 1000 Hz, the angle of the poles, and falls away on both sides. The impulse response rings like a decaying sinusoid, which is how a resonant system behaves.

Why recursion is efficient

Consider a low-pass filter with a transition band of 100 Hz at a 48 kHz sampling rate. An FIR design needs hundreds of taps, which means hundreds of multiplications per output sample. A 4th-order Butterworth IIR with a similar cutoff uses about ten multiplications. The memory needed is also tiny: just the last N outputs and inputs.

That efficiency is why IIR filters dominate in embedded systems, audio equalizers and control loops.

What you give up

  • Nonlinear phase. Different frequencies are delayed by different amounts, which distorts waveforms. Offline you can apply the filter forward and backward (filtfilt) to cancel the phase.
  • Stability risk. Poles can drift outside the unit circle through bad design or coefficient rounding.
  • Quantization sensitivity. In fixed-point hardware, tiny coefficient errors move poles a lot, especially for high orders.
  • Startup transient. The filter has internal state, so the first outputs depend on initial conditions.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What makes a filter recursive?

    Recursion means the output depends on previous outputs. That feedback is what gives IIR filters their infinite impulse response.
  2. 2. For y[n] = 0.1 x[n] + 0.9 y[n-1], where is the pole?

    The denominator is 1 - 0.9 z^-1, whose root is z = 0.9, inside the unit circle, so the filter is stable.
  3. 3. In scipy.signal.lfilter(b, a, x), what do the entries of a represent?

    The a vector holds the denominator coefficients, i.e. the feedback weights, written as 1 + a1 z^-1 + ... in the convention used by lfilter.
  4. 4. Why do IIR filters need fewer coefficients than FIR filters for the same sharpness?

    Because past outputs summarize all earlier history, a short recursion can produce a response that would need very many FIR taps.

Summary

  • An IIR filter's difference equation includes past outputs; its impulse response is infinite.
  • b holds feed-forward coefficients and a holds feedback coefficients, with a0 = 1.
  • Poles come from the denominator, zeros from the numerator; poles must lie inside the unit circle for stability.
  • A one-pole smoother and a two-pole resonator show the core behavior.
  • IIR is cheap and sharp, but has nonlinear phase and needs stability care.

Next: Designing IIR Filters with the Bilinear Transform