KalmanFilter
test_update.m
Go to the documentation of this file.
1 clear all;
2 
3 addpath('../continuous_discrete');
4 addpath('../discrete_discrete');
5 
6 P_cell = {[5,0.5;0.5,3], [1 2 6;2 9 0.5; 6,0.5,0.1]};
7 for i=1:length(P_cell)
8  P = P_cell{1,i};
9  state_count = size(P,1);
10  r = 0.001;
11  P_root = chol(P)';
12  assert(max(max(abs(P_root*P_root'-P)))<0.0000000001);
13  R_root = sqrt(r);
14  measurement = 122.01;
15  estimate = randn(state_count,1);
16  C = randn(1,state_count);
17 
18  [estimate_next, covariance_sqrt] = ddekf_update_phase(R_root,P_root,C,estimate,measurement);
19  [estimate_next2, covariance_sqrt2] = cdekf_update_phase(R_root,P_root,C,estimate,measurement);
20 
21  %manual test (the classic udpate filter algorithm without square root algorithm)
22  K_k = (P_root*P_root')*(C')*inv(C*(P_root*P_root')*C'+R_root*R_root);
23  coV = (eye(state_count) - K_k*C)*(P_root*P_root');
24  estimate_new = estimate + K_k*(measurement - C*estimate);
25 
26  assert(norm(estimate_new - estimate_next) < 0.000000000001);
27  assert(max(max(abs(covariance_sqrt*covariance_sqrt' - coV))) < 0.0000000001)
28 
29 end
30 disp('update phase tested succesfully')
function ddekf_update_phase(in R_root, in P_root, in C, in estimate, in measurement)
function cdekf_update_phase(in R_root, in P_root, in C, in estimate, in measurement)