3-phase PV router
Loading...
Searching...
No Matches
EWMA_average< A > Class Template Reference

Implements an Exponentially Weighted Moving Average (EWMA). More...

#include <ewma_avg.hpp>

Inheritance diagram for EWMA_average< A >:

Public Member Functions

void addValue (int32_t input)
 Add a new value and update the EMA, DEMA, and TEMA.
 
auto getAverageD () const
 Get the Double Exponentially Weighted Moving Average (DEMA).
 
auto getAverageS () const
 Get the Exponentially Weighted Moving Average (EMA).
 
auto getAverageT () const
 Get the Triple Exponentially Weighted Moving Average (TEMA).
 

Private Attributes

int32_t ema { 0 }
 
int32_t ema_ema { 0 }
 
int32_t ema_ema_ema { 0 }
 
int32_t ema_ema_ema_raw { 0 }
 
int32_t ema_ema_raw { 0 }
 
int32_t ema_raw { 0 }
 

Detailed Description

template<uint8_t A = 10>
class EWMA_average< A >

Implements an Exponentially Weighted Moving Average (EWMA).

The EWMA_average class calculates the Exponentially Weighted Moving Average (EMA), Double EMA (DEMA), and Triple EMA (TEMA) for a given input series. It uses integer math for efficiency, making it suitable for systems with limited computational power.

Template Parameters
AThe smoothing factor, which determines the weight of recent values in the average.
  • The smoothing factor is rounded to the nearest power of 2 for faster integer calculations.
  • EMA provides a smoothed average of the input series.
  • DEMA and TEMA offer improved responsiveness, especially for peak inputs.
  • The class is optimized for use in embedded systems like Arduino.

Definition at line 79 of file ewma_avg.hpp.

Member Function Documentation

◆ addValue()

template<uint8_t A = 10>
void EWMA_average< A >::addValue ( int32_t input)
inline

Add a new value and update the EMA, DEMA, and TEMA.

This method processes a new input value and updates the Exponentially Weighted Moving Average (EMA), Double EMA (DEMA), and Triple EMA (TEMA).

Parameters
inputThe new input value to process.

Definition at line 90 of file ewma_avg.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAverageD()

template<uint8_t A = 10>
auto EWMA_average< A >::getAverageD ( ) const
inline

Get the Double Exponentially Weighted Moving Average (DEMA).

Returns
auto The DEMA value.

Definition at line 117 of file ewma_avg.hpp.

Here is the caller graph for this function:

◆ getAverageS()

template<uint8_t A = 10>
auto EWMA_average< A >::getAverageS ( ) const
inline

Get the Exponentially Weighted Moving Average (EMA).

Returns
auto The EMA value.

Definition at line 107 of file ewma_avg.hpp.

Here is the caller graph for this function:

◆ getAverageT()

template<uint8_t A = 10>
auto EWMA_average< A >::getAverageT ( ) const
inline

Get the Triple Exponentially Weighted Moving Average (TEMA).

Returns
auto The TEMA value.

Definition at line 127 of file ewma_avg.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ ema

template<uint8_t A = 10>
int32_t EWMA_average< A >::ema { 0 }
private

EMA value.

Definition at line 138 of file ewma_avg.hpp.

◆ ema_ema

template<uint8_t A = 10>
int32_t EWMA_average< A >::ema_ema { 0 }
private

DEMA value.

Definition at line 136 of file ewma_avg.hpp.

◆ ema_ema_ema

template<uint8_t A = 10>
int32_t EWMA_average< A >::ema_ema_ema { 0 }
private

TEMA value.

Definition at line 134 of file ewma_avg.hpp.

◆ ema_ema_ema_raw

template<uint8_t A = 10>
int32_t EWMA_average< A >::ema_ema_ema_raw { 0 }
private

Raw value for TEMA calculation.

Definition at line 133 of file ewma_avg.hpp.

◆ ema_ema_raw

template<uint8_t A = 10>
int32_t EWMA_average< A >::ema_ema_raw { 0 }
private

Raw value for DEMA calculation.

Definition at line 135 of file ewma_avg.hpp.

◆ ema_raw

template<uint8_t A = 10>
int32_t EWMA_average< A >::ema_raw { 0 }
private

Raw value for EMA calculation.

Definition at line 137 of file ewma_avg.hpp.


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