The z-Transform
The DTFT evaluates on the unit circle. The z-transform replaces by an arbitrary complex number , turning sequences into functions on the complex plane, often simple rational functions. It turns difference equations into algebra, makes stability a question about where the poles are, and is the discrete twin of the Laplace transform.
Definition
The sum converges for in a region of convergence (ROC), an annulus. On the unit circle, , the z-transform is the DTFT (when the circle lies in the ROC).
Two fundamental pairs:
The second is a geometric series: .
import numpy as np
a = 0.6
n = np.arange(200)
x = a ** n
for z in (2.0, 1.0, np.exp(0.7j), 0.7 + 0.2j):
series = np.sum(x * z ** (-n.astype(float)))
closed = 1 / (1 - a / z)
print(f"z = {complex(z):.3f}: |z| = {abs(z):.3f} series {complex(series):.5f} closed form {complex(closed):.5f}")z = 2.000+0.000j: |z| = 2.000 series 1.42857+0.00000j closed form 1.42857+0.00000j
z = 1.000+0.000j: |z| = 1.000 series 2.50000+0.00000j closed form 2.50000+0.00000j
z = 0.765+0.644j: |z| = 1.000 series 1.22367-0.87413j closed form 1.22367-0.87413j
z = 0.700+0.200j: |z| = 0.728 series 2.20000-2.40000j closed form 2.20000-2.40000j
For every the truncated series matches the closed form.
Delay becomes multiplication
The key property: delaying by one sample multiplies by , so . The convolution becomes , and a filter with difference equation
has transfer function
These are exactly the b and a arrays that scipy.signal.lfilter(b, a, x) takes.
import numpy as np
b = [0.2, 0.2] # y[n] = 0.2 x[n] + 0.2 x[n-1] + 0.6 y[n-1]
a = [1.0, -0.6]
def H(z):
return (b[0] + b[1] / z) / (a[0] + a[1] / z)
# impulse response by running the difference equation
h, y_prev, x_prev = [], 0.0, 0.0
for n in range(8):
x = 1.0 if n == 0 else 0.0
y = 0.2 * x + 0.2 * x_prev + 0.6 * y_prev
h.append(round(y, 5)); y_prev, x_prev = y, x
print("impulse response:", h)
w = 0.4 # compare H on the unit circle with the DTFT of h
long_h = [0.2] + [0.32 * 0.6 ** (n - 1) for n in range(1, 400)]
dtft = sum(hn * np.exp(-1j * w * n) for n, hn in enumerate(long_h))
print(f"H(e^(0.4i)) = {complex(H(np.exp(1j * w))):.5f} DTFT of h = {complex(dtft):.5f}")impulse response: [0.2, 0.32, 0.192, 0.1152, 0.06912, 0.04147, 0.02488, 0.01493]
H(e^(0.4i)) = 0.60333-0.48921j DTFT of h = 0.60333-0.48921j
The impulse response is , and the transfer function evaluated on the unit circle equals its DTFT.
Inverse z-transform by partial fractions
To find from a rational , split it into simple fractions , each of which inverts to . So the impulse response is a sum of geometric sequences, one per pole . That is the bridge to stability in the next lesson.
In software
scipy.signal.tf2zpk,residuez(partial fractions),freqz(evaluate on the unit circle),dltiobjects.- SymPy can compute z-transforms of symbolic sequences via summation.
Exercises
Exercise 1: A finite sequence
What is the z-transform of (starting at )?
Answer
.
Solution
Each sample contributes . Finite sequences give polynomials in , converging everywhere except .
Exercise 2: Transfer function
Write for .
Answer
.
Solution
Transform term by term: , so .
Exercise 3: Partial fractions (code)
Verify that by comparing impulse responses for .
Answer
Both give .
Solution
import numpy as np
n = np.arange(6)
from_fractions = 2 * 0.5 ** n - 0.25 ** n
y = []
for k in range(6): # y[n] = x[n] + 0.75 y[n-1] - 0.125 y[n-2]
x = 1.0 if k == 0 else 0.0
y.append(x + 0.75 * (y[k - 1] if k >= 1 else 0) - 0.125 * (y[k - 2] if k >= 2 else 0))
print(np.round(from_fractions, 4).tolist())
print(np.round(y, 4).tolist())[1.0, 0.75, 0.4375, 0.2344, 0.1211, 0.0615]
[1.0, 0.75, 0.4375, 0.2344, 0.1211, 0.0615]
The denominator gives the difference equation used in the loop.
Test yourself
Delaying a sequence by samples multiplies its z-transform by…
The z-transform of is…
Evaluating on the unit circle gives…
- the impulse response
- the frequency response
- the poles
- the step response