The Bilinear Transform and Pre-Warping
You have an analog filter that works: an RC low-pass at , a Butterworth prototype from Analog Prototypes, an equaliser stage from a schematic. Now it must run on a processor sampling at . You need a rule that turns into , keeps a stable filter stable, and keeps the frequency response where the specification put it. The bilinear transform does all three, provided you pre-warp the frequencies that matter. This lesson derives it, shows the warping, compares it with impulse invariance, and checks every claim on the RC example. The z-transform background is in The z-Transform and Poles and Zeros in z; the circuit version of the RC filter is in First-Order Filters.
The substitution
Integrating with the trapezoidal rule over one sample period replaces the integrator by . Substituting everywhere:
This maps the whole left half of the s-plane into the inside of the unit circle (stable stays stable), and the whole axis onto the unit circle exactly once. Put with the digital frequency: . So the analog frequency that the digital filter shows at is
The infinite analog axis is squeezed into . At low frequencies and ; near the compression is severe. This is frequency warping.
Because the analog response at infinity lands at , an analog low-pass that falls to zero at infinity gets an exact zero at : no aliasing at all, unlike sampling the impulse response. The price is the bent frequency axis.
Pre-warping
Warping is harmless if you know it. Choose one critical frequency (a cutoff, a centre frequency, a notch) that must be exact in the digital filter, compute the analog frequency that will land there,
design the analog filter at , then transform. Only one frequency per band edge can be exact; the shape between edges is warped, which is fine for piecewise-constant specifications (the passband stays flat, the stopband stays below its limit) and wrong for filters whose shape matters, such as a differentiator or an analog equaliser curve.
Worked example: the RC low-pass at 8 kSa/s
Given: with ; .
Find: by the bilinear transform with and without pre-warping, and by impulse invariance; the gains at several frequencies; where the point lands without pre-warping.
Solve: with , substituting gives . Without pre-warping, and : , . Pre-warping first: (), giving , . Impulse invariance samples : pole , scaled here to unit DC gain.
import numpy as np
from scipy import signal
fs, fc = 8000.0, 1000.0
wc = 2 * np.pi * fc
# Analog RC low-pass H(s) = wc / (s + wc), digitised three ways
bz1, az1 = signal.bilinear([wc], [1, wc], fs=fs) # bilinear, no pre-warping
wcw = 2 * fs * np.tan(np.pi * fc / fs) # pre-warped analog cutoff
bz2, az2 = signal.bilinear([wcw], [1, wcw], fs=fs) # bilinear with pre-warping
a = np.exp(-wc / fs)
bz3, az3 = [1 - a], [1, -a] # impulse invariance, scaled for unit DC gain
print(f"pre-warped analog cutoff = {wcw / (2 * np.pi):.1f} Hz")
print(f"bilinear : b = {np.round(bz1, 5)}, a = {np.round(az1, 5)}")
print(f"pre-warped : b = {np.round(bz2, 5)}, a = {np.round(az2, 5)}")
print(f"imp. invar. : b = {np.round(bz3, 5)}, a = {np.round(az3, 5)}")
fk = [100, 500, 1000, 2000, 3000, 4000]
_, Ha = signal.freqs([wc], [1, wc], worN=2 * np.pi * np.array(fk))
print("f (Hz) analog bilinear pre-warped impulse-inv. (dB)")
for i, f in enumerate(fk):
g = [20 * np.log10(abs(signal.freqz(b, a_, worN=[f], fs=fs)[1][0])) for b, a_ in ((bz1, az1), (bz2, az2), (bz3, az3))]
t = [f"{v:.2f}" if v > -150 else "zero" for v in g] # bilinear: exact zero at fs/2
print(f"{f:5d} {20 * np.log10(abs(Ha[i])):7.2f} {t[0]:>8s} {t[1]:>9s} {t[2]:>10s}")
f3 = fs / np.pi * np.arctan(np.pi * fc / fs)
print(f"without pre-warping the -3 dB point lands at {f3:.1f} Hz")pre-warped analog cutoff = 1054.8 Hz
bilinear : b = [0.28197 0.28197], a = [ 1. -0.43606]
pre-warped : b = [0.29289 0.29289], a = [ 1. -0.41421]
imp. invar. : b = [0.54406], a = [ 1. -0.45594]
f (Hz) analog bilinear pre-warped impulse-inv. (dB)
100 -0.04 -0.04 -0.04 -0.04
500 -0.97 -0.99 -0.90 -0.91
1000 -3.01 -3.25 -3.01 -2.79
2000 -6.99 -8.74 -8.34 -6.11
3000 -10.00 -15.89 -15.44 -7.97
4000 -12.30 zero zero -8.55
without pre-warping the -3 dB point lands at 952.9 Hz
Check: without pre-warping the cutoff moves down to and the gain at is instead of ; pre-warping puts the exactly at . Both bilinear filters fall faster than the analog one at high frequency and reach an exact zero at (the analog infinity). Impulse invariance keeps the shape at low frequency but aliases: the analog tail above folds back, so the gain at is , not even as low as the analog . Impulse invariance suits low-pass filters with a cutoff far below and is useless for high-pass filters; the bilinear transform is the default.
Higher orders: let SciPy pre-warp
For a cutoff near the difference is dramatic. signal.butter(N, fc, fs=fs) (and cheby1, ellip, …) pre-warps the band edges internally and returns the digital filter directly, best as second-order sections:
import numpy as np
from scipy import signal
fs, fc = 8000.0, 3000.0 # a 4th-order Butterworth low-pass with its cutoff close to fs/2
z, p, k = signal.butter(4, 2 * np.pi * fc, analog=True, output="zpk")
naive = signal.zpk2sos(*signal.bilinear_zpk(z, p, k, fs=fs)) # analog design at 3 kHz, no pre-warp
sos = signal.butter(4, fc, output="sos", fs=fs) # SciPy pre-warps for you
for name, s in (("naive bilinear", naive), ("butter(fs=...)", sos)):
_, H = signal.sosfreqz(s, worN=[1000, 2500, 3000], fs=fs)
g = np.round(20 * np.log10(np.abs(H)), 2) + 0.0
print(f"{name:15s} gain at 1 / 2.5 / 3 kHz: {g[0]:6.2f} {g[1]:6.2f} {g[2]:6.2f} dB")
fa = 2 * fs * np.tan(np.pi * fc / fs) / (2 * np.pi)
print(f"pre-warped analog cutoff: {fa:.0f} Hz for a digital cutoff of {fc:.0f} Hz")
print("second-order sections [b0 b1 b2 a0 a1 a2]:")
print(np.round(sos, 5))naive bilinear gain at 1 / 2.5 / 3 kHz: 0.00 -8.91 -24.94 dB
butter(fs=...) gain at 1 / 2.5 / 3 kHz: 0.00 -0.09 -3.01 dB
pre-warped analog cutoff: 6148 Hz for a digital cutoff of 3000 Hz
second-order sections [b0 b1 b2 a0 a1 a2]:
[[0.34682 0.69364 0.34682 1. 0.8554 0.20972]
[1. 2. 1. 1. 1.11303 0.57406]]
Designing the analog Butterworth at and transforming it naively lands the point near , so at the gain is : the filter is useless for its specification. butter designs the analog prototype at instead and the digital filter is exactly at . The two sections each have the numerator (a double zero at , the image of ); the overall gain sits in the first section.
Recipe for IIR design
- Convert the digital band edges to pre-warped analog edges (or let the design function do it with
fs=). - Choose the prototype and order (
buttord,ellipord, … withfs=also pre-warp). - Transform low-pass to the wanted type (high-pass, band-pass) in the analog domain (
lp2hp,lp2bp; again automatic inbutter(..., btype=...)). - Apply the bilinear transform and return second-order sections.
- Verify the response against the mask; then quantise (Biquads and SOS).
Guided lab: digitising an RC filter
Hand calculation. The RC low-pass (, , ) gives at and at . The pre-warped digital copy at gives and .
Simulation. Run the first program with : the three digital versions agree with the analog filter to within a few hundredths of a dB up to , because the cutoff is now far below .
What you would measure. Build the RC on a breadboard and run the digital version on a USB-powered board at ; drive both with the same amplitude sine at , and . Expect the analog filter within about of the calculation (1 % resistor, 5 % capacitor shift ) and the digital one within about (converter gain only), with the two differing by about at and at , as the table predicts.
Hazards and safe setup. Function generator and USB-powered board only, signals within the converter's input range (set the offset with the output off and check on a scope); no mains-powered circuit is opened.
Pitfalls
- Designing the analog filter at the digital cutoff and transforming without pre-warping.
- Pre-warping twice: SciPy's
butter(..., fs=fs)already does it; do not pass it a pre-warped frequency. - Using impulse invariance for a high-pass or for a cutoff near (aliasing).
- Expecting the bilinear transform to preserve the shape of a smooth analog response (equalisers, differentiators): only the chosen frequency is exact.
- Returning
b, apolynomials for high orders instead of SOS.
Practice
- At , where does an analog cutoff land after the bilinear transform without pre-warping?
- What analog frequency must you design for to get a digital notch at with ?
- Why does a bilinear-transformed low-pass have a zero at ?
Answer
- .
- ().
- is the image of , where an analog low-pass has its zeros.
Test yourself
The bilinear transform maps the analog axis onto
- the real axis
- the unit circle, once
- the unit circle, infinitely many times
- the left half-plane
Pre-warping the cutoff of a 1 kHz RC low-pass for kHz means designing the analog filter at
- 1000 Hz
- 952.9 Hz
- 1054.8 Hz
- 4000 Hz
Impulse invariance is a poor choice for a high-pass filter because
- it is unstable
- the analog response above aliases into the band
- it needs pre-warping
- it produces FIR filters
A 4th-order Butterworth at 3 kHz ( kHz) transformed without pre-warping gives at 3 kHz about
- dB
- dB
- dB
- 0 dB