mc_filter::ExponentialMovingAverage< VectorT > Struct Template Reference

#include <mc_filter/ExponentialMovingAverage.h>

Public Member Functions

 ExponentialMovingAverage (double dt, double timeConstant, const VectorT &initValue=VectorT::Zero())
 
void append (const VectorT &value)
 
const VectorT & eval () const
 
void saturation (double limit)
 
void reset (const VectorT &initVal)
 
double timeConstant () const
 
void timeConstant (double T)
 

Protected Attributes

VectorT average_ = VectorT::Zero()
 
double alpha_
 
double dt_
 
double timeConstant_
 
double saturation_ = -1.
 

Detailed Description

template<typename VectorT>
struct mc_filter::ExponentialMovingAverage< VectorT >

Exponential Moving Average.

This filter can be seen as an integrator:

\[ y(t) = \frac{1}{T} \int_{u=0}^t x(u) e^{(u - 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 (~63%) of the original signal.

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

Expects type VectorT to have:

  • VectorT::Zero() static function
  • VectorT::setZero() Common types: Eigen::Vector3d, Eigen::Vector6d, etc.

Constructor & Destructor Documentation

◆ ExponentialMovingAverage()

template<typename VectorT >
mc_filter::ExponentialMovingAverage< VectorT >::ExponentialMovingAverage ( double  dt,
double  timeConstant,
const VectorT &  initValue = VectorT::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.

Member Function Documentation

◆ append()

template<typename VectorT >
void mc_filter::ExponentialMovingAverage< VectorT >::append ( const VectorT &  value)
inline

Append a new reading to the series.

Parameters
valueNew value.

◆ eval()

template<typename VectorT >
const VectorT& mc_filter::ExponentialMovingAverage< VectorT >::eval ( ) const
inline

Evaluate the smoothed statistic.

◆ reset()

template<typename VectorT >
void mc_filter::ExponentialMovingAverage< VectorT >::reset ( const VectorT &  initVal)
inline

Reset average to provided value.

Parameters
initValinitial value of the average

◆ saturation()

template<typename VectorT >
void mc_filter::ExponentialMovingAverage< VectorT >::saturation ( double  limit)
inline

Set output saturation; disable by providing a negative value.

Parameters
limitOutput will saturate between -limit and +limit.

◆ timeConstant() [1/2]

template<typename VectorT >
double mc_filter::ExponentialMovingAverage< VectorT >::timeConstant ( ) const
inline

Get time constant of the filter.

◆ timeConstant() [2/2]

template<typename VectorT >
void mc_filter::ExponentialMovingAverage< VectorT >::timeConstant ( double  T)
inline

Update time constant.

Parameters
TNew time constant of the filter.
Note
T is explicitely enforced to respect the Nyquist–Shannon sampling theorem, that is T is at least 2*timestep.

Member Data Documentation

◆ alpha_

template<typename VectorT >
double mc_filter::ExponentialMovingAverage< VectorT >::alpha_
protected

◆ average_

template<typename VectorT >
VectorT mc_filter::ExponentialMovingAverage< VectorT >::average_ = VectorT::Zero()
protected

◆ dt_

template<typename VectorT >
double mc_filter::ExponentialMovingAverage< VectorT >::dt_
protected

◆ saturation_

template<typename VectorT >
double mc_filter::ExponentialMovingAverage< VectorT >::saturation_ = -1.
protected

◆ timeConstant_

template<typename VectorT >
double mc_filter::ExponentialMovingAverage< VectorT >::timeConstant_
protected

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