08-12-2009 09:52 AM
Hi. I'm looking for an array exponential averaging function in MS 8.1 enterprise and it looks to me like nothing exists.
I need to have a "running" average of autospectrum data. I've built a function that uses a collection to do a simple running average but an exponential running average would be prefered.
thanks
Bob
08-13-2009 05:13 PM
Hi Bob,
Your searching is correct; there is not an exponential moving average function in Measurement Studio. Here's some example C-code for an exponential average (aka, exponentially weighted average). You'll need to modify it a little to get it to be a moving average, but hopefully this will get you started:
#include <ansi_c.h> int main (int argc, char *argv[]) { double data[20] = {99, 50, 24, 50, 22, 48, 89, 10, 8, 45, 22, 6, 99, 99, 99, 99, 99, 99, 99, 99}; double ex_data[20]; int i; double multiplier, sum = 0.0, ex_avg = 0; int size = sizeof(data)/sizeof(data[0]); double f = 1.0 - 2.0/(20.0/2.8854); for (i = 0; i < size; i++) { multiplier = (1 - f) * pow(f,i); sum += multiplier; ex_avg += data[i] * multiplier; ex_data[i] = data[i] * multiplier; } printf ("sum (Should approach 1) = %f\naverage = %f", sum, ex_avg); getchar (); return 0; }