3-phase PV router
Loading...
Searching...
No Matches
Classes | Functions
ewma_avg.hpp File Reference

This file implements an Exponentially Weighted Moving Average template class. More...

#include <Arduino.h>
#include "type_traits.hpp"
Include dependency graph for ewma_avg.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  EWMA_average< A >
 Exponentially Weighted Moving Average. More...
 

Functions

constexpr uint8_t round_up_to_power_of_2 (uint16_t v)
 Helper compile-time function to retrieve the previous power of 2 of the given number (120 => 64 => 6)
 

Detailed Description

This file implements an Exponentially Weighted Moving Average template class.

Author
Frédéric Metrich (frede.nosp@m.ric..nosp@m.metri.nosp@m.ch@l.nosp@m.ive.f.nosp@m.r)
Version
0.1
Date
2024-02-27

Description

The Exponentially Weighted Moving Average (EWMA) is a quantitative or statistical measure used to model or describe a time series. The EWMA is widely used in finance, the main applications being technical analysis and volatility modeling.

The moving average is designed as such that older observations are given lower weights. The weights fall exponentially as the data point gets older – hence the name exponentially weighted.

The only decision a user of the EWMA must make is the parameter alpha. The parameter decides how important the current observation is in the calculation of the EWMA. The higher the value of alpha, the more closely the EWMA tracks the original time series.

Computation of DEMA (Double EMA) with half-alpha has been added to get a better response of the average, especially when "peak inputs" are recorded.

Computation of TEMA (Triple EMA) with quarter-alpha has been added to get a even better response of the average, especially when "peak inputs" are recorded. This seems to be the "optimal" solution.

Note

This class is implemented in way to use only integer math. This comes with some restrictions on the alpha parameter, but the benefit of full integer math wins on the side-drawback.

Definition in file ewma_avg.hpp.

Function Documentation

◆ round_up_to_power_of_2()

constexpr uint8_t round_up_to_power_of_2 ( uint16_t  v)
constexpr

Helper compile-time function to retrieve the previous power of 2 of the given number (120 => 64 => 6)

Parameters
vThe input number
Returns
constexpr uint8_t The next power of two

Definition at line 47 of file ewma_avg.hpp.

Here is the caller graph for this function: