On Jan 15, 2009, at 10:25 AM, wagnerj@proaxis.com wrote: > Heard that this is a common technique. > > Mean of N samples is (1/N) sum(Xi) where Xi is one of the samples > X0, X1, > ... XN-1 > > Now if you are doing a total mean rather than a windowed mean (most > recent > N samples), then the new mean value is > > Mean = (N*MeanPrevious + Xnew)/(N+1) I'd keep a what I'd claim to be the Sum of X samples laying around. Then I would say that Sum(N) = Sum(N-1) - Mean(N-1) + Sample(N); and then Mean(N) = Sum(N) / X. If you kept a history of X samples then you could keep a running sum subtracting the old out and adding the new in. But without a history to draw on you could subtract out the previous average as a good approximation before adding the new. The difference between what I suggest and what you proposed is that I wouldn't multiply the old mean by the number of samples, I'd keep the raw sum laying around as it has a tad more precision and this skips a multiply step. Make sure that the precision of Sum is great enough to hold X Samples at max values. When using integer math you might consider adding 0.5X to Sum before dividing by X so that it rounds "normally". -- David Kelly N4HHE, dkelly@HiWAAY.net ======================================================================== Whom computers would destroy, they must first drive mad.
Message
Re: [AVR-Chat] GMM
2009-01-15 by David Kelly
Attachments
- No local attachments were found for this message.