Cookbook formulae for audio equalizer biquad filter coefficients

Author
Robert Bristow-Johnson
Editor
Doug Schepers (W3C)

Adapted from Audio-EQ-Cookbook.txt, by Robert Bristow, with permission.

Biquad Filter Formulae

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:

(1)H(z)=b0+b1z1+b2z2a0+a1z1+a2z2

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:

(2)H(z)=(b0a0)+(b1a0)z1+(b2a0)z21+(a1a0)z1+(a2a0)z2

or:

(3)H(z)=(b0a0)1+(b1b0)z1+(b2b0)z21+(a1a0)z1+(a2a0)z2

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

y[n]=(b0a0)x[n]+(b1a0)x[n1]+(b2a0)x[n2](4)(a1a0)y[n1](a2a0)y[n2]

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. A=10dBgain/20=10dBgain/40(for peaking and shelving EQ filters only)
  2. ω0=2πf0Fs
  3. cosω0sinω0
  4. α=sinω02Q(case: Q)=sinω0sinh(log22BWω0sinω0)(case: BW)=sinω02(A+1A)(1S1)+2(case: S)

FYI: The relationship between bandwidth and Q is

digital filter with BLT

1Q=2sinh(log22BWω0sinω0)

or

analog filter prototype

1Q=2sinh(log22BW)

The relationship between shelf slope and Q is

1Q=(A+1A)(1S1)+2 2Aα=(sinω0)(A2+1)(1S1)+2A

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+1 b0=1cosω02b1=1cosω0b2=1cosω02a0=1+αa1=2cosω0a2=1α
HPF
H(s)=s2s2+sQ+1 b0=1+cosω02b1=(1+cosω0)b2=1+cosω02a0=1+αa1=2cosω0a2=1α
BPF
(constant skirt gain,
peak gain = Q)
H(s)=ss2+sQ+1 b0=sinω02=Qαb1=0b2=sinω02=Qαa0=1+αa1=2cosω0a2=1α
BPF
(constant 0 dB peak gain)
H(s)=sQs2+sQ+1 b0=αb1=0b2=αa0=1+αa1=2cosω0a2=1α
notch
H(s)=s2+1s2+sQ+1 b0=1b1=2cosω0b2=1a0=1+αa1=2cosω0a2=1α
APF
H(s)=s2sQ+1s2+sQ+1 b0=1αb1=2cosω0b2=1+αa0=1+αa1=2cosω0a2=1α
peakingEQ
H(s)=s2+sAQ+1s2+sAQ+1 b0=1+αAb1=2cosω0b2=1αAa0=1+αAa1=2cosω0a2=1αA
lowShelf
H(s)=As2+AQs+AAs2+AQs+1 b0=A((A+1)(A1)cosω0+2Aα)b1=2A((A1)(A+1)cosω0)b2=A((A+1)(A1)cosω02Aα)a0=(A+1)+(A1)cosω0+2Aαa1=2((A1)+(A+1)cosω0)a2=(A+1)+(A1)cosω02Aα
highShelf
H(s)=AAs2+AQs+1s2+AQs+A b0=A((A+1)+(A1)cosω0+2Aα)b1=2A((A1)+(A+1)cosω0)b2=A((A+1)+(A1)cosω02Aα)a0=(A+1)(A1)cosω0+2Aαa1=2((A1)(A+1)cosω0)a2=(A+1)(A1)cosω02Aα

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

(normalized)

s1tanω021z11+z1

and makes use of these trig identities:

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

resulting in these substitutions:

  1. 11+cosω01+cosω01+2z1+z21+2z1+z2
  2. s1+cosω0sinω01z11+z1=1+cosω0sinω01z21+2z1+z2
  3. s21+cosω01cosω012z1+z21+2z1+z2

The factor:

1+cosω01+2z1+z2

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. 11+2z1+z21+cosω0
  2. s1z2sinω0
  3. s212z1+z21cosω0

In addition, all terms, numerator and denominator, can be multiplied by a common

sin2ω0 factor, finally resulting in these substitutions:
  1. 1(1+2z1+z2)(1cosω0)
  2. s(1z2)sinω0
  3. s2(12z1+z2)(1+cosω0)
  4. 1+s22(12cosω0z1+z2)

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.

Converted to using TeX formulas instead of MathML by Raymond Toy.