Cookbook formulae for audio equalizer biquad filter coefficients

Author:
Robert Bristow-Johnson
Editor:
Doug Schepers (previously W3C)
Editor's Draft:
https://github.com/shepazu/Audio-EQ-Cookbook

Adapted from http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt, with permission.

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:

H ( z ) = b 0 + b 1 z - 1 + b 2 z - 2 a 0 + a 1 z - 1 + a 2 z - 2     (equation 1)

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:

H ( z ) = ( b 0 a 0 ) + ( b 1 a 0 ) z - 1 + ( b 2 a 0 ) z - 2 1 + ( a 1 a 0 ) z - 1 + ( a 2 a 0 ) z - 2     (equation 2)

or:

H ( z ) = ( b 0 a 0 ) 1 + ( b 1 b 0 ) z - 1 + ( b 2 b 0 ) z - 2 1 + ( a 1 a 0 ) z - 1 + ( a 2 a 0 ) z - 2 (equation 3)

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

y [ n ] = ( b 0 a 0 ) x [ n ] + ( b 1 a 0 ) x [ n - 1 ] + ( b 2 a 0 ) x [ n - 2 ] - ( a 1 a 0 ) y [ n - 1 ] - ( a 2 a 0 ) y [ n - 2 ] (equation 4)

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 = 10 dBgain 20 = 10 dBgain 40 (for peaking and shelving EQ filters only)
  2. ω 0 = 2 π f 0 F s
  3. cos(ω0) sin(ω0)
  4. α = sin ( ω 0 ) 2 Q (case: Q) = sin ( ω 0 ) sinh ( ln ( 2 ) 2 B W ω 0 sin ( ω 0 ) ) (case: BW) = sin ( ω 0 ) 2 ( A + 1 A ) ( 1 S - 1 ) + 2 (case: S)

FYI: The relationship between bandwidth and Q is

digital filter with BLT

1 Q = 2 sinh ( ln ( 2 ) 2 BW ω 0 sin ( ω 0 ) )

or

analog filter prototype

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

The relationship between shelf slope and Q is

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

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

(normalized)

s1tan(ω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. 11+cos(ω0)1+cos(ω0)1+2z-1+z-21+2z-1+z-2
  2. s1+cos(ω0)sin(ω0)1-z-11+z-1=1+cos(ω0)sin(ω0)1-z-21+2z-1+z-2
  3. s21+cos(ω0)1-cos(ω0)1-2z-1+z-21+2z-1+z-2

The factor:

1+cos(ω0)1+2z-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. 11+2z-1+z-21+cos(ω0)
  2. s1-z-2sin(ω0)
  3. s21-2z-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+2z-1+z-2)(1-cos(ω0))
  2. s(1-z-2)sin(ω0)
  3. s2(1-2z-1+z-2)(1+cos(ω0))
  4. 1+s22(1-2cos(ω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.