All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::MovingAverage< T > Class Template Reference

This class provides an implementation for calculating a moving average with a fixed window. More...

#include <Radiant/MovingAverage.hpp>

Public Member Functions

void add (const T &t, Radiant::TimeStamp ts=Radiant::TimeStamp::currentTime())
 Add a sample with the given timestamp to the buffer. More...
 
avg (Radiant::TimeStamp ts=Radiant::TimeStamp::currentTime()) const
 Compute the average of the history values before given timestamp. More...
 
void forget (int number)
 Forget samples. More...
 
 MovingAverage (const T &t, double history)
 Construct a new buffer. More...
 
operator* () const
 Implicit conversion to value-type. More...
 
void set (const T &t)
 Sets the average of the buffer to given value. More...
 

Detailed Description

template<typename T>
class Radiant::MovingAverage< T >

This class provides an implementation for calculating a moving average with a fixed window.

Constructor & Destructor Documentation

template<typename T >
Radiant::MovingAverage< T >::MovingAverage ( const T &  t,
double  history 
)
inline

Construct a new buffer.

Parameters
tinitial value
historyhistory length in seconds

Member Function Documentation

template<typename T >
void Radiant::MovingAverage< T >::add ( const T &  t,
Radiant::TimeStamp  ts = Radiant::TimeStamp::currentTime() 
)
inline

Add a sample with the given timestamp to the buffer.

Parameters
tsample value
tstimestamp of the value
template<typename T >
T Radiant::MovingAverage< T >::avg ( Radiant::TimeStamp  ts = Radiant::TimeStamp::currentTime()) const
inline

Compute the average of the history values before given timestamp.

Parameters
tstime limit
Returns
average
template<typename T >
void Radiant::MovingAverage< T >::forget ( int  number)
inline

Forget samples.

Parameters
numberof samples to forget from the end of the buffer
template<typename T >
T Radiant::MovingAverage< T >::operator* ( ) const
inline

Implicit conversion to value-type.

Returns
average of all samples in the buffer
template<typename T >
void Radiant::MovingAverage< T >::set ( const T &  t)
inline

Sets the average of the buffer to given value.

Parameters
tnew buffer average