Wednesday, 10 January 2018

Should I MAC Or Should I MSUB (With Apologies To The Clash)

When implementing FIR filters the coefficients are all in a linear array so the task of importing the coefficients into an application is relatively straight forward.

Importing IIR coefficients into an application, however, is quite different and there are several traps than can cause the application to fail.

The following diagram shows the flow diagram of a direct form I IIR biquad :


All digital filter design programs will return a single or multi-dimensional array along the lines of the following :

int pIIRCoeffs[NUMBER_OF_FILTER_STAGES * NUMBER_OF_COEFFS_PER_BIQUAD] = {
    Coefficients for Biquad #1,
    Coefficients for Biquad #2,
    Coefficients for Biquad #3
};

There are two traps to consider when using the coefficients from a digital filter design program.

  1. The sign of the feedback coefficients may or may not be negated, in which case you may need to negate the coefficients yourself.
  2. There is no international standard for which set of coefficients should be notated an or bn. You should check the documentation of your design tools because there are always : 3 feedforward coefficients and 2 feedback coefficients. You may need to re-order the feedforward and feedback coefficients in your array.
Point 1. raises further issues with the implementation :


  1. Negating the feedback coefficients allows the use of the Multiply-Accumulate (mac) instruction, which is available on all DSPs and many microprocessors and microcontrollers.
  2. Not negating the feedback coefficients will require a multiply followed by a subtract. Nearly all DSPs and some microprocessors and microcontrollers implement a Multiply-Subtract (msub) instruction. If your chosen device does not implement msub then the multiply and subtract operations will be separated leading to slower performance. In this case it would be better to negate the coefficients and use a code implementation that uses the mac instruction. Many digital filter design programs, including Numerix' Digital Filter Plus (http://www.numerix-dsp.com/dfplus/) provide an option to pre-negate the coefficients, which allows the use of the mac instruction. The SigLib DSP library (http://www.numerix-dsp.com/siglib.html) includes functions to implement either format.

If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.

Evaluate The Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

Copyright © 2018 Delta Numerix

No comments:

Post a Comment