ESP-LiveControl  1.99.1
HTTP server, AJAX API backend and Vue.js web application implementing self-contained, zero-install WiFi remote control of hardware modules attached to the Espressif ESP32 SoC
Public Member Functions | Protected Attributes | List of all members
MovingAverageUInt16< N > Class Template Reference

Does a recursive moving average over N values. More...

#include <adc_filter_interpolation.hpp>

Public Member Functions

 MovingAverageUInt16 (uint16_t init_value)
 
void initialize (uint16_t init_value)
 Initializes the moving average filter with a start value. More...
 
void input_data (uint16_t value_in)
 Read in a new datum and update the filter. More...
 
uint16_t get_result ()
 Get filter output value. More...
 

Protected Attributes

size_t current_index = 0
 
std::array< uint16_t, N > input_buffer
 
uint32_t result_sum
 

Detailed Description

template<size_t N>
class MovingAverageUInt16< N >

Does a recursive moving average over N values.

Filter length must be power of two and smaller than 2^16

This is a template class to have a compile-time-known fixed divisor, allowing the compiler to use fast bit shift operation instead of int division.

Member Function Documentation

◆ get_result()

template<size_t N>
uint16_t MovingAverageUInt16< N >::get_result ( )
inline

Get filter output value.

Returns
: Filtered result, unsigned 16 bit

◆ initialize()

template<size_t N>
void MovingAverageUInt16< N >::initialize ( uint16_t  init_value)
inline

Initializes the moving average filter with a start value.

Called from constructor but can also be called on demand.

Parameters
init_valueInitial value
Note
First N calls of the filter yield no completely filtered result but a varyingly weighted average of the init value and input data.

◆ input_data()

template<size_t N>
void MovingAverageUInt16< N >::input_data ( uint16_t  value_in)
inline

Read in a new datum and update the filter.

Parameters
value_inInput datum, unsigned 16 bit

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