utils::ExponentialMovingAverage Struct Reference

Exponential Moving Average. More...

#include <lipm_walking/utils/ExponentialMovingAverage.h>

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW ExponentialMovingAverage (double dt, double timeConstant, const Eigen::Vector3d &initValue=Eigen::Vector3d::Zero())
 Constructor. More...
 
void append (const Eigen::Vector3d &value)
 Append a new reading to the series. More...
 
const Eigen::Vector3d & eval () const
 Evaluate the smoothed statistic. More...
 
const Eigen::Vector3d & raw () const
 Last raw value provided to the integrator. More...
 
void reset ()
 Reset average to zero. More...
 
void saturation (double limit)
 Set output saturation; disable by providing a negative value. More...
 
void setZero ()
 Reset average to zero. More...
 
double timeConstant () const
 Get time constant of the filter. More...
 
void timeConstant (double T)
 Update time constant. More...
 

Protected Attributes

Eigen::Vector3d average_ = Eigen::Vector3d::Zero()
 
Eigen::Vector3d rawValue_ = Eigen::Vector3d::Zero()
 
double alpha_
 
double dt_
 
double saturation_ = -1.
 
double timeConstant_
 

Detailed Description

Exponential Moving Average.

This filter can be seen as an integrator:

\[ y(t) = \frac{1}{T} \int_{\tau=0}^t x(\tau) e^{(\tau - t) / T} {\rm d}{\tau} \]

with \(T > 0\) a reset period acting as anti-windup. It can also (informally) be interpreted as the average value of the input signal \(x(t)\) over the last \(T\) seconds. Formally, it represents the amount of time for the smoothed response of a unit input to reach \(1-1/e \ (\approx 63\%)\) of the original signal.

See https://en.wikipedia.org/wiki/Exponential_smoothing. It is equivalent to a low-pass filter applied to the integral of the input signal.

Definition at line 56 of file ExponentialMovingAverage.h.

Constructor & Destructor Documentation

EIGEN_MAKE_ALIGNED_OPERATOR_NEW utils::ExponentialMovingAverage::ExponentialMovingAverage ( double  dt,
double  timeConstant,
const Eigen::Vector3d &  initValue = Eigen::Vector3d::Zero() 
)
inline

Constructor.

Parameters
dtTime in [s] between two readings.
timeConstantInformally, length of the recent-past window, in [s].
initValueInitial value of the output average.

Definition at line 69 of file ExponentialMovingAverage.h.

Member Function Documentation

void utils::ExponentialMovingAverage::append ( const Eigen::Vector3d &  value)
inline

Append a new reading to the series.

Parameters
valueNew value.

Definition at line 82 of file ExponentialMovingAverage.h.

const Eigen::Vector3d& utils::ExponentialMovingAverage::eval ( ) const
inline

Evaluate the smoothed statistic.

Definition at line 95 of file ExponentialMovingAverage.h.

const Eigen::Vector3d& utils::ExponentialMovingAverage::raw ( ) const
inline

Last raw value provided to the integrator.

Definition at line 103 of file ExponentialMovingAverage.h.

void utils::ExponentialMovingAverage::reset ( )
inline

Reset average to zero.

Definition at line 111 of file ExponentialMovingAverage.h.

void utils::ExponentialMovingAverage::saturation ( double  limit)
inline

Set output saturation; disable by providing a negative value.

Parameters
limitOutput will saturate between -limit and +limit.

Definition at line 121 of file ExponentialMovingAverage.h.

void utils::ExponentialMovingAverage::setZero ( )
inline

Reset average to zero.

Definition at line 129 of file ExponentialMovingAverage.h.

double utils::ExponentialMovingAverage::timeConstant ( ) const
inline

Get time constant of the filter.

Definition at line 137 of file ExponentialMovingAverage.h.

void utils::ExponentialMovingAverage::timeConstant ( double  T)
inline

Update time constant.

Parameters
TNew time constant of the filter.

Definition at line 147 of file ExponentialMovingAverage.h.

Member Data Documentation

double utils::ExponentialMovingAverage::alpha_
protected

Definition at line 176 of file ExponentialMovingAverage.h.

Eigen::Vector3d utils::ExponentialMovingAverage::average_ = Eigen::Vector3d::Zero()
protected

Definition at line 174 of file ExponentialMovingAverage.h.

double utils::ExponentialMovingAverage::dt_
protected

Definition at line 177 of file ExponentialMovingAverage.h.

Eigen::Vector3d utils::ExponentialMovingAverage::rawValue_ = Eigen::Vector3d::Zero()
protected

Definition at line 175 of file ExponentialMovingAverage.h.

double utils::ExponentialMovingAverage::saturation_ = -1.
protected

Definition at line 178 of file ExponentialMovingAverage.h.

double utils::ExponentialMovingAverage::timeConstant_
protected

Definition at line 179 of file ExponentialMovingAverage.h.