TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
MovingAverage< N > Class Template Reference

Computes the moving average of a sequence of values. More...

#include <MovingAverage.h>

Public Member Functions

 MovingAverage (size_t size)
 
void addMeasurement (N value)
 
float calculate ()
 
void setSize (size_t size)
 Defines the number of values.
 

Protected Attributes

std::list< N > values
 
size_t size = 0
 

Detailed Description

template<class N = float>
class tinyrobotics::MovingAverage< N >

Computes the moving average of a sequence of values.

This template class maintains a fixed-size window of the most recent values and efficiently computes their arithmetic mean. It is useful for smoothing noisy sensor data, filtering out short-term fluctuations, and providing a simple low-pass filter in embedded and robotics applications.

Features

Usage Example

MovingAverage<float> avg(5); // 5-sample moving average
avg.addMeasurement(1.0f);
avg.addMeasurement(2.0f);
float mean = avg.calculate();
Computes the moving average of a sequence of values.
Definition: MovingAverage.h:36
Template Parameters
NNumeric type of the values (e.g., float, int)
Author
Phil Schatzmann

The documentation for this class was generated from the following file: