ENع
←Transfer functions H(z)
Lesson 35 · The Z-transform

Transfer functions H(z)

16 min11 steps5 questionsAdvanced
About this lesson

A transfer function H(z) is one formula that captures a whole digital system. Take the filter y[n] = 0.5·y[n−1] + 0.25·x[n] + 0.25·x[n−1], watch its impulse response come out as 1/4, 3/8, 3/16, 3/32 ..., then turn every delay into z⁻¹ and solve for H(z) = Y(z)/X(z) = 0.25(z + 1)/(z − 0.5). You will find its zero and pole, see that H(z) is the Z-transform of h[n], and walk a point around the unit circle to get the frequency response of a low-pass filter. It builds on "The Z-transform and its region of convergence" and "The inverse Z-transform with partial fractions"; the continuous-time version is in the Circuits lessons on the Laplace transform and on transfer functions and Bode plots.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 35 · Interactive
01 / 11

A filter drawn as blocks

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.

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
Loading figure…
or ← →
Read the lesson step by step
  1. A filter drawn as blocks

    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.

    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
  2. Feed in one impulse

    Send in a single 1, then zeros: the impulse δ[n]. Out come 1/4, 3/8, 3/16, 3/32 ... This list is the impulse response h[n]. It describes the system completely, but it never ends.

    input δ[n] = 1, 0, 0, 0 ...
    
    n   0.25·x[n]  0.25·x[n−1]  0.5·y[n−1]  y[n]
    0   1/4        0            0           1/4
    1   0          1/4          1/8         3/8
    2   0          0            3/16        3/16
    3   0          0            3/32        3/32
    
    as decimals: 0.25, 0.375, 0.1875, 0.09375 ...
    so h[n] = 0.25, 0.375, 0.1875, 0.09375 ...
  3. A delay is a multiply by z⁻¹

    The Z-transform turns a list x[n] into a function X(z). Its shift rule says x[n−1] becomes z⁻¹X(z). So each delay box is simply "multiply by z⁻¹". That is why books label delays z⁻¹.

    Z-transform:  X(z) = Σ x[n]·z⁻ⁿ
    
    shift rule (one sample later):
      x[n−1]  <->  z⁻¹·X(z)
      y[n−1]  <->  z⁻¹·Y(z)
    
    z is a complex number;
    z⁻¹ = 1/z
    
    a delay in time = multiply by z⁻¹
    (the Z-transform itself: lesson
     "The Z-transform and its region of convergence")
  4. Transform every term

    Apply the Z-transform to both sides. Each list becomes a function of z, each delay becomes z⁻¹, and the weights stay as they are: Y = 0.5z⁻¹Y + 0.25X + 0.25z⁻¹X. No more sample-by-sample loop.

    time:  y[n] = 0.5·y[n−1] + 0.25·x[n] + 0.25·x[n−1]
    
    z:     Y(z) = 0.5·z⁻¹Y(z) + 0.25·X(z) + 0.25·z⁻¹X(z)
    
    the transform is linear:
      weights pass straight through
      sums stay sums
      each delay -> one factor z⁻¹
  5. Divide: H(z) = Y(z)/X(z)

    Move the Y terms left and factor: (1 − 0.5z⁻¹)Y = 0.25(1 + z⁻¹)X. Divide output by input. The ratio H(z) = 0.25(1 + z⁻¹)/(1 − 0.5z⁻¹) is the transfer function. It no longer depends on the input.

    Y − 0.5z⁻¹Y = 0.25X + 0.25z⁻¹X
    (1 − 0.5z⁻¹)·Y = 0.25(1 + z⁻¹)·X
    
              Y(z)     0.25 + 0.25z⁻¹
    H(z) = ------ = --------------
              X(z)       1 − 0.5z⁻¹
    
    top:     the input weights  b = [0.25, 0.25]
    bottom:  1, then minus the feedback  a = [1, −0.5]
    for ANY input:  Y(z) = H(z)·X(z)
  6. H(z) is the transform of h[n]

    For the impulse, X(z) = 1, so Y(z) = H(z): the transfer function is the Z-transform of h[n]. Partial fractions give back h[0] = 1/4 and h[n] = 0.75·0.5ⁿ: 3/8, 3/16, 3/32, as the cells show.

    δ[n] <-> 1,  so  Y(z) = H(z)·1 = H(z)
    
    partial fractions (previous lesson):
    H(z) = 0.25(1 + z⁻¹)/(1 − 0.5z⁻¹)
         = −0.5 + 0.75/(1 − 0.5z⁻¹)
    
    h[n] = −0.5·δ[n] + 0.75·0.5ⁿ·u[n]
      h[0] = −0.5 + 0.75 = 0.25
      h[1] = 0.375   h[2] = 0.1875   h[3] = 0.09375
    
    convolution y = h * x  becomes  Y = H·X
  7. One zero, one pole

    Multiply top and bottom by z: H(z) = 0.25(z + 1)/(z − 0.5). The top is 0 at z = −1: a zero. The bottom is 0 at z = 0.5: a pole, where H grows without limit. Plot them on the z-plane.

    H(z) = 0.25(1 + z⁻¹)/(1 − 0.5z⁻¹)    × z/z
         = 0.25(z + 1)/(z − 0.5)
    
    zero:  z + 1 = 0    ->  z = −1   (drawn o)
    pole:  z − 0.5 = 0  ->  z = 0.5  (drawn ×)
    gain:  0.25
    
    z-plane: real part across, imaginary part up
    dashed circle: |z| = 1, the unit circle
  8. The pole is the feedback

    The pole 0.5 is the feedback weight. After n = 1 each output is 0.5 times the last: 3/8, 3/16, 3/32. The pole sits inside the unit circle (|0.5| < 1), so the response dies away: the filter is stable.

    h[n] = 0.75·0.5ⁿ for n ≥ 1
    
    ratio of neighbours:
      h[2]/h[1] = 0.1875/0.375 = 0.5
      h[3]/h[2] = 0.09375/0.1875 = 0.5
    = the pole
    
    |pole| < 1  ->  h[n] shrinks  ->  stable
    |pole| > 1  ->  h[n] grows    ->  unstable
    (more in "Stability and the unit circle")
  9. Walk around the unit circle

    Put z = e^jω, a point on the unit circle at angle ω. Then H(e^jω) is the frequency response. Its size is 0.25 × (distance to the zero) ÷ (distance to the pole). From ω = 0 to π it falls from 1 to 0.

    z = e^jω = cos ω + j·sin ω,  |z| = 1
    ω in radians per sample, 0 .. π
    
    |H(e^jω)| = 0.25 · |e^jω + 1| / |e^jω − 0.5|
                = 0.25 · (to the zero) / (to the pole)
    
    ω = 0:  0.25 × 2 / 0.5 = 1.000
    ω = π:  0.25 × 0 / 1.5 = 0
    
    allowed because the ROC |z| > 0.5
    contains the unit circle
  10. Low frequencies pass

    At ω = π/2 the distances are 1.414 and 1.118, so |H| = 0.25 × 1.414 ÷ 1.118 = 0.316. Near the pole the gain is high; at the zero it is 0. Slow wiggles pass, fast ones are blocked: a low-pass filter.

    ω = π/2:  z = j
      to the zero: |j + 1|   = √2    = 1.414
      to the pole: |j − 0.5| = √1.25 = 1.118
      |H| = 0.25 × 1.414 / 1.118 = 0.316
          = -10.0 dB
    
    half power (|H|² = 1/2): cos ω = 0.8,
      ω = 0.644 rad/sample
    
    same idea as H(s) and Bode plots in
    Circuits, "Transfer functions and Bode plots"
  11. In Python: tf2zpk and freqz

    In Python 3 with scipy, b and a are the top and bottom of H(z). signal.tf2zpk finds the zero −1 and pole 0.5, signal.freqz computes H(e^jω), and signal.lfilter runs the filter, giving h[n] again.

    from scipy import signal
    b, a = [0.25, 0.25], [1, -0.5]
    z, p, k = signal.tf2zpk(b, a)
    w, H = signal.freqz(b, a)
    h = signal.lfilter(b,a,[1,0,0,0])
    
    >>> z, p, k
    (array([-1.]), array([0.5]), np.float64(0.25))
    >>> len(w), abs(H[0]), abs(H[256]).round(3)
    (512, 1.0, 0.316)     # w[256] = π/2
    >>> h
    array([0.25   , 0.375  , 0.1875 , 0.09375])
    
    freqz: 512 points on [0, π) by default

Quiz Unlocks after the last step.