title: How to implement IIR filter in C?
body: <p>I am trying to implement an IIR filter. </p>
  
  <p>I tried to implement the following filter but </p>
  
  <pre><code>FIR : y(n) = b0(x[n]) + ... +bM-1(x[n-M+1])
  
  IIR : y(n) = {b0(x[n]) + ... +bM-1(x[n-M+1])} - {a1(y[n-1]) + ... +aN(y[n-N}
  </code></pre>
  
  <p>I am confused on how to implement <code>y[n-1].....</code>.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>void IIRFloat(double *coeffs_B, double *coeffs_A, double *input, double *output, int length, int filterLength)
  {
      double bcc, acc;
      double *coeffa, *coeffb;
      double *inputp;
      double *outputp;
      int n,k;
  
      //filter length =7
      for (n = 0; n &lt; length; n++) {
          coeffa = coeffs_A;
          coeffb = coeffs_B;
          inputp = &amp;insamp[filterLength - 1 + n]; //insamp[6]~insamp[85]
  
          acc = 0;
          bcc = 0;
  
          for (k = 0; k &lt; filterLength; k++) {
              bcc += (*coeffb++) * (*inputp--); //b[0] * x[6] + b[1] * x[5]...+b[6] * x[0]
          }
  
          for (k = 1; k &lt; filterLength; k++) {
              acc += (*coeffa++) * (*output--); //a[1] * y[5] + a[2] * y[4]...+a[6] * y[0]
          }
          output[n] = bcc-acc;
  
      }
  }
  </code></pre>
  
  <p>I will not copy here the code for <code>memove</code> function for seek of brevity.</p>