1 function [estimate, covariance_sqrt] =
cdekf_predict_phase(f_func,jacobian_func,h,dt_between_measurements,start_time,P_0_sqrt,x_0,Q_root)
2 %runs predict portion of update of the extended kalman filter
3 %[estimate, covariance_sqrt]
cdekf_predict_phase(f_func,jacobian_func,h,dt_between_measurements,start_time,P_0_sqrt,x_0,Q_root)
5 % f_func: encodes relationship \dot{x} = f_func(x,t)
for state x
8 % jacobian_func: the jacobian of f_func at state x and time t
10 % h: fixed timestep used by RK4 to cover dt_between_measurements
11 % to evolve estimate as well covariance matrix. h must be less
12 % than dt_between_measurements
14 % dt_between_measurements: distance between incoming measurements
16 % start_time: start time over which solving RK4
17 % (finish time is start_time + dt_between_measurements)
19 % x_0: estimate of x at start_time
21 % P_0_sqrt: square root factor of covariance P at
22 % start_time. P_0 = P_0_sqrt*(P_0_sqrt
') 24 % Q_root: square root of process noise covariance matrix 25 % Q where Q = Q_root*(Q_root');
28 % estimate: estimate of x at dt_between_measurements + start_time
30 % covariance_sqrt: square root of covariance P after the
31 % update phase. P = covariance_sqrt*(covariance_sqrt
') 33 current_time = start_time; 34 finish_time = start_time + dt_between_measurements; 36 state_count = length(x); 38 Phi = eye(state_count); 39 Phi_sum_root = zeros(state_count,state_count); 41 while(current_time < finish_time) 42 if(current_time + h > finish_time) 43 h = finish_time - current_time; 47 k1 = h.*f_func(x,current_time); 48 k2 = h.*f_func(x + k1./2,current_time+h/2); 49 k3 = h.*f_func(x + k2./2,current_time+h/2); 50 k4 = h.*f_func(x + k3, current_time + h); 51 x = x + k1./6 + k2./3 + k3./3 + k4./6; 54 jac_a = jacobian_func(x,current_time); 55 %k_phi_1 = h.*jac_A*(Phi); 56 %k_phi_2 = k_phi_1 + (0.5*h).*jac_A*(k_phi_1); 57 %k_phi_3 = k_phi_1 + (0.5*h).*jac_A*(k_phi_2); 58 %k_phi_4 = k_phi_1 + h.*jac_A*(k_phi_3); 59 %Phi_next = Phi + k_phi_1./6 + k_phi_2./3 + k_phi_3./3 + 61 %since jac_A is constant at current time the commented lines 62 %can be replaced with the stuff below 65 jac_a_2 = jac_a*jac_a; 66 jac_a_3 = jac_a_2*jac_a; 67 jac_a_4 = jac_a_3*jac_a; 68 Phi_next = (eye(state_count) + (h).*jac_a + (1/2*h^2).*jac_a_2 +... 69 (1/6*h^3).*jac_a_3 + (1/24*h^4).*jac_a_4)*Phi; 71 %Trapezoid rule. add phi and phi_next together 72 [~, R_tmp1] = qr([Phi*Q_root,Phi_next*Q_root]');
73 R_tmp1 = sqrt(h*0.5).*R_tmp1
'; 74 R_tmp1 = R_tmp1(1:state_count, 1:state_count); 76 %Add previous sum to overall phi sum 77 [~, R_tmp1] = qr([R_tmp1,Phi_sum_root]');
79 R_tmp1 = R_tmp1(1:state_count, 1:state_count); 80 Phi_sum_root = R_tmp1; 83 current_time = current_time + h; 86 [~, R_tmp1] = qr([Phi*P_0_sqrt,Phi_sum_root]');
87 covariance_sqrt = R_tmp1
'; 88 covariance_sqrt = covariance_sqrt(1:state_count,1:state_count); function cdekf_predict_phase(in f_func, in jacobian_func, in h, in dt_between_measurements, in start_time, in P_0_sqrt, in x_0, in Q_root)