ΣSigmaStudio Ask AI Русский Log in

Recursive Moving Average Filter

SigmaDSP & SigmaStudio KJBob Nov 5, 2012 00:00 2 replies Original on forum ↗
Subscribe
KJBob Question
Nov 5, 2012 00:00

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:

https://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:

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:

The Bessel filter:

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.

smoothing

bessel

filter

accumulator

fir

moving_average

recursive

Show More

0675.dfe0284d37e98a104cff35206301ef25.jpg
0675.dfe0284d37e98a104cff35206301ef25.jpg
6445.dfe0284d37e98a104cff35206301ef25.jpg-585x198.jpg
Open original image
6761.ebfe84ac6cc2f3b5046f42d6c94ddef4.jpg
6761.ebfe84ac6cc2f3b5046f42d6c94ddef4.jpg
0677.ebfe84ac6cc2f3b5046f42d6c94ddef4.jpg-450x240.jpg
0677.ebfe84ac6cc2f3b5046f42d6c94ddef4.jpg-450x240.jpg
3755.cd484791f27dae2190ce105c8154b66c.jpg
3755.cd484791f27dae2190ce105c8154b66c.jpg
2627.cd484791f27dae2190ce105c8154b66c.jpg-450x242.jpg
2627.cd484791f27dae2190ce105c8154b66c.jpg-450x242.jpg
ADIApproved Reply
Nov 6, 2012 00:00

Hi Bob,

That's great! Maybe I can convince the software team to make a new cell from that concept and add it to the "Envelopes" library.

KJBob Reply
Nov 7, 2012 00:00

Brett.

That would make my day to see that filter incorporated into SigmaStudio. Users would only need to input the FIR length and the compiler would do the rest. Great idea!

Bob