Round Memory Averaging for Realtime Datasampling and processing
- Initialize memory space by:
RoundMemory<float> sensorReadings = RoundMemory<float>(100, 0);
- Append new sensor readings to memory space using:
sensorReadings.append( sensor.getReading() ); // replace argument with new reading to append.
- Use avg() to get the average of the samples of last 'size' readings.
Serial.println( sensorReadings.avg() ); // returns average of readings.
- RoundMemory.append() function returns the change in average before appending and after appending.
float delta = sensorReadings.append( sensor.getReading() );
// is the same as:
float u = sensorReadings.avg();
sensorReadings.append( sensor.getReading() );
float delta = u - sensorReadings.avg();
4 + (size * sizeof(datatype T)). increases linearly as size is higher. Higher the size, more cpu cycles will be used to perform avg();
Use conservative-branch for low memory application, and for much higher performance.