TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › The Bilinear Transform and Pre-Warping

The Bilinear Transform and Pre-Warping

You have an analog filter that works: an RC low-pass at 1 kHz1\ \text{kHz}, a Butterworth prototype from Analog Prototypes, an equaliser stage from a schematic. Now it must run on a processor sampling at 8 kSa/s8\ \text{kSa/s}. You need a rule that turns H(s)H(s) into H(z)H(z), 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 T=1/fsT = 1/f_s replaces the integrator 1/s1/s by T21+z−11−z−1\frac{T}{2}\frac{1 + z^{-1}}{1 - z^{-1}}. Substituting everywhere:

s=2T 1−z−11+z−1=2fs z−1z+1s = \frac{2}{T}\,\frac{1 - z^{-1}}{1 + z^{-1}} = 2 f_s\,\frac{z - 1}{z + 1}

This maps the whole left half of the s-plane into the inside of the unit circle (stable stays stable), and the whole jΩj\Omega axis onto the unit circle exactly once. Put z=ejωz = e^{j\omega} with ω=2πfd/fs\omega = 2\pi f_d/f_s the digital frequency: s=j 2fstan⁡(ω/2)s = j\,2f_s\tan(\omega/2). So the analog frequency faf_a that the digital filter shows at fdf_d is

fa=fsπtan⁡ ⁣(πfdfs),fd=fsπarctan⁡ ⁣(πfafs)f_a = \frac{f_s}{\pi}\tan\!\left(\frac{\pi f_d}{f_s}\right), \qquad f_d = \frac{f_s}{\pi}\arctan\!\left(\frac{\pi f_a}{f_s}\right)

The infinite analog axis is squeezed into 0…fs/20 \ldots f_s/2. At low frequencies tan⁡x≈x\tan x \approx x and fd≈faf_d \approx f_a; near fs/2f_s/2 the compression is severe. This is frequency warping.

0 2 4 6 8 10 12 kHz 1 2 3 4 kHz digital frequency fd analog frequency fa 3 kHz -> 2.23 kHz pre-warp: 6.15 kHz -> 3 kHz fs/2 fd = fa

Because the analog response at infinity lands at fs/2f_s/2, an analog low-pass that falls to zero at infinity gets an exact zero at z=−1z = -1: 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,

Ωpre=2fstan⁡ ⁣(πfcfs)\Omega_\text{pre} = 2 f_s \tan\!\left(\frac{\pi f_c}{f_s}\right)

design the analog filter at Ωpre\Omega_\text{pre}, 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: H(s)=ωc/(s+ωc)H(s) = \omega_c/(s + \omega_c) with fc=1 kHzf_c = 1\ \text{kHz}; fs=8 kHzf_s = 8\ \text{kHz}.

Find: H(z)H(z) by the bilinear transform with and without pre-warping, and by impulse invariance; the gains at several frequencies; where the −3 dB-3\ \text{dB} point lands without pre-warping.

Solve: with K=2fsK = 2f_s, substituting gives H(z)=ωc(1+z−1)(K+ωc)+(ωc−K)z−1H(z) = \frac{\omega_c (1 + z^{-1})}{(K + \omega_c) + (\omega_c - K) z^{-1}}. Without pre-warping, ωc=6283 rad/s\omega_c = 6283\ \text{rad/s} and K=16 000 s−1K = 16\,000\ \text{s}^{-1}: b0=b1=6283/22 283=0.28197b_0 = b_1 = 6283/22\,283 = 0.28197, a1=(6283−16 000)/22 283=−0.43606a_1 = (6283 - 16\,000)/22\,283 = -0.43606. Pre-warping first: Ωpre=16 000tan⁡(π/8)=6627 rad/s\Omega_\text{pre} = 16\,000 \tan(\pi/8) = 6627\ \text{rad/s} (1054.8 Hz1054.8\ \text{Hz}), giving b0=b1=0.29289b_0 = b_1 = 0.29289, a1=−0.41421a_1 = -0.41421. Impulse invariance samples h(t)=ωce−ωcth(t) = \omega_c e^{-\omega_c t}: pole a=e−ωcT=0.45594a = e^{-\omega_c T} = 0.45594, scaled here to unit DC gain.

python · try it yourself
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 fd=(8000/π)arctan⁡(π/8)=952.9 Hzf_d = (8000/\pi)\arctan(\pi/8) = 952.9\ \text{Hz} and the gain at 1 kHz1\ \text{kHz} is −3.25 dB-3.25\ \text{dB} instead of −3.01-3.01; pre-warping puts the −3.01 dB-3.01\ \text{dB} exactly at 1 kHz1\ \text{kHz}. Both bilinear filters fall faster than the analog one at high frequency and reach an exact zero at 4 kHz4\ \text{kHz} (the analog infinity). Impulse invariance keeps the shape at low frequency but aliases: the analog tail above fs/2f_s/2 folds back, so the gain at 4 kHz4\ \text{kHz} is −8.55 dB-8.55\ \text{dB}, not even as low as the analog −12.30 dB-12.30\ \text{dB}. Impulse invariance suits low-pass filters with a cutoff far below fs/2f_s/2 and is useless for high-pass filters; the bilinear transform is the default.

