> ----------------------------------------------------------------------------- > -- | > -- Module : DSP.Filter.IIR.IIR > -- Copyright : (c) Matthew Donadio 2003 > -- License : GPL > -- > -- Maintainer : m.p.donadio@ieee.org > -- Stability : experimental > -- Portability : portable > -- > -- Cookbook formulae for audio EQ biquad filter coefficients > -- by Robert Bristow-Johnson <robert@wavemechanics.com> > -- > -- <http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt> > -- > -----------------------------------------------------------------------------

> module DSP.Filter.IIR.Cookbook where

> import DSP.Filter.IIR.IIR

> import DSP.Basic((^!))Cookbook formulae for audio EQ biquad filter coefficients ----------------------------------------------------------------------------- by Robert Bristow-Johnson

> {-# specialize lpf :: Float -> Float -> [Float] -> [Float] #-} > {-# specialize lpf :: Double -> Double -> [Double] -> [Double] #-}

> lpf :: Floating a => a -> a -> [a] -> [a] > lpf bw w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = (1 - cos w) / 2 > b1 = 1 - cos w > b2 = (1 - cos w) / 2 > a0 = 1 + alpha > a1 = -2 * cos w > a2 = 1 - alpha > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w)HPF: H(s) = s^2 / (s^2 + s/Q + 1) b0 = (1 + cos)/2 b1 = -(1 + cos) b2 = (1 + cos)/2 a0 = 1 + alpha a1 = -2*cos a2 = 1 - alpha

> {-# specialize hpf :: Float -> Float -> [Float] -> [Float] #-} > {-# specialize hpf :: Double -> Double -> [Double] -> [Double] #-}

> hpf :: Floating a => a -> a -> [a] -> [a] > hpf bw w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = (1 + cos w) / 2 > b1 = -(1 + cos w) > b2 = (1 + cos w) / 2 > a0 = 1 + alpha > a1 = -2 * cos w > a2 = 1 - alpha > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w)BPF: H(s) = s / (s^2 + s/Q + 1) (constant skirt gain, peak gain = Q) b0 = sin/2 = Q*alpha b1 = 0 b2 = -sin/2 = -Q*alpha a0 = 1 + alpha a1 = -2*cos a2 = 1 - alpha

> {-# specialize bpf_csg :: Float -> Float -> [Float] -> [Float] #-} > {-# specialize bpf_csg :: Double -> Double -> [Double] -> [Double] #-}

> bpf_csg :: Floating a => a -> a -> [a] -> [a] > bpf_csg bw w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = sin w / 2 > b1 = 0 > b2 = -sin w / 2 > a0 = 1 + alpha > a1 = -2 * cos w > a2 = 1 - alpha > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w)BPF: H(s) = (s/Q) / (s^2 + s/Q + 1) (constant 0 dB peak gain) b0 = alpha b1 = 0 b2 = -alpha a0 = 1 + alpha a1 = -2*cos a2 = 1 - alpha

> {-# specialize bpf_cpg :: Float -> Float -> [Float] -> [Float] #-} > {-# specialize bpf_cpg :: Double -> Double -> [Double] -> [Double] #-}

> bpf_cpg :: Floating a => a -> a -> [a] -> [a] > bpf_cpg bw w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = alpha > b1 = 0 > b2 = -alpha > a0 = 1 + alpha > a1 = -2 * cos w > a2 = 1 - alpha > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w)notch: H(s) = (s^2 + 1) / (s^2 + s/Q + 1) b0 = 1 b1 = -2*cos b2 = 1 a0 = 1 + alpha a1 = -2*cos a2 = 1 - alpha

> {-# specialize notch :: Float -> Float -> [Float] -> [Float] #-} > {-# specialize notch :: Double -> Double -> [Double] -> [Double] #-}

> notch :: Floating a => a -> a -> [a] -> [a] > notch bw w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = 1 > b1 = -2 * cos w > b2 = 1 > a0 = 1 + alpha > a1 = -2 * cos w > a2 = 1 - alpha > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w)APF: H(s) = (s^2 - s/Q + 1) / (s^2 + s/Q + 1) b0 = 1 - alpha b1 = -2*cos b2 = 1 + alpha a0 = 1 + alpha a1 = -2*cos a2 = 1 - alpha

