Larus glider flight sensor system 3.9.2024
Software-In-The-Loop test and validation system
Loading...
Searching...
No Matches
accumulating_averager.h
Go to the documentation of this file.
1#ifndef GENERIC_ALGORITHMS_ACCUMULATING_AVERAGER_H_
2#define GENERIC_ALGORITHMS_ACCUMULATING_AVERAGER_H_
3
5template <typename type> class accumulating_averager
6{
7public:
9 : sum(0), samples(0)
10 {}
11 void update( type input)
12 {
13 sum += input;
14 ++samples;
15 }
16 type get_average( void) const
17 {
18 if( samples == 0)
19 return { 0};
20
21 float tmp = 1.0f / samples;
22 return sum * tmp;
23 }
24 void reset( type set_this_value, unsigned set_this_count)
25 {
26 sum = set_this_value * set_this_count;
27 samples = set_this_count;
28 }
29private:
30 type sum;
31 unsigned samples;
32};
33
34#endif /* GENERIC_ALGORITHMS_ACCUMULATING_AVERAGER_H_ */
simple average mechanism using the sum of input values
void reset(type set_this_value, unsigned set_this_count)