-
Notifications
You must be signed in to change notification settings - Fork 165
/
kalman_filter.h
46 lines (40 loc) · 1.46 KB
/
kalman_filter.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
/*
* FileName : kalman_filter.h
* Author : xiahouzuoxin @163.com
* Version : v1.0
* Date : 2014/9/24 20:37:01
* Brief :
*
* Copyright (C) MICL,USTB
*/
#ifndef _KALMAN_FILTER_H
#define _KALMAN_FILTER_H
/*
* NOTES: n Dimension means the state is n dimension,
* measurement always 1 dimension
*/
/* 1 Dimension */
typedef struct {
float x; /* state */
float A; /* x(n)=A*x(n-1)+u(n),u(n)~N(0,q) */
float H; /* z(n)=H*x(n)+w(n),w(n)~N(0,r) */
float q; /* process(predict) noise convariance */
float r; /* measure noise convariance */
float p; /* estimated error convariance */
float gain;
} kalman1_state;
/* 2 Dimension */
typedef struct {
float x[2]; /* state: [0]-angle [1]-diffrence of angle, 2x1 */
float A[2][2]; /* X(n)=A*X(n-1)+U(n),U(n)~N(0,q), 2x2 */
float H[2]; /* Z(n)=H*X(n)+W(n),W(n)~N(0,r), 1x2 */
float q[2]; /* process(predict) noise convariance,2x1 [q0,0; 0,q1] */
float r; /* measure noise convariance */
float p[2][2]; /* estimated error convariance,2x2 [p0 p1; p2 p3] */
float gain[2]; /* 2x1 */
} kalman2_state;
extern void kalman1_init(kalman1_state *state, float init_x, float init_p);
extern float kalman1_filter(kalman1_state *state, float z_measure);
extern void kalman2_init(kalman2_state *state, float *init_x, float (*init_p)[2]);
extern float kalman2_filter(kalman2_state *state, float z_measure);
#endif /*_KALMAN_FILTER_H*/