$ cat posts/filters-you-can-hear.md
Filters you can hear
In signals courses, filters live on paper: transfer functions, pole–zero plots, Bode plots. I wanted to hear what a pole does. So I built Filter Lab: design a filter, see its poles, zeros and frequency response, and listen to it live on music, test signals or your microphone. Press Space to switch between the original and filtered sound.
From analog prototype to digital filter
The classic IIR families (Butterworth, Chebyshev I and II, Elliptic and Bessel) are all designed in the analog domain first. The bilinear transform then maps them to digital filters:
It maps the whole left half of the $s$-plane into the unit circle, so a stable analog filter always becomes a stable digital one. The catch is that it squeezes the frequency axis:
So the cutoff frequency has to be pre-warped before the analog design, or it lands in the wrong place. Filter Lab follows the same steps as SciPy’s iirfilter: analog prototype, band transform, then the bilinear transform with pre-warping.
Checking against SciPy
To be sure the maths was right, I compared Filter Lab with SciPy on 780 random designs. The poles and zeros agree to about $10^{-12}$, and the magnitude responses to $10^{-9}$ dB. The reference side is only a couple of lines:
from scipy import signal
sos = signal.butter(4, 1000, btype="low", fs=48000, output="sos")
w, h = signal.sosfreqz(sos, fs=48000)
Things to try
- Push a pole outside the unit circle and watch the impulse response blow up. That’s instability, and you can hear it.
- Load the 50 Hz hum remover preset on music with mains hum added. (Sri Lanka’s mains frequency is 50 Hz.) The notch is surprisingly narrow.
- Compare a Butterworth and an Elliptic filter of the same order. The elliptic one is much steeper, but listen to the ripple in its passband.
Filter Lab can also export the design as MATLAB, Python or C code, and save any plot as a PNG for a lab report. The code is on GitHub: rivija21/interactive-DSP.