TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › The z-Transform and Discrete Transfer Functions

The z-Transform and Discrete Transfer Functions

A vendor library hands you a filter as two coefficient arrays, b = [1, 1] and a = [1, -0.5], and nothing else. What is its gain at DC and at half the sampling rate? What is its impulse response in closed form? If you put two such filters in series, what are the coefficients of the combination? The z-transform answers all of these with polynomial algebra, the way the Laplace transform did for continuous systems. This lesson is the practical toolkit: transfer functions from difference equations, the frequency response on the unit circle, inverse transforms with scipy.signal.residuez, and cascades by polynomial multiplication. The derivations and more pairs are in The z-Transform.

Definition and the delay operator

X(z)=∑n=−∞∞x[n] z−nX(z) = \sum_{n=-\infty}^{\infty} x[n]\,z^{-n}

The one property that does most of the work: a delay of one sample multiplies the transform by z−1z^{-1}, so x[n−k]↔z−kX(z)x[n - k] \leftrightarrow z^{-k}X(z). Applying it term by term to the difference equation ∑kaky[n−k]=∑kbkx[n−k]\sum_k a_k y[n-k] = \sum_k b_k x[n-k] gives

H(z)=Y(z)X(z)=b0+b1z−1+⋯+bMz−M1+a1z−1+⋯+aNz−NH(z) = \frac{Y(z)}{X(z)} = \frac{b_0 + b_1 z^{-1} + \cdots + b_M z^{-M}}{1 + a_1 z^{-1} + \cdots + a_N z^{-N}}

The coefficient arrays of lfilter(b, a, x) are the transfer function, in ascending powers of z−1z^{-1}. Convolution becomes multiplication, Y(z)=H(z)X(z)Y(z) = H(z)X(z), and H(z)H(z) is the z-transform of the impulse response.

x[n] z^-1 + y[n] z^-1 0.5 x[n-1] y[n-1] H(z) = (1 + z^-1) / (1 - 0.5 z^-1)

Pairs you will use (all for causal sequences, valid for ∣z∣\lvert z \rvert larger than the largest pole magnitude, the region of convergence):

x[n]x[n] X(z)X(z) ROC
δ[n]\delta[n] 11 all zz
δ[n−k]\delta[n - k] z−kz^{-k} z≠0z \ne 0
u[n]u[n] 11−z−1\dfrac{1}{1 - z^{-1}} ∣z∣>1\lvert z \rvert > 1
anu[n]a^n u[n] 11−az−1\dfrac{1}{1 - a z^{-1}} ∣z∣>∣a∣\lvert z \rvert > \lvert a \rvert
rncos⁡(Ω0n) u[n]r^n\cos(\Omega_0 n)\,u[n] 1−rcos⁡Ω0 z−11−2rcos⁡Ω0 z−1+r2z−2\dfrac{1 - r\cos\Omega_0\,z^{-1}}{1 - 2r\cos\Omega_0\,z^{-1} + r^2 z^{-2}} ∣z∣>r\lvert z \rvert > r

Frequency response. Setting z=ejΩz = e^{j\Omega} (the unit circle) gives H(ejΩ)H(e^{j\Omega}), the frequency response. Two points are worth evaluating by hand for any filter: z=1z = 1 (DC, Ω=0\Omega = 0) gives the DC gain ∑bk/∑ak\sum b_k / \sum a_k, and z=−1z = -1 (Ω=π\Omega = \pi, i.e. fs/2f_s/2) gives the Nyquist gain ∑(−1)kbk/∑(−1)kak\sum (-1)^k b_k / \sum (-1)^k a_k.

Link to the s-plane. Sampling epte^{pt} gives (epT)n(e^{pT})^n, so a continuous pole pp corresponds to a discrete pole z=epTz = e^{pT}: the left half-plane maps inside the unit circle, the jωj\omega axis onto it, with Ω=ωT\Omega = \omega T. The next lesson, Poles, Zeros and Stability in z, uses this map to read filters geometrically.

Worked example: the vendor filter

Given: b = [1, 1], a = [1, -0.5], fs=1 kSa/sf_s = 1\ \text{kSa/s}, i.e. y[n]=0.5 y[n−1]+x[n]+x[n−1]y[n] = 0.5\,y[n-1] + x[n] + x[n-1].

Find: H(z)H(z), the DC and Nyquist gains, the pole and zero, the impulse response in closed form.

