ScienceComputer Science

Z-Transform
calculator.

Find the poles, zeros, stability and frequency response of a digital filter H(z).

How it's worked out

A linear digital filter computes each output sample y[n] from the current and past inputs x and its own past outputs. The coefficients b weight the inputs and a weight the outputs:

a0y[n]+a1y[n−1]+a2y[n−2]\displaystyle a_0 y[n] + a_1 y[n-1] + a_2 y[n-2]=b0x[n]+b1x[n−1]+b2x[n−2]\displaystyle {}= b_0 x[n] + b_1 x[n-1] + b_2 x[n-2]

The z-transform turns a delay of one sample into a factor z−1z^{-1}. Applied to both sides, the equation becomes a ratio of two polynomials, the transfer function H(z). You enter b and a in that order, starting with the power 0, the same order SciPy and MATLAB use.

H(z)\displaystyle H(z)=b0+b1z−1+b2z−2a0+a1z−1+a2z−2\displaystyle {}= \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}

The zeros are the values of z that make the top 0, and the poles are the values that make the bottom 0. The tool multiplies top and bottom by a power of z so both are ordinary polynomials, then finds every root, real or complex, by the Durand-Kerner iteration.

A causal filter is stable when every pole lies strictly inside the unit circle, where |z| < 1. Each pole p adds a term that behaves like p to the power n in the impulse response, so a pole of magnitude 0.5 halves that term every sample, and a pole of magnitude 1.2 makes it grow.

The frequency response is H on the unit circle, at z=ejωz = e^{j\omega}, with ω from 0 (DC) to π (the Nyquist frequency, half the sampling rate). The gain is its size |H|. Poles near the circle lift the gain at their angle and zeros on the circle push it to 0.

Worked examples

A one-pole smoother

The filter y[n] = x[n] + 0.5y[n − 1] has b = 1 and a = 1, −0.5, so H(z) = 1 ÷ (1 − 0.5z⁻¹). The bottom is 0 at z = 0.5, one pole inside the unit circle, so the filter is stable.

Feed in a single 1 and the output is 1, 0.5, 0.25, 0.125, 0.0625 and so on, halving each time. The gain is 2 at DC and 0.6667 at Nyquist, so slow changes pass through and fast wiggles are damped: a gentle low-pass filter.

Open this example in the tool

A resonance from complex poles

H(z) = 1 ÷ (1 − z⁻¹ + 0.5z⁻²) has a pair of poles at 0.5 + 0.5j and 0.5 − 0.5j. Their magnitude is 0.7071, inside the circle, so it is stable.

Complex poles make the impulse response swing: 1, 1, 0.5, 0, −0.25, −0.25, −0.125. The gain peaks at 2.8284 near 0.23π, higher than 2 at DC. Move the poles closer to the circle and the peak gets taller and narrower.

Open this example in the tool

A four-point moving average

Averaging the last four inputs gives b = 0.25 four times and a = 1. There are no poles away from the origin, so the filter is stable and its impulse response is just 0.25, 0.25, 0.25, 0.25, 0: it ends after four samples. Filters like this are called FIR, finite impulse response.

The zeros sit on the unit circle at 0 + 1j, −1, 0 − 1j. The gain is 1 at DC but 0 at Nyquist and 0 at half of it, so the average wipes out a tone at those two frequencies completely.

Open this example in the tool

Reading your result

The verdict comes from the largest pole. Under 1 means stable, so any bounded input gives a bounded output. A pole exactly on the circle is on the edge: the response never dies away. Above 1 the output grows without limit.

How close the largest pole is to the circle tells you how long the filter rings. With a pole at 0.5 the impulse response is down to 0.0078 after 8 samples. With a pole at 0.99 it is still 0.9321.

The shape sentence compares the gain at DC, at Nyquist and at any peak in between. It is a quick label, not a full filter specification; for cut-off frequencies and ripple, read the gain curve.

In the roots table the angle is in multiples of π. A pole or zero at angle θ affects the gain most near ω = θ, so a zero at 0.5π removes a tone at half the Nyquist frequency.

Common mistakes

  • Entering coefficients in powers of z instead of z⁻¹. The tool reads b and a starting at the power 0 of z⁻¹, as SciPy’s lfilter and MATLAB’s filter do. A textbook written in positive powers of z needs its list read the other way round, padded so the lengths match.
  • Forgetting the minus sign on feedback. y[n] = x[n] + 0.5y[n − 1] has a₁ = −0.5, not 0.5, because the output terms move to the left side. With +0.5 the pole moves to −0.5 and the filter becomes high-pass.
  • Reading the gain of an unstable filter. 1 ÷ (1 − 1.2z⁻¹) has a pole at 1.2 and its impulse response grows: 1, 1.2, 1.44, 1.728, 2.0736. The curve can still be drawn, but no causal filter delivers it.
  • Missing the poles at the origin. 1 ÷ (1 − 0.75z⁻¹ + 0.125z⁻²) has 2 zeros at z = 0 once written in powers of z. They do not change the gain, but they count toward the order.
  • Rounding coefficients from a design tool. In a high-order filter, cutting coefficients to a few digits can move a pole from just inside the circle to just outside. Paste them at full length and use the decimal places control only for display.

Questions people ask

Find the roots of the denominator and check their size. If every one has magnitude below 1, the causal filter is stable; a single pole on or outside the unit circle makes the output grow or ring forever. A pole cancelled by an equal zero does not count, so cancel common factors first.

Sources