arthur.hauer
Member
Hi!
Currently I'm trying to implement an average calculator in a S5-95U.
In order to do the job, I'm using the folowing equation:
M(k) = M(k-1)*((k-1)/k) + V(k)/k
Where k is the sample index, M(k) is the average value for sample k and V(k) is the value of interest for sample k.
I got to this equation after contemplating the overflow problem that would be caused by simple average equation:
(V(k)+V(k-1)+...V(k-n))/k
Because this code will run for a long time, the sample count will eventually overflow.
I think calling this function periodically should do the trick. The question is: How to do this? Is there a better way to calculate the average value?
Att.,
Arthur
Post Scriptum: Sorry for bad english
Currently I'm trying to implement an average calculator in a S5-95U.
In order to do the job, I'm using the folowing equation:
M(k) = M(k-1)*((k-1)/k) + V(k)/k
Where k is the sample index, M(k) is the average value for sample k and V(k) is the value of interest for sample k.
I got to this equation after contemplating the overflow problem that would be caused by simple average equation:
(V(k)+V(k-1)+...V(k-n))/k
Because this code will run for a long time, the sample count will eventually overflow.
I think calling this function periodically should do the trick. The question is: How to do this? Is there a better way to calculate the average value?
Att.,
Arthur
Post Scriptum: Sorry for bad english