# Cookbook formulae for audio equalizer biquad filter coefficients

Author
Robert Bristow-Johnson
Editor
Doug Schepers (W3C)

All filter transfer functions were derived from analog prototypes (that are shown below for each equalizer (EQ) filter type) and had been digitized using the Bilinear Transform (BLT). BLT frequency warping has been taken into account for both significant frequency relocation (this is the normal "prewarping" that is necessary when using the BLT) and for bandwidth readjustment (since the bandwidth is compressed when mapped from analog to digital using the BLT).

First, given a biquad transfer function defined as:

This shows 6 coefficients instead of 5 so, depending on your architecture, you will likely normalize $a0$ to be 1 and perhaps also $b0$ to 1 (and collect that into an overall gain coefficient). Then your transfer function would look like:

or:

$H\left(z\right)=\left(\frac{{b}_{0}}{{a}_{0}}\right)\cdot \frac{1+\left(\frac{{b}_{1}}{{b}_{0}}\right)\cdot {z}^{-1}+\left(\frac{{b}_{2}}{{b}_{0}}\right)\cdot {z}^{-2}}{1+\left(a\frac{1}{a}0\right)\cdot {z}^{-1}+\left(a\frac{2}{a}0\right)\cdot {z}^{-2}}\text{(equation 3)}$

The most straight forward implementation would be the "Direct Form 1" (equation 2):

$\begin{array}{llll}y\left[n\right]& =\left(\frac{{b}_{0}}{{a}_{0}}\right)\cdot x\left[n\right]& +\left(\frac{{b}_{1}}{{a}_{0}}\right)\cdot x\left[n-1\right]+\left(\frac{{b}_{2}}{{a}_{0}}\right)\cdot x\left[n-2\right]& \\ & & -\left(\frac{{a}_{1}}{{a}_{0}}\right)\cdot y\left[n-1\right]-\left(\frac{{a}_{2}}{{a}_{0}}\right)\cdot y\left[n-2\right]& \text{(equation 4)}\end{array}$

This is probably both the best and the easiest method to implement in the 56K and other fixed-point or floating-point architectures with a double wide accumulator.

Begin with these user defined parameters:

$Fs$
the sampling frequency
$f0$
Center Frequency or Corner Frequency, or shelf midpoint frequency, depending on which filter type. The "significant frequency". "wherever it's happenin', man."
$dBgain$
used only for peaking and shelving filters
$Q$ or $BW$ or $S$
$Q$
the EE kind of definition, except for peakingEQ in which A*Q is the classic EE Q. That adjustment in definition was made so that a boost of N dB followed by a cut of N dB for identical Q and f0/Fs results in a precisely flat unity gain filter or "wire".
$BW$
the bandwidth in octaves (between -3 dB frequencies for BPF and notch or between midpoint (dBgain/2) gain frequencies for peaking EQ)
$S$
a "shelf slope" parameter (for shelving EQ only). When S = 1, the shelf slope is as steep as it can be and remain monotonically increasing or decreasing gain with frequency. The shelf slope, in dB/octave, remains proportional to S for all other values for a fixed f0/Fs and dBgain

Then compute a few intermediate variables:

1. $\begin{array}{lll}A& =\sqrt{{10}^{\frac{dBgain}{20}}}& \\ & ={10}^{\frac{dBgain}{40}}& \text{(for peaking and shelving EQ filters only)}\end{array}$
2. ${\omega }_{0}=2\cdot \pi \cdot \frac{{f}_{0}}{{F}_{s}}$
3. $cos(ω0)$ $sin(ω0)$
4. $\begin{array}{lll}\alpha & =\frac{\mathrm{sin}\left({\omega }_{0}\right)}{2\cdot Q}& \text{(case: Q)}\\ & =\mathrm{sin}\left({\omega }_{0}\right)\cdot \mathrm{sinh}\left(\frac{\mathrm{ln}\left(2\right)}{2}\cdot BW\cdot \frac{{\omega }_{0}}{\mathrm{sin}\left({\omega }_{0}\right)}\right)& \text{(case: BW)}\\ & =\frac{\mathrm{sin}\left({\omega }_{0}\right)}{2}\cdot \sqrt{\left(A+\frac{1}{A}\right)\cdot \left(\frac{1}{S}-1\right)+2}& \text{(case: S)}\end{array}$

FYI: The relationship between bandwidth and Q is

digital filter with BLT

$\frac{1}{Q}=2\cdot sinh\left(\frac{ln\left(2\right)}{2}\cdot \mathrm{BW}\cdot \frac{{\omega }_{0}}{sin\left({\omega }_{0}\right)}\right)$

or

analog filter prototype

$1Q=2⋅sinh(ln(2)2⋅BW)$

The relationship between shelf slope and Q is

$1Q=(A+1A)⋅(1S-1)+2$ $2⋅A⋅α=sin(ω0)⋅(A2+1)⋅(1S-1)+2⋅A$

is a handy intermediate variable for shelving EQ filters.

Finally, compute the coefficients for whichever filter type you want:

(The analog prototypes, H(s), are shown for each filter type for normalized frequency.)

LPF
$H(s)=1s2+sQ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A+1)-(A-1)⋅cos(ω0)+2⋅A⋅αa1=2⋅((A-1)-(A+1)⋅cos(ω0))a2=(A+1)-(A-1)⋅cos(ω0)-2⋅A⋅α$

FYI: The bilinear transform (with compensation for frequency warping) substitutes:

(normalized)

$s←1tan(ω02)⋅1-z-11+z-1$

and makes use of these trig identities:

1. $tan(ω02)=sin(ω0)1+cos(ω0)$
2. $(tan(ω02))2=1-cos(ω0)1+cos(ω0)$

resulting in these substitutions:

1. $1←1+cos(ω0)1+cos(ω0)⋅1+2⋅z-1+z-21+2⋅z-1+z-2$
2. $s←1+cos(ω0)sin(ω0)⋅1-z-11+z-1=1+cos(ω0)sin(ω0)⋅1-z-21+2⋅z-1+z-2$
3. $s2←1+cos(ω0)1-cos(ω0)⋅1-2⋅z-1+z-21+2⋅z-1+z-2$

The factor:

$1+cos(ω0)1+2⋅z-1+z-2$

is common to all terms in both numerator and denominator, can be factored out, and thus be left out in the substitutions above resulting in:

1. $1←1+2⋅z-1+z-21+cos(ω0)$
2. $s←1-z-2sin(ω0)$
3. $s2←1-2⋅z-1+z-21-cos(ω0)$

In addition, all terms, numerator and denominator, can be multiplied by a common $(sin(ω0))2$ factor, finally resulting in these substitutions:

1. $1←(1+2⋅z-1+z-2)⋅(1-cos(ω0))$
2. $s←(1-z-2)⋅sin(ω0)$
3. $s2←(1-2⋅z-1+z-2)⋅(1+cos(ω0))$
4. $1+s2←2⋅(1-2⋅cos(ω0)⋅z-1+z-2)$

The biquad coefficient formulae above come out after a little simplification.

## Acknowledgements

Special thanks to Robert Bristow-Johnson for creating the Audio EQ Cookbook and permitting its adaption and use for the Web Audio API.

Thanks to Peter Krautzberger for help in adapting these mathematical formulae to MathML, and to the whole MathJax team for making the JavaScript extension that makes the use of math on the web possible.

Thanks to Peter Jipsen, creator of ASCIIMathML, for making it easier to convert ASCII math notation to MathML.