Simple round robin (moving average) array in C#
The easiest option for this is probably to use a Queue<T>
, as this provides the first-in, first-out behavior you're after. Just Enqueue() your items, and when you have more than X items, Dequeue() the extra item(s).
Possibly use a filter:
average = 0.9*average + 0.1*value where 'value' is the most recent measurement
Vary with the 0.9 and 0.1 (as long as the sum of these two is 1)
This is not exactly an average, but it does filter out spikes, transients, etc, but does not require arrays for storage.
Greetings, Karel