I've used this before, but just can't remember it, and can't find it anywhere.
It's a running average where the newest value has twice the weight of all the previous values (combined), so that as time passes the oldest values have less and less effect. And I don't have enough memory to store the older values.
TO GET AVERAGE:
int sum=0;
int n = 0;
float aver = 0;
for(;;){
float new_value = some_function();
sum += new_value;
++n;
aver = sum / n;
}
But how to I get an average where the new_value is weighted to be twice the weighting of the previous average?
float aver = 0;
for(;;){
float new_value = some_function();
aver = aver * ??? + new_value * ???;
}
Compute the special average on the sum and the latest.