Solve:

  • H(z)=1+z−11−0.5z−1=z+1z−0.5H(z) = \dfrac{1 + z^{-1}}{1 - 0.5z^{-1}} = \dfrac{z + 1}{z - 0.5}: zero at z=−1z = -1, pole at z=0.5z = 0.5 (inside the unit circle, stable).
  • DC: H(1)=2/0.5=4H(1) = 2/0.5 = 4 (12.04 dB12.04\ \text{dB}). Nyquist (500 Hz500\ \text{Hz}): H(−1)=0/1.5=0H(-1) = 0/1.5 = 0. A low-pass with a gain of 4.
  • Partial fractions in z−1z^{-1}: H(z)=−2+31−0.5z−1H(z) = -2 + \dfrac{3}{1 - 0.5z^{-1}}, so h[n]=−2 δ[n]+3 (0.5)nu[n]=1,1.5,0.75,0.375,…h[n] = -2\,\delta[n] + 3\,(0.5)^n u[n] = 1, 1.5, 0.75, 0.375, \ldots

Check: run the recursion with an impulse: h[0]=1h[0] = 1, h[1]=0.5×1+1=1.5h[1] = 0.5 \times 1 + 1 = 1.5, h[2]=0.5×1.5=0.75h[2] = 0.5 \times 1.5 = 0.75. And ∑h=−2+3/(1−0.5)=4\sum h = -2 + 3/(1 - 0.5) = 4, the DC gain.

python · try it yourself
import numpy as np
from scipy.signal import lfilter, residuez, freqz, tf2zpk

b, a = [1.0, 1.0], [1.0, -0.5]
z, p, k = tf2zpk(b, a)
print("zeros:", z, " poles:", p, " gain:", k)

r, pr, direct = residuez(b, a)                       # H = sum r/(1 - p z^-1) + direct terms
print(f"partial fractions: {float(r[0].real):.1f} / (1 - {float(pr[0].real):.1f} z^-1)  + direct {direct}")

n = np.arange(6)
h_formula = 3 * 0.5**n + np.where(n == 0, -2.0, 0.0)
h_filter = lfilter(b, a, (n == 0).astype(float))
print("h[n] formula:", h_formula)
print("h[n] lfilter:", h_filter)

def H_at(zv):                                        # evaluate H(z) = B(z^-1)/A(z^-1) at any z
    zi = 1 / zv
    return np.polyval(b[::-1], zi) / np.polyval(a[::-1], zi)
print(f"H(1) = {H_at(1.0).real:.3f}, H(-1) = {abs(H_at(-1.0)):.3f}, |H(j)| = {abs(H_at(1j)):.4f} (f = fs/4)")
_, Hf = freqz(b, a, worN=[0.0, 100.0, 250.0], fs=1000.0)
print("freqz |H| at 0, 100, 250 Hz:", np.round(np.abs(Hf), 4))
zeros: [-1.]  poles: [0.5]  gain: 1.0
partial fractions: 3.0 / (1 - 0.5 z^-1)  + direct [-2.]
h[n] formula: [1.      1.5     0.75    0.375   0.1875  0.09375]
h[n] lfilter: [1.      1.5     0.75    0.375   0.1875  0.09375]
H(1) = 4.000, H(-1) = 0.000, |H(j)| = 1.2649 (f = fs/4)
freqz |H| at 0, 100, 250 Hz: [4.     2.8643 1.2649]

freqz evaluates exactly the same function on the unit circle; z=jz = j is fs/4=250 Hzf_s/4 = 250\ \text{Hz}.

Cascades and the step response

In series, transfer functions multiply, and multiplying polynomials in z−1z^{-1} is convolving their coefficient arrays. The step response follows from Y(z)=H(z)/(1−z−1)Y(z) = H(z)/(1 - z^{-1}), and its final value from the final value theorem lim⁡n→∞y[n]=lim⁡z→1(1−z−1)Y(z)=H(1)\lim_{n \to \infty} y[n] = \lim_{z \to 1}(1 - z^{-1})Y(z) = H(1) for a stable HH:

python · try it yourself
import numpy as np
from scipy.signal import lfilter

b1, a1 = np.array([1.0, 1.0]), np.array([1.0, -0.5])     # the vendor filter
b2, a2 = np.array([0.2, 0.2]), np.array([1.0, -0.6])     # a second low-pass, DC gain 1
b, a = np.convolve(b1, b2), np.convolve(a1, a2)         # H = H1 * H2
print("cascade b =", b, " a =", a)

