-
Notifications
You must be signed in to change notification settings - Fork 0
/
KalmanFilter.c
48 lines (36 loc) · 1.33 KB
/
KalmanFilter.c
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
//
// Created by ILKER KESER on 25.11.2024.
//
#include "KalmanFilter.h"
#include <math.h>
void KalmanFilter_Init(KalmanFilter_t *kalman,float mea_e,float est_e, float q){
kalman->_err_measure = mea_e;
kalman->_err_estimate = est_e;
kalman->_q = q;
kalman->_current_estimate =0.0f;
kalman->_last_estimate =0.0f;
kalman->_kalman_gain =0.0f;
}
float updateEstimate(KalmanFilter_t *kalman,float mea){
kalman->_kalman_gain = kalman->_err_estimate /(kalman->_err_estimate + kalman->_err_measure);
kalman->_current_estimate = kalman->_last_estimate + kalman->_kalman_gain * (mea - kalman->_last_estimate);
kalman->_err_estimate = (1.0f - kalman->_kalman_gain) * kalman->_err_estimate +
fabsf(kalman->_last_estimate - kalman->_current_estimate)*kalman->_q;
kalman->_last_estimate = kalman->_current_estimate;
return kalman->_current_estimate;
}
void setMeasurementError(KalmanFilter_t *kalman,float mea_e){
kalman->_err_measure = mea_e;
}
void setEstimateError(KalmanFilter_t *kalman,float est_e){
kalman->_err_estimate = est_e;
}
void setProcessNoise(KalmanFilter_t *kalman,float q){
kalman->_q = q;
}
float getKalmanGain(KalmanFilter_t *kalman){
return kalman->_kalman_gain;
}
float getEstimateError(KalmanFilter_t *kalman){
return kalman->_err_estimate;
}