mathematics//signal processing//digital filter//IIR filter
An IIR (infinite impulse response) filter is a digital filter that computes each output from recent inputs and also from its own past outputs, and it is the workhorse of real-time sensor filtering because it cuts sharply with very few coefficients: the low-pass on a drone's gyro, the filters in a motor drive and most filters in a PLC are of this kind. Feeding its output back gives it a memory that, in principle, never ends: an impulse in makes it ring for ever, decaying.
An IIR (infinite impulse response) filter is a digital filter that computes each output from recent inputs and also from its own past outputs, and it is the workhorse of real-time sensor filtering because it cuts sharply with very few coefficients: the low-pass on a drone's gyro, the filters in a motor drive and most filters in a PLC are of this kind. Feeding its output back gives it a memory that, in principle, never ends: an impulse in makes it ring for ever, decaying.
A second-order section (a biquad) is the usual building block, five coefficients for two past inputs and two past outputs:
yk=b0xk+b1xk−1+b2xk−2−a1yk−1−a2yk−2.y_k=b_0x_k+b_1x_{k-1}+b_2x_{k-2}-a_1y_{k-1}-a_2y_{k-2} .yk=b0xk+b1xk−1+b2xk−2−a1yk−1−a2yk−2.
Those five numbers achieve a cut that an FIR filter needs dozens of taps for. The Butterworth design is the default: its passband is as flat as possible, with no ripple, so the signal in band keeps its amplitude, and a second-order Butterworth low-pass is the standard first filter on an autopilot's gyro. The first-order low-pass filter is the smallest IIR filter of all, one coefficient and one past output.
Feedback buys sharpness and charges in phase and in stability.
Different frequencies are delayed by different amounts, so a pulse comes out deformed, and the delay grows near the cut-off (a 30 Hz Butterworth at 1 kHz delays about 7.7 ms in band). Coefficients badly rounded can move the filter's poles outside the unit circle and make it oscillate on its own.
Implementation decides stability more than design. A high-order filter written as one long recursion is fragile in fixed point or single precision, because small coefficient errors move its poles far; cascading second-order sections keeps each pole pair under control (fixed-point arithmetic).
Its delay is not constant, which matters for shape and less for control. For a loop, what counts is the phase lag near crossover, and an IIR low-pass with its corner several times above the loop bandwidth costs a few degrees there; a waveform that must keep its shape (an ECG, a pulse) calls for linear phase instead.
An IIR filter is a small dynamical system. A one-coefficient section behaves exactly like a sampled first-order system and a biquad like a second-order one, its poles are eigenvalues, and its stability is the stability of a discrete linear recursion (equilibrium and stability).
On recorded data the phase distortion can be removed entirely by running it forwards and backwards (zero-phase filtering), which no live system can do.