01What a signal is
A signal is a quantity that changes over time: a voltage from a microphone, a temperature, a price. Digital signal processing, or DSP, is what you can do to one with arithmetic alone.
This instrument is a small synthesiser. Two generators make waves, those waves are combined, and the result goes through a filter. The four plots show the same sound in four ways: as a waveform in time, as a spectrum of frequencies, as the filter’s gain at each frequency, and as poles and zeros on the Z plane.
Turn on the Sound switch at the top of the panel to hear it. The sound is computed by the same code that draws the plots, so what you hear is exactly what you see. The dim line is the signal before the filter, and the bright line is after it.
Try this: start with a plain sine wave, then a saw wave at the same pitch. Same note, very different sound.
02Sampling
A computer cannot store a continuous wave. It stores a number every so often, and this bench takes 8000 numbers each second:
8000 samples per second is telephone quality. Real audio usually uses 44,100 or 48,000. This low rate is chosen on purpose, because it makes the effects below easy to see and hear.
The key limit is the Nyquist frequency, half the sampling rate, which here is 4000 Hz. To capture a frequency you need more than two samples per cycle.
03Aliasing
What happens above Nyquist? The samples cannot tell the difference between a high frequency and a lower one, so the high frequency shows up disguised as the lower one. It folds back around Nyquist like a sheet of paper:
So 5000 Hz, sampled at 8000 Hz, is heard at 3000 Hz. You have seen this in films, where a wheel at speed seems to turn slowly backwards. The camera is sampling the wheel too slowly.
Try this: play a 5000 Hz sine wave and read where it lands. Then drag Frequency 1 slowly upward from 3500 Hz. The pitch rises, reaches 4000 Hz, then falls, even though the slider is still going up.
This is why real systems filter before sampling. Once a signal has aliased, no later processing can separate it from a true low frequency.
04Frequency content
Any repeating wave can be built from sine waves: a fundamental at the pitch you hear, and harmonics at whole-number multiples of it. The spectrum shows how much of each is there.
A sine wave is a single line. A square wave has only odd harmonics, falling as 1/n. A saw wave has every harmonic, also falling as 1/n, which is why it sounds so bright. A triangle has odd harmonics that fall much faster, at 1/n², which is why it sounds soft. Noise has energy everywhere.
Sharp corners need high frequencies. That means these waves have harmonics above Nyquist, and those harmonics alias. Real synthesisers go to some trouble to remove them, and this one does not, so you can hear the problem.
Try this: compare a square wave with a triangle, then raise a saw to 1760 Hz and look for spectral lines that do not sit at multiples of the pitch. Those are aliases.
05What a filter does
A filter changes how much of each frequency gets through. Multiply the spectrum by the gain curve, and you have the output spectrum. That is the convolution theorem again: in time the filter is a convolution, and in frequency it is a multiplication.
The four standard shapes are named for what they let through.
- Low-pass keeps what is below the cutoff. It makes sounds darker.
- High-pass keeps what is above it. It makes sounds thinner.
- Band-pass keeps a band around the cutoff. Sweep it and you have a wah pedal.
- Band-stop removes a band. A narrow one is called a notch, and is how you remove mains hum.
The resonant biquad is the simplest filter here. Its Q sets how sharply it behaves near the cutoff: high Q makes a resonant peak, and the filter rings.
Try this: take a saw through a resonant low-pass, play it, and sweep the Cutoff slider. Then remove a tone with a notch, and watch the line at 1500 Hz vanish from the spectrum.
06Filter families
No real filter can pass everything up to a cutoff and nothing after it. Every design trades steepness against something else, and the classic families are named after who worked out each trade. Order sets how much you have to spend: each extra order adds about 20 dB per decade to the slope, at the cost of more arithmetic and more delay.
- Butterworth is as flat as possible in the passband, with no ripple. It is 3 dB down at the cutoff, whatever the order. This is the sensible default.
- Chebyshev type I allows ripple in the passband, and spends it on a steeper edge. More ripple buys more steepness.
- Chebyshev type II keeps the passband flat and puts the ripple in the stopband instead. Here the cutoff marks where the stopband begins.
- Elliptic ripples in both, and has the steepest edge possible for its order. Its zeros sit on the unit circle, and they carve deep notches just past the cutoff.
- Bessel gives up steepness for time. It has the steadiest delay across its passband, so a wave keeps its shape and a sharp edge does not ring.
- Linkwitz-Riley is built for loudspeaker crossovers. It is two Butterworth filters in series, so it is 6 dB down at the cutoff, and its low-pass and high-pass outputs add back to a flat response. That means no bump where the woofer hands over to the tweeter. Its order is always even, so odd settings round up.
Try this: put noise through each at the same order, and watch the edge of the spectrum. Start with Butterworth, then Chebyshev I, elliptic and Bessel. Watch the poles too: Butterworth poles sit on a circle, Chebyshev poles on an ellipse. Then see how a square wave through Bessel keeps its shape, where elliptic rings at every edge.
07How a filter works
A digital filter is only a short recipe of multiplying and adding. Each output sample is a weighted sum of recent inputs and recent outputs:
There are two families. A finite impulse response (FIR) filter uses only past inputs, so a single click fades out after a fixed number of samples. An infinite impulse response (IIR) filter also feeds back past outputs, so it can ring on for much longer. The filters here are IIR, which get a sharp response from very little arithmetic. FIR filters need more computing power, but they are always stable and can leave the shape of a wave intact.
08The Z plane
The Z transform turns that recipe into a ratio of polynomials, where means “one sample ago”:
The roots of the numerator are the zeros, and the roots of the denominator are the poles.
The unit circle holds every frequency the system can represent. Zero hertz is at the right, Nyquist at the left, and the top half of the circle runs between them. A sine wave at frequency sits at an angle:
To read the gain at any frequency, stand at that point on the circle. The gain is the product of your distances to the zeros, divided by the product of your distances to the poles. So a pole near the circle pushes the gain up at that frequency, and a zero on the circle pulls it to nothing.
Stability is simple: every pole must lie inside the unit circle, or the filter’s feedback grows without limit. Here the sliders stop just short of it, which also protects your speakers.
09Build your own filter
Choose “Your poles and zeros” and drag the markers. Poles are × and zeros are ○. They come in mirror-image pairs, so that the filter’s coefficients stay real numbers. Each pair has a radius, for how close it sits to the circle, and an angle, for the frequency it acts on. Setting a radius to 0 turns that pair off.
Try this: noise through a single pole pair makes a whistle at 1000 Hz. Drag the pole towards the circle, and the whistle gets narrower and purer.
Then try a zero on the circle to cut a hole in the noise at 1000 Hz. Two poles side by side make two formants, which is how the vocal tract shapes vowels.
10Combining signals
Adding two signals keeps their frequencies as they are. Multiplying them does something different: it makes new ones, at the sum and the difference of the originals.
This is called ring modulation, and it is how radios shift a signal up to a broadcast frequency and back down again.
Try this: 440 Hz times 90 Hz. The spectrum shows lines at 350 Hz and 530 Hz, and neither original tone is there.
11What this leaves out
The rate is fixed at 8000 samples per second. The generators are not band limited, by design. Whole-number frequencies are used so that the sound loops cleanly, and noise loops once a second, which a sharp ear may catch.
The spectrum uses a Hann window over 2048 samples, so a pure tone shows as a narrow peak rather than a single line. Volume is capped, and the sound stops when you leave the tab. The filters are digital versions of analog designs, made with the bilinear transform, so very close to Nyquist their shapes are squeezed. When you play at this low rate, your browser resamples the sound for your speakers, which can slightly colour the very top of the range.
The test suite checks each family against what defines it: Butterworth at 3 dB and its roll-off, ripple and stopband depth for Chebyshev and elliptic, steady delay for Bessel, and the flat sum of Linkwitz-Riley, with every family stable across the controls. It also checks the spectrum against the known harmonics of a square wave, and that a filter’s measured gain on a sine wave matches the computed curve.
12References
- A. V. Oppenheim and R. W. Schafer, Discrete-Time Signal Processing
- S. W. Smith, The Scientist and Engineer's Guide to Digital Signal Processing
- R. Bristow-Johnson, Audio EQ Cookbook, for the resonant biquad
- S. J. Orfanidis, Lecture Notes on Elliptic Filter Design, for the elliptic poles and zeros