running average vs lowpass filter

J

Jamie Morken

Guest
Hi,

I have a 40Hz -3dB RC lowpass filter and I would like to digitize it to
a 1Hz -3dB lowpass filter. I see two methods to do this, by using an
80Hz or greater sampling of the 40Hz signal, and then doing a running
average on it down to 2Hz, and then feeding that 2Hz signal into the
digital filter to get the 1Hz -3dB output. Or the other method would be
to run the filter at an 80Hz sampling rate, which would take a lot more
computations, and (I am using an 8bit microcontroller!). Does the
100Hz filter method have any advantages over the 100Hz running average
method?

cheers,
Jamie
 
In article <3qmd11lqlgm5e7mi460iv4leg0snkn4bti@4ax.com>,
John Larkin <jjSNIPlarkin@highTHISlandPLEASEtechnology.XXX> wrote:
[...]
Out = Out + (In - Out) / K

which can be done in integer math. The divide-by-K can just be a
signed arithmetic right shift. You'd need to use a long enough integer
size to encompass your ADC bit length plus room for the shift, plus a
bit or two more for luck. Be careful about overflows.
You can get other factors in the form of N/K where K is a power of two and
N has a low number of bit set in it. You do it sort of like this:

A = X
A = A SHR 1
A = A + X
A = A SHR 3

This gives you a 3/16 factoring.



--
--
kensmith@rahul.net forging knowledge
 
In article <xMARd.201$0h.3@clgrps13>, Jamie Morken <jmorken@shaw.ca> wrote:
Hi,
[...]

average on it down to 2Hz, and then feeding that 2Hz signal into the
digital filter to get the 1Hz -3dB output.
A simple average sliding along the data is called a "box-car filter"

A Bartlett filter is a lot better than a running average and only takes a
bit more computing power.


X = input
Y = output
Z = other variable
n = Now
K = Width of 1/2 filter

Assuming the X values go into a circular buffer in incrementing order.
You do this:

Z = Z + X(n) - 2*X(n-K) + X(n-2K)
Y = Y + Z

The trick here is to remember to zero everything out at start up and this
only works for integers. Floaters will drift away.

You can do even better if you cascade two stages of filter-decimate code.
The advantage is that you can make the width of the box-car or Bartlett
filters place the zeros at exactly where you want the aliased signals not
to be trouble.


An IIR filter takes less room in memory for a given amount of lowpassing.
It has the disadvantage of a recovery tail.

--
--
kensmith@rahul.net forging knowledge
 

Welcome to EDABoard.com

Sponsor

Back
Top