Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Biquad Software Implementations

In matlab, an efficient biquad section is implemented by calling

        outputsignal = filter(B,A,inputsignal);
where

\begin{eqnarray*}
\texttt{B} &=& [g, g\beta_1, g\beta_2],\\
\texttt{A} &=& [1, a_1, a_2].
\end{eqnarray*}

A complete C++ class implementing a biquad filter section is included in the free, open-source Synthesis Tool Kit (STK) [15]. (See the BiQuad STK class.)

Figure B.10 lists an example biquad implementation in the C programming language.

Figure B.10: C code implementing a biquad filter section.

 
  typedef double *pp;  // pointer to array of length NTICK
  typedef word double; // signal and coefficient data type

  typedef struct _biquadVars {
      pp output;
      pp input;
      word s2;
      word s1;
      word gain;
      word a2;
      word a1;
      word b2;
      word b1;
  } biquadVars;

  void biquad(biquadVars *a)
  {
      int i;
      dbl A;
      word s0;
      for (i=0; i<NTICK; i++) {
          A = a->gain * a->input[i];
          A -= a->a1 * a->s1;
          A -= a->a2 * a->s2;
          s0 = A;
          A += a->b1 * a->s1;
          a->output[i] = a->b2 * a->s2 + A;
          a->s2 = a->s1;
          a->s1 = s0;
      }
  }


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]

``Introduction to Digital Filters with Audio Applications'', by Julius O. Smith III, (September 2007 Edition).
Copyright © 2014-03-23 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA