-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinnow.h
55 lines (44 loc) · 1.66 KB
/
Winnow.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
54
55
#ifndef _Winnow_h
#define _Winnow_h
/**
* @brief Implements a simple Kalman filter for one-dimensional data
*/
class Winnow {
private:
double q; // process noise covariance
double r; // measurement noise covariance
double x; // value
double p; // estimation error covariance
double k; // kalman gain
public:
// Constructors
Winnow() : q(0.0), r(0.0), p(0.0), x(0.0), k(0.0) {}
Winnow(double process_noise, double sensor_noise, double estimated_error, double initial_value)
: q(process_noise), r(sensor_noise), p(estimated_error), x(initial_value), k(0.0) {}
double getFilteredValue(double measurement) {
this->p = this->p + this->q;
// measurement update
this->k = this->p / (this->p + this->r);
this->x = this->x + this->k * (measurement - this->x);
this->p = (1 - this->k) * this->p;
return this->x;
}
// Setters
void setParameters(double process_noise, double sensor_noise, double estimated_error) {
this->q = process_noise;
this->r = sensor_noise;
this->p = estimated_error;
}
void setParameters(double process_noise, double sensor_noise) {
this->q = process_noise;
this->r = sensor_noise;
}
void setProcessNoise(double process_noise) { this->q = process_noise; }
void setSensorNoise(double sensor_noise) { this->r = sensor_noise; }
void setEstimatedError(double estimated_error) { this->p = estimated_error; }
// Getters
double getProcessNoise() const { return this->q; }
double getSensorNoise() const { return this->r; }
double getEstimatedError() const { return this->p; }
};
#endif