-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEwma.h
53 lines (44 loc) · 1.13 KB
/
Ewma.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* EWMA Filter - Exponentially Weighted Moving Average filter used for smoothing data series readings.
*
* output = alpha * reading + (1 - alpha) * lastOutput
*
* Where:
* - alpha = factor greater than 0 and less or equal to 1
* - reading = current input value
* - lastOutput = last filter output value
* - output = filter output value after the last reading
* https://www.arduino.cc/reference/en/libraries/ewma/
*/
#ifndef EWMA_H_
#define EWMA_H_
class Ewma {
public:
/*
* Current data output
*/
double output = 0;
/*
* Smoothing factor, in range [0,1]. Higher the value - less smoothing (higher the latest reading impact).
*/
double alpha = 0;
// Custom constructor, need alpha init
Ewma();
/*
* Creates a filter without a defined initial output. The first output will be equal to the first input.
*/
Ewma(double alpha);
/*
* Creates a filter with a defined initial output.
*/
Ewma(double alpha, double initialOutput);
void reset();
/*
* Specifies a reading value.
* @returns current output
*/
double filter(double input);
private:
bool hasInitial = false;
};
#endif /* EWMA_H_ */