> {-# specialize apf :: Float -> Float -> [Float] -> [Float] #-} > {-# specialize apf :: Double -> Double -> [Double] -> [Double] #-}

> apf :: Floating a => a -> a -> [a] -> [a] > apf bw w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = 1 - alpha > b1 = -2 * cos w > b2 = 1 + alpha > a0 = 1 + alpha > a1 = -2 * cos w > a2 = 1 - alpha > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w)peakingEQ: H(s) = (s^2 + s*(A/Q) + 1) / (s^2 + s/(A*Q) + 1) b0 = 1 + alpha*A b1 = -2*cos b2 = 1 - alpha*A a0 = 1 + alpha/A a1 = -2*cos a2 = 1 - alpha/A

> {-# specialize peakingEQ :: Float -> Float -> Float -> [Float] -> [Float] #-} > {-# specialize peakingEQ :: Double -> Double -> Double -> [Double] -> [Double] #-}

> peakingEQ :: Floating a => a -> a -> a -> [a] -> [a] > peakingEQ bw dBgain w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = 1 + alpha * a > b1 = -2 * cos w > b2 = 1 - alpha * a > a0 = 1 + alpha / a > a1 = -2 * cos w > a2 = 1 - alpha / a > alpha = sin w * sinh (log 2 / 2 * bw * w / sin w) > a = 10 ** (dBgain / 40)lowShelf: H(s) = A * (s^2 + (sqrt(A)/Q)*s + A) / (A*s^2 + (sqrt(A)/Q)*s + 1) b0 = A*[ (A+1) - (A-1)*cos + beta*sin ] b1 = 2*A*[ (A-1) - (A+1)*cos ] b2 = A*[ (A+1) - (A-1)*cos - beta*sin ] a0 = (A+1) + (A-1)*cos + beta*sin a1 = -2*[ (A-1) + (A+1)*cos ] a2 = (A+1) + (A-1)*cos - beta*sin

> {-# specialize lowShelf :: Float -> Float -> Float -> [Float] -> [Float] #-} > {-# specialize lowShelf :: Double -> Double -> Double -> [Double] -> [Double] #-}

> lowShelf :: Floating a => a -> a -> a -> [a] -> [a] > lowShelf s dBgain w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = a*( (a+1) - (a-1) * cos w + beta * sin w) > b1 = 2*a*( (a-1) - (a+1) * cos w ) > b2 = a*( (a+1) - (a-1) * cos w - beta * sin w) > a0 = (a+1) + (a-1) * cos w + beta * sin w > a1 = -2*( (a-1) + (a+1) * cos w ) > a2 = (a+1) + (a-1) * cos w - beta * sin w > beta = sqrt ((a^!2 + 1) / s - (a-1)^!2) > a = 10 ** (dBgain / 40)highShelf: H(s) = A * (A*s^2 + (sqrt(A)/Q)*s + 1) / (s^2 + (sqrt(A)/Q)*s + A) b0 = A*[ (A+1) + (A-1)*cos + beta*sin ] b1 = -2*A*[ (A-1) + (A+1)*cos ] b2 = A*[ (A+1) + (A-1)*cos - beta*sin ] a0 = (A+1) - (A-1)*cos + beta*sin a1 = 2*[ (A-1) - (A+1)*cos ] a2 = (A+1) - (A-1)*cos - beta*sin

> {-# specialize highShelf :: Float -> Float -> Float -> [Float] -> [Float] #-} > {-# specialize highShelf :: Double -> Double -> Double -> [Double] -> [Double] #-}

> highShelf :: Floating a => a -> a -> a -> [a] -> [a] > highShelf s dBgain w = biquad_df1 (a1/a0) (a2/a0) (b0/a0) (b1/a0) (b2/a0) > where b0 = a*( (a+1) - (a-1) * cos w + beta * sin w) > b1 = -2*a*( (a-1) - (a+1) * cos w ) > b2 = a*( (a+1) - (a-1) * cos w - beta * sin w) > a0 = (a+1) + (a-1) * cos w + beta * sin w > a1 = -2*( (a-1) + (a+1) * cos w ) > a2 = (a+1) + (a-1) * cos w - beta * sin w > beta = sqrt ((a^!2 + 1) / s - (a-1)^!2) > a = 10 ** (dBgain / 40)(This text-only file is best viewed or printed with a mono-spaced font.)