x[0]1x[1]0x[2]0x[3]0DELAYz⁻¹0×0.25×0.25DELAYz⁻¹0×0.5y[0]–y[1]–y[2]–y[3]–1x[n−1] -> z⁻¹X(z)2Y = 0.5z⁻¹Y + 0.25X + 0.25z⁻¹X3(1 − 0.5z⁻¹)Y = 0.25(1 + z⁻¹)X4H(z) = 0.25(1 + z⁻¹)/(1 − 0.5z⁻¹)5 = 0.25(z + 1)/(z − 0.5)1from scipy import signal2b, a = [0.25, 0.25], [1, -0.5]3z, p, k = signal.tf2zpk(b, a)4w, H = signal.freqz(b, a)5h = signal.lfilter(b,a,[1,0,0,0])000000000000
-1-0.500.51-101real part of zimaginary partZ-PLANEzero −1pole 0.5z = e^jωo zero, × pole|0.5| < 1: stablez = e^jω, |z| = 1tf2zpk: −1 and 0.50π/4π/23π/4π00.51ω (radians per sample)gain|H(e^jω)|falls from 1 to 0ω = π/2: |H| = 0.316freqz gives this curve
Coloured parts: what the current step is about; everything else rests in whiteBlocks: input cells x[n], two delay boxes, three weights, the adder, output cells y[n], an algebra card and a Python cardPlots: the z-plane with the unit circle, the zero o and the pole ×; and the gain |H(e^jω)| from ω = 0 to πValue tokens carry the impulse one sample at a time; a point walks the unit circle in the frequency stepsThe filter y[n] = 0.5·y[n−1] + 0.25·x[n] + 0.25·x[n−1] has impulse response 1/4, 3/8, 3/16, 3/32 ... and transfer function H(z) = 0.25(z + 1)/(z − 0.5): a zero at −1, a pole at 0.5, a low-pass gain from 1 down to 0. H(z) is the discrete-time twin of H(s): the Circuits lessons "Circuit analysis with the Laplace transform" and "Transfer functions and Bode plots" do the same for circuits, with the jω axis playing the part of the unit circle.

A filter and its impulse response

  1. Our filter follows y[n] = 0.5·y[n−1] + 0.25·x[n] + 0.25·x[n−1]. Two delay boxes remember the last input and the last output. Three weights scale the values, and the adder sums them into the new output.

From the equation to H(z)

Poles, zeros and frequency

In code

The working

# step 1/11 · system

y[n] = 0.5·y[n−1] + 0.25·x[n] + 0.25·x[n−1]

x[n]     input, sample number n
y[n]     output, sample number n
x[n−1]   the input one sample ago   (input delay)
y[n−1]   the output one sample ago  (output delay)

weights: 0.25 and 0.25 on the inputs
         0.5 on the old output (feedback)
start at rest: both delays hold 0

The weights 0.25, 0.25 and 0.5 are chosen so every impulse-response value is a short exact fraction and the gain at ω = 0 is exactly 1. Every number in the figure is computed from this model; the Python output was checked with scipy 1.18. H(z) here is causal with region of convergence |z| > 0.5. Because that region contains the unit circle, the frequency response is H(z) evaluated at z = e^jω (Oppenheim and Schafer, ch. 5).