# Where can I find information about how to implement IIR filters on micro-controllers?

I am trying to implement an IIR filter on a LPC1769 (I don't know if it's relevant). I already have the H(z) so all the design part is prety much solved. What I am looking for is information about:

• How to select an appropiate word lenght for the coefficients, acummulator, etc.
• How to select the most appropiate structure (parallel,cascade, direct forms, indirect forms....) (or some guidance at least)
• Some understanding on how to avoid overflow (scalling the coefficients or signal)
• A deeper explanation of the fdatool parameters than the one given in real-time digital signal processing.
• etc....

I've been using the fdatool of matlab to play around with the quatization of the filter. But I don't know the implications of these or what they actually mean.

I've also been reading a few chapters of this book: real-time digital signal processing : implementations and applications sen m. kuo, but I am looking for more detail in these implementation aspects. So could you tell me of some book, application note, paper or whatever that explains these issues?

I am triying to implement an A-weighting filter (the transfer function is in the link). The application is mainly taking data from the adc, perform the A-weighting and taking the RMS value of this signal.

• what's your application ? Jul 9 '19 at 0:27
• I've added it, thanks! Jul 9 '19 at 0:41
• Take a look at this section of the ARM Cortex M3 instruction set: 34.2.6.2 UMULL, UMLAL, SMULL, and SMLAL on page 706 and 34.2.3.4 Shift Operations on page 664. You will use those instructions a lot. with 32-bit operand words and a 64-bit accumulator, you will have no problem with lack of precision. either left-justify your signals or make sure the sign bit is extended to the left. remember what scaling you apply to coefficients because your result will be too large by that factor. if you line things up right, your result will simply be in the most-significant word. Jul 9 '19 at 4:05
• in fixed point, you want to use the Direct Form 1 and an accumulator that is double wide. you're gonna have a lotta fun doing high-quality fixed-point DSP with this. 32-bit words (and a 64-bit accumulator) are plenty wide. just be careful about scaling and overflow. Jul 9 '19 at 4:06
• is your LPC1769 doing other tasks besides this A-weighted audio meter? i think you're gonna have MIPS to burn!!! but maybe there are other tasks that you will have to share with. are you doing this in the ARM assembly language? with C, you do not have a natural 32 bit x 32 bit going into a 64 bit result. with C it's more wasteful. also, if you're doing dB, you need a good $\log_2(\cdot)$ function. i posted some good polynomial approximations here somewhere. Jul 9 '19 at 4:15

Here are 3 points that you must consider :

1 - What is the minimal latency you can tolerate? This is important, as it's important to know whether to need process every sample as fast as possible or if you can perform batch processing which is typically more efficient but creates latency .

2 - No matter if you implement the IIR in fixed-point or floating-point, it is always a good idea to split the filter in sub-filters. This minimizes quantization issues that can occur even if you use double-precision arithmetic. One effective strategy is to cascade the filter in second-order sub-filters. Check out https://www.mathworks.com/help/signal/ref/sosfilt.html

3 - If you implement in fixed-point, it is a good idea to create a fixed-point model in Matlab/Python/Scilab/tool of your choice and compare it to the "ideal" floating-point filter before implementing it in your microcontroller.

• Ben, I can wait a second or even more to have the output of the filter, so that is not a problem. I was thinking of using fixed point. Like I've said in the question I've played around with the fdatool and with the quantization parameters. What I would like to know is the meaning of those parameters so I can recreate them at the time of programming the micro-controller and find the options that best suit my problem. What would be really useful is that you could refer me to some article, book or whatever that talks about these issues. Jul 9 '19 at 2:07
• Well technically, if you toy around with the FDA toolbox it tells you how many bits there are in the accumulator, in the coefficients, number of guard bits, etc. From there, it should be easy if you know how to perform fixed-point calculations in C. You can also check this pdf ece.uah.edu/~jovanov/CPE495/notes/msp430_filter.pdf
– Ben
Jul 9 '19 at 2:45

ARM provides efficient reference implementations of different DSP processes, including IIR: https://arm-software.github.io/CMSIS_5/DSP/html/index.html You can try them out and evaluate which is best for your purposes by checking performance and memory consumption. You could probably optimize for your specific application, but I wouldn’t bother unless it becomes a problem. This should get your concept on target in a hurry.