4 C = [1, 0.1]; %observation matrix to obtain measurement y (y = C*x + noise)
5 A = [-1,0.2;-0.1,-1]; %(d/dt)x(t) = A*x(t)
6 R_c = [0.1^2]; %continuous sensor noise
7 Q_c = [0.001^2,0;0,0.001^2]; %continuous process noise
8 P_0 = eye(2);%initial covariance
14 dt = (t_final-t_start)/outputs;
16 A_d = eye(2) + dt.*A;%x_{k+1} = A_d*x_k
21 isOctave = exist(
'OCTAVE_VERSION',
'builtin') ~= 0;
23 jacobian_func = @(x) A_d + 0.*x;
25 xx = sym(
'x',[state_count,1]);
26 jacobian_func = matlabFunction(jacobian(func(xx),xx),
'Vars',xx);
28 func = @(x,t) func(x) + 0.*t;
29 jacobian_func = @(x,t) jacobian_func(x) + 0.*t;
31 x_0 = [100; 80]; %initial real data state
32 state_count = length(x_0);
34 ideal_data = zeros(state_count,outputs); %data with no process noise
35 process_noise_data = zeros(state_count,outputs);
36 measurements = zeros(sensor_count,outputs);
47 x = x + dt.*(A*x);%Explicit Eulers
48 ideal_data(:,ii) = x;%the first column of ideal_data and process_noise_data is x_1
49 x_noise = x_noise + dt.*(A*x_noise) + sqrt(Q_d)*randn(state_count,1);%Euler-Maruyama
50 process_noise_data(:,ii) = x_noise;
51 measurements(ii) = C*x_noise + sqrt(R_d)*randn(sensor_count,1);
54 [estimates, covariances ] =
ddekf(func,jacobian_func,dt,t_start,state_count,...
55 sensor_count,outputs,C,chol(Q_d)
',chol(R_d)',chol(P_0)
',x_0, measurements); function ddekf(in f_func, in jacobian_func, in dt_between_measurements, in start_time, in state_count, in sensor_count, in measurement_count, in C, in Q_root, in R_root, in P_0_root, in x_0, in measurements)