Higher orders: let SciPy pre-warp

For a cutoff near fs/2f_s/2 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:

python · try it yourself
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 3 kHz3\ \text{kHz} and transforming it naively lands the −3 dB-3\ \text{dB} point near (8000/π)arctan⁡(3π/8)=2.23 kHz(8000/\pi)\arctan(3\pi/8) = 2.23\ \text{kHz}, so at 3 kHz3\ \text{kHz} the gain is −24.9 dB-24.9\ \text{dB}: the filter is useless for its specification. butter designs the analog prototype at 6148 Hz6148\ \text{Hz} instead and the digital filter is exactly −3.01 dB-3.01\ \text{dB} at 3 kHz3\ \text{kHz}. The two sections each have the numerator 1+2z−1+z−21 + 2z^{-1} + z^{-2} (a double zero at z=−1z = -1, the image of s=∞s = \infty); the overall gain sits in the first section.

Recipe for IIR design

  1. Convert the digital band edges to pre-warped analog edges (or let the design function do it with fs=).
  2. Choose the prototype and order (buttord, ellipord, … with fs= also pre-warp).
  3. Transform low-pass to the wanted type (high-pass, band-pass) in the analog domain (lp2hp, lp2bp; again automatic in butter(..., btype=...)).
  4. Apply the bilinear transform and return second-order sections.
  5. Verify the response against the mask; then quantise (Biquads and SOS).

Guided lab: digitising an RC filter

Hand calculation. The RC low-pass (R=1.59 kΩR = 1.59\ \text{k}\Omega, C=100 nFC = 100\ \text{nF}, fc=1.00 kHzf_c = 1.00\ \text{kHz}) gives −3.01 dB-3.01\ \text{dB} at 1 kHz1\ \text{kHz} and −6.99 dB-6.99\ \text{dB} at 2 kHz2\ \text{kHz}. The pre-warped digital copy at 8 kSa/s8\ \text{kSa/s} gives −3.01-3.01 and −8.34 dB-8.34\ \text{dB}.

Simulation. Run the first program with fs=48 kHzf_s = 48\ \text{kHz}: the three digital versions agree with the analog filter to within a few hundredths of a dB up to 2 kHz2\ \text{kHz}, because the cutoff is now far below fs/2f_s/2.

What you would measure. Build the RC on a breadboard and run the digital version on a USB-powered board at 8 kSa/s8\ \text{kSa/s}; drive both with the same 1 V1\ \text{V} amplitude sine at 11, 22 and 3 kHz3\ \text{kHz}. Expect the analog filter within about ±0.3 dB\pm 0.3\ \text{dB} of the calculation (1 % resistor, 5 % capacitor shift fcf_c) and the digital one within about ±0.1 dB\pm 0.1\ \text{dB} (converter gain only), with the two differing by about 1.4 dB1.4\ \text{dB} at 2 kHz2\ \text{kHz} and 5.4 dB5.4\ \text{dB} at 3 kHz3\ \text{kHz}, 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 fs/2f_s/2 (aliasing).
  • Expecting the bilinear transform to preserve the shape of a smooth analog response (equalisers, differentiators): only the chosen frequency is exact.
  • Returning b, a polynomials for high orders instead of SOS.

Practice

  1. At fs=48 kHzf_s = 48\ \text{kHz}, where does an analog 20 kHz20\ \text{kHz} cutoff land after the bilinear transform without pre-warping?
  2. What analog frequency must you design for to get a digital notch at 50 Hz50\ \text{Hz} with fs=200 Hzf_s = 200\ \text{Hz}?
  3. Why does a bilinear-transformed low-pass have a zero at z=−1z = -1?
Answer
  1. fd=(48 000/π)arctan⁡(20 000π/48 000)=15 279×0.9184=14.03 kHzf_d = (48\,000/\pi)\arctan(20\,000\pi/48\,000) = 15\,279 \times 0.9184 = 14.03\ \text{kHz}.
  2. fa=(200/π)tan⁡(π⋅50/200)=63.66×1=63.7 Hzf_a = (200/\pi)\tan(\pi \cdot 50/200) = 63.66 \times 1 = 63.7\ \text{Hz} (Ω=400 rad/s\Omega = 400\ \text{rad/s}).
  3. z=−1z = -1 is the image of s=∞s = \infty, where an analog low-pass has its zeros.

Test yourself

The bilinear transform maps the analog jΩj\Omega axis onto

  1. the real axis
  2. the unit circle, once
  3. the unit circle, infinitely many times
  4. the left half-plane

Pre-warping the cutoff of a 1 kHz RC low-pass for fs=8f_s = 8 kHz means designing the analog filter at

  1. 1000 Hz
  2. 952.9 Hz
  3. 1054.8 Hz
  4. 4000 Hz

Impulse invariance is a poor choice for a high-pass filter because

  1. it is unstable
  2. the analog response above fs/2f_s/2 aliases into the band
  3. it needs pre-warping
  4. it produces FIR filters

A 4th-order Butterworth at 3 kHz (fs=8f_s = 8 kHz) transformed without pre-warping gives at 3 kHz about

  1. −3-3 dB
  2. −9-9 dB
  3. −25-25 dB
  4. 0 dB