Newsgroups: comp.speech,comp.dsp,comp.robotics
From: tchannon@black.demon.co.uk (Tim Channon)
Path: lyra.csx.cam.ac.uk!pipex!demon!black.demon.co.uk!tchannon
Subject: Re: calc. of long & short term avgs.
References: <31620k$n2i@falcon.ccs.uwo.ca>
Followup-To: comp.speech
Lines: 19
Date: Fri, 29 Jul 1994 18:48:46 +0000
Message-ID: <775532926snx@black.demon.co.uk>
Sender: usenet@demon.co.uk
Xref: lyra.csx.cam.ac.uk comp.speech:2962 comp.dsp:8567 comp.robotics:9566

> >Help!  I am trying to calculate a long-term average at each point of
> >a continuous data stream.  The following algorithm works fine when using
> >floating point type values but does not for integer types (e.g. 8 or 16 bit
> >integer) because of loss of precision when the oldLTA(see eq.) approaches
> >the current data value.

If long term is short enough for power of 2 RAM locations you could try a
crude moving average filter which is very fast to compute on 8 bitters as
well as simple. It must be initialised before use.

  acc = acc - data[i]
  data[i] = newdata
  acc = acc + newdata
  i = (i+1) mod N  -- for ^2 just i & (N-1)
  av = acc div N -- for ^2 is shift, round if you want.

  TC. 
    E-mail: tchannon@black.demon.co.uk or tchannon@cix.compulink.co.uk
                               
