I have 5 'negative peaking' biquads that will change center frequency while maintaining a constant Q and A (amplitude reduction) on a realtime microcontroller (ARM cortex-m4) with a codec over i2s controlled by i2c system operating at 96kHz. I am concerned (with concerns raised by my oscilloscope) that I am going to be hosed by divisions and sine/cosine. What can I do to speed things up?

Using RBJ's EQ cookbook, a peak filter takes the following coefficients:

w0 = 2*pi*f0/Fs;
A  = sqrt(10^(dBgain/40));
alpha = (sin(w0)/(2*Q));

b0 =   1 + alpha*A;
b1 =  -2*cos(w0);
b2 =   1 - alpha*A;
a0 =   1 + alpha/A;
a1 =  -2*cos(w0);
a2 =   1 - alpha/A;

Furthermore, the feedback coefficients will take the form c0 = b0/a0 c1 = b1/a0 c2 = b2/a0 and the feedforward coefficients: c3 = a1 / a0; c4 = a2 / a0;

Expanding these divisions:

c0 = (1 + (sin(w0)/(2*Q))*A)/(1 + (sin(w0)/(2*Q))/A);
c1 = -2*cos(w0) /  (1 + sin(w0)/(2*Q)/A);
c2 =  (1 - (sin(w0)/(2*Q))*A)/(1 + (sin(w0)/(2*Q))/A);
c3 = c1;
c4 = (1 - (sin(w0)/(2*Q))/A) / (1 + (sin(w0)/(2*Q))/A);

Using simplify() in MATLAB with symbolic variables w0, Q, and A, we obtain:

c0 = (2AQ + A^2*sin(w0))/(2AQ+sin(w0))
c1 = -(4AQ*cos(w0))/(sin(w0) + 2AQ)
c2 = -(A^2*sin(w0) - 2AQ)/(2AQ + sin(w0));
c3 = c1;
c4 =  -(sin(w0)- 2AQ)/(2AQ + sin(w0)); 

If Q and A are constant, no problem, these can be computed ahead of time. What will kill me are the divisions and the sine/cosine computations.

What tricks or processes can be used to speed up the calculation or if at all, further simplify or approximate the filter coefficients?

  • 2
    $\begingroup$ listen, i never wrote in the cookbook that this Direct Form 1 works real good for time-variant coefficients. if they vary slowly, it's probably not too bad. otherwise you need to look into other forms, most likely either the Lattice or Normalized Ladder or maybe Hal Chamberlin's State-Variable Filter. since they all boil down to 2nd-order IIR filters, you can map the coefficients in these other forms to the coefficients in the DF1, but there some work involved. in those other filters, there is a single coefficient that determines the resonant frequency. so it's decoupled from Q. $\endgroup$ May 18, 2015 at 19:57
  • $\begingroup$ Thanks for the suggestions. I don't think these filters are going to cut it for high-Q (Q>2) negative peaking filters. I tried the state-variable filter in MATLAB, which is lightning fast and would be great for a synth but I have five time-varying narrow bands where I'm trying to apply a severe magnitude rejection. The lattice looks useful for allpass, but I can't see how it would apply to the case of a negative peaking EQ. I may end up going with your DF1 but limiting the time varying case to every 128 or 256 samples. The ladder seems appropriate for a resonator but not a deep notch. $\endgroup$
    – panthyon
    May 19, 2015 at 19:58
  • $\begingroup$ The problem with SVF being it can't realize Q > 2, let alone specify the depth of the notch, at least with the implementation I used from musicdsp.org $\endgroup$
    – panthyon
    May 19, 2015 at 20:08

1 Answer 1


there is an earlier answer regarding how to more cheaply evaluate functions like sin() and log() and such. they're approximations, but very good ones.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.