24 #include <gsl/gsl_vector.h>
25 #include <gsl/gsl_matrix.h>
26 #include <gsl/gsl_blas.h>
35 s.
xk = gsl_vector_alloc(p.
n);
36 gsl_vector_set_zero(s.
xk);
38 s.
xkm = gsl_vector_alloc(p.
n);
39 gsl_vector_set_zero(s.
xkm);
41 s.
Pxk = gsl_matrix_alloc(p.
n, p.
n);
42 gsl_matrix_set_zero(s.
Pxk);
44 s.
Fxk = gsl_matrix_alloc(p.
n, p.
n);
45 gsl_matrix_set_zero(s.
Fxk);
47 s.
Rv = gsl_matrix_alloc(p.
n, p.
n);
48 gsl_matrix_set_zero(s.
Rv);
51 s.
yk = gsl_vector_alloc(p.
no);
52 gsl_vector_set_zero(s.
yk);
55 gsl_vector_set_zero(s.
ino_yk);
57 s.
Hyk = gsl_matrix_alloc(p.
no, p.
n);
58 gsl_matrix_set_zero(s.
Hyk);
60 s.
Rn = gsl_matrix_alloc(p.
no, p.
no);
61 gsl_matrix_set_zero(s.
Rn);
64 s.
Kk = gsl_matrix_alloc(p.
n, p.
no);
65 gsl_matrix_set_zero(s.
Kk);
92 gsl_matrix_set_identity(s.
Rn);
96 gsl_matrix_set_identity(s.
Pxk);
103 gsl_vector_free(s.
xk);
104 gsl_vector_free(s.
xkm);
105 gsl_matrix_free(s.
Pxk);
106 gsl_matrix_free(s.
Fxk);
107 gsl_matrix_free(s.
Rv);
109 gsl_vector_free(s.
yk);
110 gsl_vector_free(s.
ino_yk);
111 gsl_matrix_free(s.
Hyk);
112 gsl_matrix_free(s.
Rn);
114 gsl_matrix_free(s.
Kk);
124 template <
typename FunctProcess,
typename JacobianProcess,
typename FunctObservation,
typename JacobianObservation>
142 gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, s.
Pxk, s.
Fxk, 0.0, s.
temp_n_n);
143 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, s.
Fxk, s.
temp_n_n, 0.0, s.
Pxk);
144 gsl_matrix_add(s.
Pxk, s.
Rv);
159 gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, s.
Pxk, s.
Hyk, 0.0, s.
temp_n_no);
168 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, s.
Pxk, s.
temp_n_no, 0.0, s.
Kk);
178 for(
int i = 0 ; i < p.
no ; ++i)
180 for(
int j = 0 ; j < p.
no ; ++j)
182 gsl_matrix_set(s.
temp_no_no, i, j, gsl_matrix_get(s.
Hyk, i, i) * gsl_matrix_get(s.
Hyk, j, j) * gsl_matrix_get(s.
Pxk, i, j) + gsl_matrix_get(s.
Rn, i, j));
192 for(
int i = 0 ; i < p.
no; ++i)
193 for(
int j = 0 ; j < p.
no ; ++j)
195 for(
int i = p.
no ; i < p.
n; ++i)
196 for(
int j = 0 ; j < p.
no ; ++j)
199 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, s.
Pxk, s.
temp_n_no, 0.0, s.
Kk);
206 gsl_vector_memcpy(s.
ino_yk, yk);
208 gsl_vector_memcpy(s.
xk, s.
xkm);
209 gsl_blas_dgemv(CblasNoTrans, 1.0, s.
Kk, s.
ino_yk, 1.0,s.
xk);
215 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, -1.0, s.
Kk, s.
Hyk, 0.0, s.
temp_n_n);
218 for(
int i = 0 ; i < p.
n ; ++i)
224 for(
int i = 0 ; i < p.
n ; ++i)
226 for(
int j = 0 ; j < p.
no ; ++j)
228 gsl_matrix_set(s.
temp_n_n, i, j, (i==j?1.0:0.0) - gsl_matrix_get(s.
Kk, i,j) * gsl_matrix_get(s.
Hyk, j,j) );
230 for(
int j = p.
no ; j < p.
n ; ++j)
232 gsl_matrix_set(s.
temp_n_n, i, j, (i == j ? 1.0 : 0.0));
double observation_noise
Covariance of the observation noise.
Definition: ekf_types.h:50
virtual void updateEvolutionNoise(ekf_param &p, ekf_state &s)=0
int no
Dimension of the output.
Definition: ekf_types.h:65
gsl_matrix * Rv
Variance covariance of the evolution noise.
Definition: ekf_types.h:99
gsl_vector * ino_yk
Current innovations.
Definition: ekf_types.h:109
gsl_matrix * temp_n_no
Definition: ekf_types.h:132
void ekf_free(ekf_param &p, ekf_state &s)
Definition: ekf.h:101
gsl_vector * yk
Current observation.
Definition: ekf_types.h:104
Structure holding the parameters of the statistical linearization.
Definition: ekf_types.h:39
Definition: ekf_types.h:74
gsl_matrix * Rn
Variance covariance of the observation noise.
Definition: ekf_types.h:119
gsl_vector * xkm
Predicted state.
Definition: ekf_types.h:84
gsl_vector * xk
Current estimate of the state.
Definition: ekf_types.h:79
EvolutionNoise * evolution_noise
Evolution noise type.
Definition: ekf_types.h:45
gsl_matrix * temp_n_n
Temporary matrices.
Definition: ekf_types.h:129
gsl_matrix * Hyk
Jacobian of the observation function.
Definition: ekf_types.h:114
gsl_matrix * Kk
Kalman gain.
Definition: ekf_types.h:124
void ekf_init(ekf_param &p, ekf_state &s)
Definition: ekf.h:31
gsl_vector * temp_no
Definition: ekf_types.h:134
void ekf_iterate(ekf_param &p, ekf_state &s, FunctProcess f, JacobianProcess df, FunctObservation h, JacobianObservation dh, gsl_vector *yk)
Definition: ekf.h:125
gsl_matrix * temp_no_no
Definition: ekf_types.h:131
gsl_matrix * temp_n_1
Definition: ekf_types.h:130
gsl_matrix * Fxk
Jacobian of the evolution function.
Definition: ekf_types.h:94
double prior_pk
Prior estimate of the covariance matrix.
Definition: ekf_types.h:55
void init(ekf_param &p, ekf_state &s)
Definition: ekf_types.h:154
gsl_matrix * Pxk
Variance-Covariance of the state.
Definition: ekf_types.h:89
gsl_matrix * temp_2_n_n
Definition: ekf_types.h:133
int n
Number of parameters to estimate.
Definition: ekf_types.h:60
bool observation_gradient_is_diagonal
Is the observation gradient diagonal ? In that case, simplifications can be introduced.
Definition: ekf_types.h:70
gsl_vector * params
Optional parameters (this must be allocated and initialized from the user side!
Definition: ekf_types.h:139