KJBob

Recursive Moving Average Filter

Discussion created by KJBob on Nov 5, 2012
Latest reply on Nov 7, 2012 by KJBob

     The moving average filter is a FIR filter of length N with all taps set equal to (1/N).  It's known for lousy frequency separation, but excellent time response -- in that sense, it out-Bessels a Bessel filter.  You can implement it with SigmaStudio's FIR block as described here:

 

http://ez.analog.com/message/21716#21716

 

The longer the filter, the more smoothing -- but the standard FIR filter algorithm uses lots of instructions for huge filters, because it has to multiply coefficients for every tap.  This is a waste when all the coefficients are the same.  As Chapter 15 of Steven W. Smith's book points out, you can make a moving average filter with a recursive technique that has a tap before and after a (N-1) size delay.  Such a filter appears below as part of a test circuit with signal source and a Bessel filter for comparison:

MARFsch.jpg

     Coefficients are pulled out to the single gain block at the input.  The present sample adds to the output as it enters the delay, the delayed sample subtracts from the output as it exits.  The adder with the feedback accumulates these additions and subtractions to form the output -- this does something that's trivial in C but is otherwise a pain in the GUI.  Although a recursive technique is used, the filter remains a true FIR filter -- the length of its impulse response is set only by your delay.

 

     My test input is a square wave with added noise.  Filtered results appear as the upper trace in both photos -- First the moving average filter:

MARFout_2.jpg

 

The Bessel filter:

MARFout_1.jpg

     The moving average filter allows more noise through, but it better preserves the square wave's shape -- it doesn't round the corners, and the up and down slopes are symmetrical (it's linear phase).  Listening to the two waveforms with headphones shows a similar result -- more noise with the moving average filter, but the characteristic sound of a square wave comes through.

Attachments

Outcomes