Searching \ for '[PIC:] moving average filter' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/math/filter.htm?key=filter
Search entire site for: 'moving average filter'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] moving average filter'
2003\09\18@122127 by Robert Mash

flavicon
face
Is there a way to do an n sample moving average without storing n samples?
I want to do a 20 sample moving average.  Do I need to set aside 20 locations/variables for this task?
Is there a slicker way?

Robert Mash

this is a resend

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2003\09\18@130453 by Olin Lathrop

face picon face
> Is there a way to do an n sample moving average without storing n
> samples?

No.

> I want to do a 20 sample moving average.  Do I need to set aside 20
> locations/variables for this task?

Yes.

> Is there a slicker way?

Probably, depending on your application.  It depends on why you want to
perform this "average".  If it is to reduce random noise there are
definitely better ways.

This has been discussed many times in depth.  See the archives.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu

2003\09\19@161017 by John N. Power

flavicon
face
> From:         Robert Mash[SMTP:rmashspamKILLspamGLOBALCOOLING.COM]
> Sent:         Thursday, September 18, 2003 12:21 PM
> To:   .....PICLISTKILLspamspam.....MITVMA.MIT.EDU
> Subject:      [PIC:] moving average filter

> Is there a way to do an n sample moving average without storing n samples?
> I want to do a 20 sample moving average.  Do I need to set aside 20 locations/variables for this task?
> Is there a slicker way?

>Robert Mash

     That depends on how closely you want to approximate the standard "mean" average. If you want
     a conventional "boxcar" integration, you must retain all 20 previous values so that you can
     subtract them one at a time in order as new terms are added. (The name "boxcar" comes from
     the rectangular shape of the window function that results from adding each term with an equal
     weighting factor.)

     If you are willing to implement an exponential filter (exactly analogous to an RC hardware filter),
     you can do much better. From Z transform theory, a one stage recursive filter can be modelled
     as
     y(n) = x(n) + alpha * y(n-1)
     y(n) is the current output, x(n) is the current input, y(n-1) is the previous output, and alpha is a
     constant that sets the time interval over which the filter "remembers" the input. If I figured this
     right, alpha = exp( - T / tau ) where T is the time interval between samples and tau is the effective
     time constant desired. Rescaling will be needed to find a relationship between tau and "20" (or
     whatever number is needed). This type of filter discounts earlier samples as time goes by, as
     opposed to the "mean (boxcar)" filter which treats all values equally right up until they drop out.

There are several limitations to this filter.
1. It requires floating point.
2. Either alpha must be precomputed, or the exponential function must be available at run time.

     John Power

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\09\20@125352 by Olin Lathrop

face picon face
John N. Power wrote:
>       If you are willing to implement an exponential filter (exactly
>       analogous to an RC hardware filter), you can do much better. From Z
>       transform theory, a one stage recursive filter can be modelled as
>       y(n) = x(n) + alpha * y(n-1)

This definitely does NOT model an RC filter.  For one thing, note that this
is an infinitely increasing series even with a constant input and an ALPHA
greater than 0.  It performs no useful "filtering" function that I can think
of.

As has been discussed many times here before, the right way to model an RC
filter is:

 FILT <-- FILT + ALPHA * (NEW - FILT)

See the archives for many detailed discussions.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\09\21@171948 by John N. Power

flavicon
face
>> Is there a way to do an n sample moving average without storing n samples?
>> I want to do a 20 sample moving average.  Do I need to set aside 20 locations/variables for this task?
>> Is there a slicker way?

>>Robert Mash

 >    If you are willing to implement an exponential filter (exactly analogous to an RC hardware filter),
 >    you can do much better. From Z transform theory, a one stage recursive filter can be modelled
 >    as
 >    y(n) = x(n) + alpha * y(n-1)

  I think I made a mistake in the normalization of this formula. It should be
       y(n) = (1 - alpha) * x(n) + alpha * y(n-1)

 John Power

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\09\21@180840 by Olin Lathrop
face picon face
John N. Power wrote:
> I think I made a mistake in the normalization of this formula. It
> should be y(n) = (1 - alpha) * x(n) + alpha * y(n-1)

Yes this correctly models a simple R/C filter, although it's generally not
the way you'd want to implement such a filter on a PIC.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


'[PIC:] moving average filter'
2003\10\16@145634 by Olin Lathrop
face picon face
plee (EraseMEpaul66spam_OUTspamTakeThisOuTprimus.ca) wrote:
> saw your post.
>
> I need to design reading of ADXL202 g sensor.
> As you surely know it has big noisy and a filter, or
> an running avery is critical.
>
> I didn't find the explaination about your equation.
> PICLIST is down.
>
> Could you help to find detail to decide the factor?
>
> Paul

There is no reason this needed to be a private message to me.  The PICLIST
is never down long.  I just fetched messages and the activity look fairly
continuous since the last time I fetched.  The longest gap between
messages was only 40 minutes.

As for the filter, what detail, what factor?


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...