-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccelerometerFiltering.h
47 lines (43 loc) · 1.17 KB
/
AccelerometerFiltering.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
/**
* @file AccelerometerFiltering.h
* @author Ryan Johnson ([email protected])
* @brief Digital filters for 3-axis accelerometer data
* @version 0.1
* @date 2020-05-26
*
* @copyright Copyright (c) 2020
*
*/
#ifndef ACCELEROMETER_FILTERING_GUARD_H
#define ACCELEROMETER_FILTERING_GUARD_H
#include "ADXL355.h"
#include "MovingAverage.h"
/**
* @brief Exponentially-weighted moving average for 3-axis accelerometers
*
* @see MovingAverage
*/
class AccelerometerFilterMovingAverage {
public:
AccelerometerFilterMovingAverage(float startingPoint, float alpha)
: avgs({MovingAverage(startingPoint, alpha),
MovingAverage(startingPoint, alpha),
MovingAverage(startingPoint, alpha)}){};
void addData(ADXL355Measurement measure)
{
for (int i = 0; i < 3; i++) {
avgs[i].addPoint(((double *)&measure)[i]);
}
};
ADXL355Measurement getAverage()
{
ADXL355Measurement avg;
for (int i = 0; i < 3; i++) {
((double *)&avg)[i] = avgs[i].getAverage();
}
return avg;
};
private:
MovingAverage avgs[3];
};
#endif