An253 – Cirrus Logic AN253 User Manual
Page 9

AN253
9
in a 2-cycle increase in performance per iteration of the loop construct. This increase in performance can
be significant for FIR filters with large numbers of coefficients.
In this next algorithm and architectural optimization example, a Biquad IIR filter (Figure 3) is modified to
reduce the number of loads/stores in the inner loop. The Biquad IIR filter’s difference equation is:
y[n] = b[0]*x[n] + b[1]*x[n-1] + b[2]*x[n-2] - a[1]*y[n-1] - a[2]*y[n-2]
One C implementation of this IIR Biquad difference equation, and the one used for this example is:
double inp, accumulator;
long i;
for (i=0; i<(long)nn; i++)
{
inp = data[i];
accumulator = 0;
accumulator -= filtcoefs[0]*bqd1k_dCstates[0];
accumulator -= filtcoefs[0]*bqd1k_dCstates[1];
accumulator += filtcoefs[2]*inp;
accumulator += filtcoefs[3]*bqd1k_dCstates[2];
accumulator += filtcoefs[4]*bqd1k_dCstates[3];
// Update y[n] states (output history for feedback lines)
bqd1k_dCstates[1] = bqd1k_dCstates[0];
bqd1k_dCstates[0] = accumulator;
// Store the output
data[i] = accumulator;
// Update x[n] states (input history for delay lines)
bqd1k_dCstates[3] = bdq1k_dCstates[2];
bqd1k_dCstates[2] = inp;
}
In the assembly version of the original algorithm (on the left), the filter coefficients are loaded when need-
ed. Consequently, they are loaded in each iteration of the loop. Additionally, the state variables are loaded
when needed and then stored when updated. They are also loaded and stored in each iteration of the
loop.