5 %setting the seed
for reproducability
6 isOctave = exist(
'OCTAVE_VERSION',
'builtin') ~= 0;
13 %define discrete logistic growth model and its jacobian
16 next_func = @(x,t) x + rate.*x.*(1 - x/max_pop) + 0.*t;%time independent
17 jacobian_func = @(x,t) 1 + rate - (2*rate*x)/max_pop + 0.*t;
19 %in
this model the time is only necessary
20 %
for plotting an interpreting the results.
24 dt = (t_final - t_start)/outputs;
26 %discrete noise covariance
28 %sensor noise covariance
36 %model results
if there was no process noise
37 ideal_data = zeros(state_count,outputs);
38 %actual data (with process noise)
39 process_noise_data = zeros(state_count,outputs);
40 %noisy measurements of actual data
41 measurements = zeros(sensor_count,outputs);
43 %initial estimate and covariance
44 %the initial estimate in
this case 45 %matches the actual data
49 %initial condition
for ideal
50 %and real process data
59 x_noise = next_func(x_noise,0) + chol(Q_d)
'*randn(state_count,1); 60 process_noise_data(:,ii) = x_noise; 61 measurements(ii) = C*x_noise + chol(R_d)'*randn(sensor_count,1);
64 %filter the noisy measurements
65 [estimates, covariances] =
ddekf(next_func,jacobian_func,dt,t_start,state_count,...
66 sensor_count,outputs,C,chol(Q_d)
',chol(R_d)',chol(P_0)
',x_0, measurements); 68 %compare the measurements, estimates and true state. 69 %The ideal data is not plotted and is only for reference. 70 time = 0:dt:(outputs-1)*dt; 73 plot(time,measurements); 74 plot(time,process_noise_data); 75 plot(time,estimates(1:end-1)); 76 legend('Measurement
','Real data
','Estimate
'); 83 plot(time(1:limit),measurements(1:limit),'LineWidth
',2); 84 plot(time(1:limit),process_noise_data(1:limit),'LineWidth
',2); 85 plot(time(1:limit),estimates(1:limit),'LineWidth
',2); 86 legend('Measurement
','Real data
','Estimate
'); 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)