ph_runavg PowerHome formula function
Description
Performs a running average calculation on the supplied data 
Syntax
ph_runavg ( ad_avg, ad_newdata, al_samplecnt )
Argument Description
ad_avg Double. The current running average value from previous executions of this function. If this is the first sample for the running average, set this value the same as ad_newdata so the returned result won't be skewed
ad_newdata Double. This is the new value to be figured into the running average
al_samplecnt Long. This is the number of samples to keep in the running average. You should use a value > 1 otherwise the function will do nothing other than to return the supplied ad_newdata value
Return value
Double. Returns the running average based upon the supplied parameters 
Usage
Use this formula to perform running averages on values. Very useful for averaging data such as temperatures over multiple samples to smooth false readings. This is the same function that is used by the Analog I/O screens running average column. 

This function uses the following formula to calculate a running average:
If the al_samplecnt parameter is < 1, then the return value will be ad_newdata. Any other sample count value will result in returning a value based upon the following formula: ad_avg - ad_avg / al_samplecnt + ad_newdata / al_samplecnt< /p >

Examples
The following examples demonstrate typical syntax/usage for this function.
• ph_runavg(75.0,76.3,5) - Returns a value of 75.26. The ad_avg value of 75.0 is the current running average. The ad_newdata value is the new value to be calculated into the running average. The al_samplecnt value of 5 signifies that the running average is calculated over the last 5 samples