[sdiy] ADC filtering (was Re: A/D converter with good accuracy for a reasonable price?)
Colin f
colin at colinfraser.com
Sun May 8 02:19:39 CEST 2011
> For a moving sample filter of size 4, you will start with an
> array like a[4] filled initially with zeroes. You use that
> as a ring buffer and each sample time compute the new average as:
>
> Out=(a[0]+a[1]+a[2]+a[3])/4;
>
> Note that divide by 4 can be done with 2 right shifts. You
> maintain a modulo 4 update pointer so that it simply wraps
> and always destroys the oldest value to insert the newest
> value. The update pointer is incremented each sample time.
>
> The value Out is what you use as a "cleaned up" or filtered sample.
As a simple speed optimisation, you can also keep a running total for the
average.
Before you over-write the update pointer, subtract the doomed value from the
running total, and add the new one.
Then your out calculation needs far fewer adds for a long buffer.
Cheers,
Colin f
More information about the Synth-diy
mailing list