-
Notifications
You must be signed in to change notification settings - Fork 96
/
kalman.h
89 lines (73 loc) · 2.36 KB
/
kalman.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef __KALMAN_H__
#define __KALMAN_H__
#include "matrix.h"
/* Refer to http://en.wikipedia.org/wiki/Kalman_filter for
mathematical details. The naming scheme is that variables get names
that make sense, and are commented with their analog in
the Wikipedia mathematical notation.
This Kalman filter implementation does not support controlled
input.
(Like knowing which way the steering wheel in a car is turned and
using that to inform the model.)
Vectors are handled as n-by-1 matrices.
TODO: comment on the dimension of the matrices */
typedef struct {
/* k */
int timestep;
/* These parameters define the size of the matrices. */
int state_dimension, observation_dimension;
/* This group of matrices must be specified by the user. */
/* F_k */
Matrix state_transition;
/* H_k */
Matrix observation_model;
/* Q_k */
Matrix process_noise_covariance;
/* R_k */
Matrix observation_noise_covariance;
/* The observation is modified by the user before every time step. */
/* z_k */
Matrix observation;
/* This group of matrices are updated every time step by the filter. */
/* x-hat_k|k-1 */
Matrix predicted_state;
/* P_k|k-1 */
Matrix predicted_estimate_covariance;
/* y-tilde_k */
Matrix innovation;
/* S_k */
Matrix innovation_covariance;
/* S_k^-1 */
Matrix inverse_innovation_covariance;
/* K_k */
Matrix optimal_gain;
/* x-hat_k|k */
Matrix state_estimate;
/* P_k|k */
Matrix estimate_covariance;
/* This group is used for meaningless intermediate calculations */
Matrix vertical_scratch;
Matrix small_square_scratch;
Matrix big_square_scratch;
} KalmanFilter;
KalmanFilter alloc_filter(int state_dimension,
int observation_dimension);
void free_filter(KalmanFilter f);
/* Runs one timestep of prediction + estimation.
Before each time step of running this, set f.observation to be the
next time step's observation.
Before the first step, define the model by setting:
f.state_transition
f.observation_model
f.process_noise_covariance
f.observation_noise_covariance
It is also advisable to initialize with reasonable guesses for
f.state_estimate
f.estimate_covariance
*/
void update(KalmanFilter f);
/* Just the prediction phase of update. */
void predict(KalmanFilter f);
/* Just the estimation phase of update. */
void estimate(KalmanFilter f);
#endif