Omar Mussa Posted August 21, 2007 Report Share Posted August 21, 2007 I was recently trying to compare a few ways of calculating a running average. I was surprised that the point-by-point mean was not the same as a 'traditional' mean value. The values are only off at the 10^-15 range which makes me assume that it is a floating point value problem (and makes me feel like I don't need to spend too much time working on it) but I am still surprised that there is a difference at all (especially after the first 4 iterations in my running average (which uses a 4 point buffer). Please look at my demo VI and see if there is any other explanation. (The VI is in 8.2.1). Thanks in advance! Quote Link to comment

B Chavez Posted August 21, 2007 Report Share Posted August 21, 2007 QUOTE(Omar Mussa @ Aug 20 2007, 11:41 AM) I was recently trying to compare a few ways of calculating a running average. I was surprised that the point-by-point mean was not the same as a 'traditional' mean value. The values are only off at the 10^-15 range which makes me assume that it is a floating point value problem (and makes me feel like I don't need to spend too much time working on it) but I am still surprised that there is a difference at all (especially after the first 4 iterations in my running average (which uses a 4 point buffer).Please look at my demo VI and see if there is any other explanation. (The VI is in 8.2.1). Thanks in advance! Even more concerning is that if you lower the millisecond delay to zero and let it run for a little bit, the Mean values 'go out of tolerance'. It looks like the point-by-point mean keeps an array of x values and a running sum. The problem is that it adds the new value to the sum and subtracts the oldest value from the sum, resulting in some rounding errors that accumulate over time. What you end up with is a sum that does not exactly equal the sum of the 4 values. Quote Link to comment

Omar Mussa Posted August 21, 2007 Author Report Share Posted August 21, 2007 QUOTE(B Chavez @ Aug 20 2007, 12:31 PM) Even more concerning is that if you lower the millisecond delay to zero and let it run for a little bit, the Mean values 'go out of tolerance'. It looks like the point-by-point mean keeps an array of x values and a running sum. The problem is that it adds the new value to the sum and subtracts the oldest value from the sum, resulting in some rounding errors that accumulate over time. What you end up with is a sum that does not exactly equal the sum of the 4 values. I hadn't tried running with a 0 delay... When I did I found that the values are within 10^-13 of each other. Still close enough for me not to care, but you are right about the cumulative effects of add/subtract in ther pop on/off mechanism. I think that additionally, the difference between the values would increase the larger the buffer size you elected to use. Quote Link to comment

Ton Plomp Posted August 22, 2007 Report Share Posted August 22, 2007 QUOTE(B Chavez @ Aug 20 2007, 09:31 PM) Even more concerning is that if you lower the millisecond delay to zero and let it run for a little bit, the Mean values 'go out of tolerance'. It looks like the point-by-point mean keeps an array of x values and a running sum. The problem is that it adds the new value to the sum and subtracts the oldest value from the sum, resulting in some rounding errors that accumulate over time. What you end up with is a sum that does not exactly equal the sum of the 4 values. You can open most of the point-by-point VIs. [out of my memory mode] If I recall correctly the Mean pbp.vi uses two methods, one for a fixed number of points and one for infinity. The fixed number of points uses an array that is shifted. Their is some input checking for NaN, +infinity and -infinity. Also remember that the running average is different than the arithmic mean! WikiPedia links: average Moving average [/out of my memory mode] Ton Quote Link to comment

torekp Posted August 22, 2007 Report Share Posted August 22, 2007 QUOTE(tcplomp @ Aug 21 2007, 04:33 AM) WikiPedia links: May I suggest another extremely useful moving average, the exponentially weighted moving average: http://en.wikipedia.org/wiki/Exponential_smoothing''>http://en.wikipedia.org/wiki/Exponential_smoothing' target="_blank">http://en.wikipedia.org/wiki/Exponential_smoothing Easy on the processor and on the memory. Quote Link to comment

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.