-1

I am writing a function in C++ to calculate the moving average of a data stream. I want to use incremental averaging . As am implementing this on a relatively weak microprocessor I want to perform a moving average. That is, I want to perform an incremental average over the last X values (X ~ 100).

As I understand it, incremental averaging requires all data to be averaged and does not support a moving window.

Does anyone know a good way to calculate the "moving" incremental average?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
GammaRui
  • 21
  • 2

1 Answers1

1

If A(i, n) is the average over the n elements x_i, ..., x_(i + n - 1), then A(i + 1, n) = A(i, n) + (x_(i +n) - x_i) / n.

Pharap
  • 3,826
  • 5
  • 37
  • 51
wonce
  • 1,893
  • 12
  • 18