Clear Filters
Clear Filters

How to initialize the external input value in case of particleFilter code?

1 view (last 30 days)
I am trying to implement the Particle Filter algorithm in my work with the help of the sample code provided in "Nonlinear State Estimation Using Unscented Kalman Filter and Particle Filter" section in MathWorks. The MathWorks sample Particle Filter code is:
pf = particleFilter(@vdpParticleFilterStateFcn,@vdpExamplePFMeasurementLikelihoodFcn);
initialize(pf, 1000, [2;0], 0.01*eye(2));
R = 0.2; % Variance of the measurement noise v[k]
ukf.MeasurementNoise = R;
T = 0.05; % [s] Filter sample time
timeVector = 0:T:50;
[~,xTrue]=ode45(@vdp1,timeVector,[2;0]);
rng(1); % Fix the random number generator for reproducible results
yTrue = xTrue(:,1);
yMeas = yTrue .* (1+sqrt(R)*randn(size(yTrue))); % sqrt(R): Standard deviation of noise
for k=1:size(xTrue,1)
xCorrectedPF(k,:) = correct(pf,yMeas(k)); % Filter updates and stores Particles[k|k], Weights[k|k]
predict(pf); % Filter updates and stores Particles[k+1|k]
end
figure();
subplot(2,1,1);
plot(timeVector,xTrue(:,1),timeVector,xCorrectedPF(:,1),timeVector,yMeas(:));
legend('True','Particlte filter estimate','Measured')
ylim([-2.6 2.6]);
ylabel('x_1');
subplot(2,1,2);
plot(timeVector,xTrue(:,2),timeVector,xCorrectedPF(:,2));
ylim([-3 1.5]);
xlabel('Time [s]');
ylabel('x_2');
Where, the vdpParticleFilterStateFcn evaluate the van der Pol system ODEs: dxdt = [x(2); (1-x(1)^2)*x(2)-x(1)];
Now, by introducing a external input u(t), I have modified the system ODEs like: dxdt = [x(2); (1-x(1)^2)*x(2)-x(1)*u];
My question is how to provide the external input value, u(0) in the initialize instruction and update the value u(k) in the correct and predict step during each iteration of the for-loop?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!