I'm trying to add a running average on a PICAXE 28X1. I have two options:
1) Keep track of the average (A) and number of data points (N), or
2) Keep track of the number of data points and a running total (T).
With either option, I can end up with an overflow error (i.e $FFFF goes to $0000). I need 32 bit math on a PICAXE .
With option 1), the running average is:
A = (A*N + x)/(N + 1)
where x is a the new data point. For Option 2) the running average is:
A = (T + x)/(N + 1)
With either option, the number of data points becomes:
N = N + 1
I like option 2 because it avoids a multiplication (i.e. A*N).
1) Keep track of the average (A) and number of data points (N), or
2) Keep track of the number of data points and a running total (T).
With either option, I can end up with an overflow error (i.e $FFFF goes to $0000). I need 32 bit math on a PICAXE .
With option 1), the running average is:
A = (A*N + x)/(N + 1)
where x is a the new data point. For Option 2) the running average is:
A = (T + x)/(N + 1)
With either option, the number of data points becomes:
N = N + 1
I like option 2 because it avoids a multiplication (i.e. A*N).