Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Data Smoothing (http://www.chiefdelphi.com/forums/showthread.php?t=61623)

Lafleur 13-01-2008 22:36

Data Smoothing
 
Here is a bit of code to use the Exponential moving average (EMA) function for data smoothing. I find it much superior to that of a straight average because it favors newer samples, making it more responsive. Also it requires one to save only one value between calculations.

To use, call the EMAweight function with the number of samples that you want to smoothing over, it will calculate a weight factor for the EMA function.

call EMA with the oldvalue, newsample and the weight

here is a reference for EMA:

http://www.esignal.com/futuresource/...tudies/emi.htm
Quote:

//prototypes

float EMA (int, int, float );
float EMAweight (float);

// how to use

w = EMAweight (30.0); // set weight
xEMA = EMA( xEMA, newsample, w); // old, new, weight


//
// Ema routines
//
float EMAweight (float samples)
{
return (2.0 / ( 1.0 + samples));
}

float EMA (int prevEMA, int newVALUE, float weightx)
{
return ((weightx * (newVALUE - prevEMA)) + prevEMA);
}


kaszeta 14-01-2008 10:17

Re: Data Smoothing
 
Quote:

Originally Posted by Lafleur (Post 677327)
Here is a bit of code to use the Exponential moving average (EMA) function for data smoothing.

Nice. We've stuck with arithmetic moving averages in the past since they are fast and can be implemented in pure integer math, but it's nice to see someone using this and posting sample code.

Lafleur 14-01-2008 13:08

Re: Data Smoothing
 
You can use this with integer math with changes to the math lib.... or use scaling on the weight ratio and final EMA

Jared Russell 14-01-2008 22:06

Re: Data Smoothing
 
Second (and higher) order IIR low pass filters have responses similar to this one.


All times are GMT -5. The time now is 23:15.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi