· 11 min read
Filters in code: the biquad, five numbers behind every EQ
The tone knob on a distortion pedal, TIGHT before the clipping, the Tube Screamer’s “mid hump”, bass and treble on an amp, a parametric EQ and a wah. They are all filters, and in a digital pedal almost every one of them is the same small algorithm: the biquad. One line of code, two samples of memory and five numbers. Change those five numbers and you get any of these filters.
A filter is a sound mixed with its own past
In chorus and flanger we saw that a sound mixed with a delayed copy of itself boosts some frequencies and cancels others. The biquad does the same, only with the shortest delay possible, one and two samples:
y = b0·x + b1·x1 + b2·x2 − a1·y1 − a2·y2
x1 and x2 are the last two inputs, and y1 and y2 the last two outputs. The part with the b numbers mixes the input with its past, like a chorus. The part with the a numbers feeds the output back, like the feedback in a delay. That feedback is where resonance comes from: a frequency that comes back in phase boosts itself.
You have already met smaller filters of the same family. The smoothing in the tremolo and TIGHT in the overdrive are first-order filters, with one sample of memory each. The biquad is a second-order filter. The name comes from “bi-quadratic”: there is a second-degree polynomial both on the top and on the bottom of its formula.
Six filters, the same code
| Type | What it does | Where you meet it |
|---|---|---|
| Lowpass | passes lows, cuts highs | tone on a distortion, speaker simulation (a cabinet plays nothing above ~5 kHz) |
| Highpass | passes highs, cuts lows | TIGHT before clipping, removing boomy bass |
| Bandpass | passes only a narrow band around FREQ | wah, auto-wah, the “through a telephone” sound |
| Peak | boosts or cuts a band around FREQ | the mid hump, a metal “scoop”, parametric EQ |
| Low shelf | boosts or cuts everything below FREQ | the BASS knob on an amp |
| High shelf | boosts or cuts everything above FREQ | TREBLE and PRESENCE |
The analog versions of these circuits, with capacitors and resistors, and how they sound on real pedals, are in tone controls. Here we look at what the same thing looks like as numbers.
FREQ, Q and GAIN
FREQ says where the filter works. GAIN says how much it boosts or cuts, but only for peak and shelf. Lowpass, highpass and bandpass only pass or cut.
Q says how sharp the filter is. For peak and bandpass filters a higher Q means a narrower band. For lowpass and highpass Q decides what happens right at FREQ. With Q = 0.707 the curve is as flat as it can be before it falls (that is a Butterworth filter), and at FREQ it is exactly 3 dB down. With a higher Q a peak grows at FREQ, and higher still the filter starts to “sing” at that frequency. That is resonance, and it is the whole trick behind a wah.
What to try in the simulator
- Five numbers. Turn FREQ and watch the “right now:” line in the code. Every time you move a knob, only those five numbers change. The code below them stays the same.
- Noise. Play “Noise” and switch filter types. Noise has every frequency in it, so you hear most clearly what the filter lets through.
- Mid hump and scoop. “Mid hump” boosts the mids around 720 Hz, like a Tube Screamer: the guitar “steps forward”. “Scoop” is the opposite, so the guitar sounds big alone but gets lost in a band.
- Resonance. “Resonance (Q 15)” on noise: the filter sings a single tone. Bottom left, see how the poles sit almost on the circle.
- Wah. “Wah (turn FREQ)” is a bandpass with Q 5. Drag FREQ up and down, and that is a wah pedal. “Auto-wah” does it by itself, with an LFO.
Where the five numbers come from
Almost every digital EQ uses the same formulas, from a short text by Robert Bristow-Johnson, the “Audio EQ Cookbook”. First three helper numbers are worked out:
w0 = 2π · FREQ / sampleRate α = sin(w0) / (2·Q) A = 10^(GAIN / 40)
Then each type has its own recipe for six numbers, and at the end they are all divided by a0, which leaves five:
| Type | b0 | b1 | b2 | a0 | a1 | a2 |
|---|---|---|---|---|---|---|
| Lowpass | (1 − cos w0) / 2 | 1 − cos w0 | (1 − cos w0) / 2 | 1 + α | −2 cos w0 | 1 − α |
| Highpass | (1 + cos w0) / 2 | −(1 + cos w0) | (1 + cos w0) / 2 | 1 + α | −2 cos w0 | 1 − α |
| Bandpass | α | 0 | −α | 1 + α | −2 cos w0 | 1 − α |
| Peak | 1 + α·A | −2 cos w0 | 1 − α·A | 1 + α/A | −2 cos w0 | 1 − α/A |
The shelf formulas are a bit longer but follow the same idea (they are complete in the simulator’s source). Notice that the a numbers are the same for the first three types: all three have the same resonance and differ only in what part of it they let through.
The formulas are made so that the digital filter behaves exactly like the analog one with the same FREQ and Q at FREQ. Far from FREQ, near half the sampleRate, they differ a little, because a digital filter cannot follow frequencies above the Nyquist limit. For a guitar, which plays almost everything below 5 kHz, you cannot hear it.
Poles and zeros: why a filter can blow up
Bottom left in the picture are the poles (×) and zeros (○). Zeros are frequencies the filter cancels completely. Poles are frequencies where the feedback part boosts itself. What matters is how far a pole is from the centre of the circle:
- well inside the circle: a gentle filter, no peak,
- near the circle: a sharp peak, resonance, a wah,
- on the circle: the filter rings forever, like an oscillator,
- outside the circle: every sample is bigger than the last and the filter “blows up”.
It is the same rule as the feedback in the delay, where feedback has to stay below 1. The cookbook formulas always keep the poles inside the circle, so the filter is stable for any FREQ and Q. The danger comes when the numbers get rounded. At a low frequency and a high sampleRate the poles sit very close to the circle, and a1 and a2 are close to −2 and 1. A small rounding error can then push a pole over the circle. That is why bass filters on fixed-point chips such as the FV-1 are built with care, while on a chip that works with float numbers, like the STM32 on a Daisy Seed, it is rarely a problem.
The wah: a filter that moves
A wah pedal is a resonant filter whose FREQ you move with your foot, roughly from a few hundred hertz up to about 2 kHz. The “wah” sound comes from the same move your mouth makes when you say “oo-ah”: it changes which frequency is emphasized. In an analog Cry Baby an inductor does that job; in code it is a bandpass or a resonant lowpass with a Q of about 4 to 8.
When FREQ moves, the five numbers have to be worked out again. Do it rarely and the filter jumps in steps, with a quiet “zipper” crackle. Do it for every sample and it costs a lot, because sin and cos are involved. Here the numbers are recomputed every 16 samples, 3,000 times a second, fast enough not to be heard.
An auto-wah does the same, except FREQ is moved not by a foot but by an LFO, as in the tremolo. An envelope filter (Mu-Tron, Q-Tron) moves it with how hard you play: dig in and the filter goes up.
The promised harmonic tremolo
The tremolo article left a debt: the harmonic tremolo from early-sixties Fender amps. Now all the parts are here. The signal is split in two: one through a lowpass, the other through a highpass, both at about 800 Hz. Then each is multiplied by a tremolo, but in opposite phase: when the bass is loud the treble is quiet, and the other way round. The overall volume hardly changes, but the tone keeps moving from dark to bright. That is why it sounds “wetter” and softer than a plain tremolo, and a little like a phaser.
The code, line by line
- Three helper numbers.
w0is FREQ turned into an angle per sample,αcarries Q, andAcarries GAIN. - Five numbers from the recipe in the table, divided by
a0. This is worked out only when a knob moves, not for every sample. - The filter. One line: five multiplications and four additions per sample.
- The memory. The last inputs and outputs move along by one place.
This form is called Direct Form I. There are other forms of the same filter (Direct Form II, transposed), which use less memory or are more accurate in fixed point. They sound the same; the only difference is how the rounding happens.
And in a real pedal?
The biquad is the most common building block of digital effects. For a steeper filter you just put several in a row: two biquads make a fourth-order filter that cuts 24 dB per octave. The speaker simulation in an amp simulator is either a chain of a dozen biquads or the impulse response of a real cabinet. On an STM32 there is a ready-made function for a chain of biquads in the CMSIS-DSP library, arm_biquad_cascade_df1_f32, and it runs exactly this line of code, just optimized.
Per sample that is five multiplications, and an STM32H7 at 48 kHz can run hundreds of biquads before breaking a sweat. That is why digital pedals never skimp on filters.
Next step: reverb, lots of delays and filters at once, arranged to sound like a room →


