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.
 
void addValue (int32_t input)
 
void addValue (int32_t input)
 
auto getAverageD () const
 Get the Double Exponentially Weighted Moving Average (DEMA).
 
auto getAverageD () const
 
auto getAverageD () const
 
auto getAverageS () const
 Get the Exponentially Weighted Moving Average (EMA).
 
auto getAverageS () const
 
auto getAverageS () const
 
auto getAverageT () const
 Get the Triple Exponentially Weighted Moving Average (TEMA).
 
auto getAverageT () const
 
auto getAverageT () const
 
void reset ()
 
void reset ()
 

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.

Cloud Immunity Tuning

For PV router applications, cloud immunity is crucial to prevent relay chattering:

TEMA (getAverageT()) is recommended for relay control as it provides:

  • Best immunity to brief cloud shadows (5-60 seconds)
  • Good responsiveness to genuine load changes
  • Optimal balance for most installations

Filter Comparison:

  • EMA (getAverageS()): Basic smoothing, most responsive, least cloud immunity
  • DEMA (getAverageD()): Better cloud immunity, good responsiveness
  • TEMA (getAverageT()): Best cloud immunity, excellent responsiveness to real changes

Tuning Guidelines:

  • Template parameter A should be: delay_minutes * 60 / sample_period_seconds
  • For 5-second sampling: A = delay_minutes * 12
  • Recommended delays: 1-3 minutes for most installations

Definition at line 107 of file ewma_avg.hpp.

Member Function Documentation

◆ addValue() [1/3]

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 118 of file ewma_avg.hpp.

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

◆ addValue() [2/3]

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

Definition at line 37 of file test_main.cpp.

Here is the call graph for this function:

◆ addValue() [3/3]

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

Definition at line 38 of file test_main.cpp.

Here is the call graph for this function:

◆ getAverageD() [1/3]

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 145 of file ewma_avg.hpp.

Here is the caller graph for this function:

◆ getAverageD() [2/3]

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

Definition at line 53 of file test_main.cpp.

◆ getAverageD() [3/3]

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

Definition at line 54 of file test_main.cpp.

◆ getAverageS() [1/3]

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 135 of file ewma_avg.hpp.

Here is the caller graph for this function:

◆ getAverageS() [2/3]

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

Definition at line 49 of file test_main.cpp.

◆ getAverageS() [3/3]

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

Definition at line 50 of file test_main.cpp.

◆ getAverageT() [1/3]

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 155 of file ewma_avg.hpp.

Here is the caller graph for this function:

◆ getAverageT() [2/3]

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

Definition at line 57 of file test_main.cpp.

◆ getAverageT() [3/3]

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

Definition at line 58 of file test_main.cpp.

◆ reset() [1/2]

template<uint8_t A = 10>
void EWMA_average< A >::reset ( )
inline

Definition at line 62 of file test_main.cpp.

◆ reset() [2/2]

template<uint8_t A = 10>
void EWMA_average< A >::reset ( )
inline

Definition at line 63 of file test_main.cpp.

Member Data Documentation

◆ ema

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

EMA value.

Definition at line 166 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 164 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 162 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 161 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 163 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 165 of file ewma_avg.hpp.


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