rng = np.random.default_rng(0)
x = rng.standard_normal(200)
y_two = lfilter(b2, a2, lfilter(b1, a1, x))
y_one = lfilter(b, a, x)
print(f"max difference, two stages vs one: {np.max(np.abs(y_two - y_one)):.1e}")

step = lfilter(b, a, np.ones(40))
print(f"step response: y[39] = {step[-1]:.4f}, H(1) = sum(b)/sum(a) = {b.sum() / a.sum():.4f}")
cascade b = [0.2 0.4 0.2]  a = [ 1.  -1.1  0.3]
max difference, two stages vs one: 2.4e-15
step response: y[39] = 4.0000, H(1) = sum(b)/sum(a) = 4.0000

Multiplying polynomials is exact in mathematics but not always in fixed-point hardware: high-order filters built as one big polynomial are numerically fragile, which is why biquads keep the factors separate.

Guided lab: check a library filter on a board

Hand calculation. For the vendor filter at fs=1 kSa/sf_s = 1\ \text{kSa/s}: gain 4 at DC, 3.983.98 at 10 Hz10\ \text{Hz}, 2.862.86 at 100 Hz100\ \text{Hz}, 1.261.26 at 250 Hz250\ \text{Hz}, 0 at 500 Hz500\ \text{Hz}.

Simulation. Add 400.0 to the freqz list: 0.430.43 (−7.3 dB-7.3\ \text{dB}).

What you would measure. Run the filter on a board's ADC samples and stream input and output codes. Because the DC gain is 4, scale the input down first or the output overflows: with a 00 to 3 V3\ \text{V} input centred at 1.5 V1.5\ \text{V}, subtract the mid-scale code before filtering and keep the amplitude below a quarter of the range. Expect output/input amplitude ratios within about 1 %1\,\% of the hand values (limited by ADC noise and the generator's amplitude flatness), and a residual at 500 Hz500\ \text{Hz} that depends on the phase of the samples relative to the sine.

Hazards and safe setup. USB-powered board, generator output checked on a scope (within 00 to 3 V3\ \text{V}) before connecting, 1 kΩ1\ \text{k}\Omega series resistor.

Pitfalls

  • Reading coefficients from H(z)H(z) written in positive powers of zz: zz2−0.5\frac{z}{z^2 - 0.5} is z−11−0.5z−2\frac{z^{-1}}{1 - 0.5z^{-2}}, so b = [0, 1], a = [1, 0, -0.5], not b = [1, 0]. Divide numerator and denominator by the highest power of zz first.
  • Forgetting the sign convention: a feedback term +0.5 y[n−1]+0.5\,y[n-1] is a = [1, -0.5].
  • Applying the final value theorem to an unstable filter.
  • Ignoring the gain of a filter (here 4) and overflowing a fixed-point output.

Practice

  1. Find H(z)H(z) for y[n]=x[n]−x[n−2]y[n] = x[n] - x[n-2]. What are its DC and Nyquist gains?
  2. Find h[n]h[n] for H(z)=11−0.8z−1H(z) = \frac{1}{1 - 0.8z^{-1}} and its DC gain.
  3. A filter has b = [0.5, 0.5]. Cascaded with itself, what are the coefficients?
Answer
  1. H(z)=1−z−2H(z) = 1 - z^{-2}; H(1)=0H(1) = 0 and H(−1)=0H(-1) = 0: a band-pass with zeros at DC and fs/2f_s/2.
  2. h[n]=0.8nu[n]h[n] = 0.8^n u[n]; DC gain 1/0.2=51/0.2 = 5.
  3. [0.25,0.5,0.25][0.25, 0.5, 0.25].

Test yourself

In the z-domain a one-sample delay corresponds to

  1. multiplying by zz
  2. multiplying by z−1z^{-1}
  3. adding z−1z^{-1}
  4. differentiating

The DC gain of a filter with coefficient arrays b and a is

  1. b[0]/a[0]
  2. sum(b)/sum(a)
  3. max(b)
  4. always 1

The frequency fs/2f_s/2 corresponds to which point of the z-plane?

  1. z=1z = 1
  2. z=jz = j
  3. z=−1z = -1
  4. z=0z = 0

Two filters in series have the combined numerator

  1. b1 + b2
  2. np.convolve(b1, b2)
  3. b1 * b2 element by element
  4. np.concatenate([b1, b2])