Problem with unscented kalman filter

4 views (last 30 days)
Andrea Zuccotto
Andrea Zuccotto on 17 Oct 2019
Edited: Andrea Zuccotto on 17 Oct 2019
Hi everybody!
I'm trying to implement in matlab a simple unscented or alternatively extended Kalman Filter. At the moment i'd like just to observ a simple pendulum.
So I create a pendulum function and integrate it in 10 seconds with some Initial Conditions:
% pendulum state equation
function dxdt = pendulum(~, x)
g = 9.81;
l = 2;
dxdt = [x(2); -g/l*sin(x(1))]; % state equation
end
% integration function
function [t, x, xdot] = ode
tspan = [0:0.01:10];
IC = [pi/4,0];
[t,stat] = ode45(@pendulum, tspan, IC);
x = stat(:, 1);
xdot = stat(:, 2);
end
[time, x1, x2] = ode; % generating the results
No troubles so far
Then I create an extended Kalman Filter object, a measurment function where I suppose to measure angle Theta and some sensor readings
R = 0.1; % measurment covariance
for i = 1:length(x1)
y(i) = x1(i) + randn(1)*sqrt(R); % sensor readings
end
IC = [pi/4; 0];
UKF_pendulum = unscentedKalmanFilter(@pendulum,@MeasurementFcn,IC); % UKF object
UKF_pendulum.ProcessNoise = 0.01;
UKF_pendulum.MeasurementNoise = R;
residBuf = [];
xcorBuf = [];
xpredBuf = [];
for i = 1:size(y,2)
[Residual,ResidualCovariance] = residual(UKF_pendulum,y(i));
[CorrectedState,CorrectedStateCovariance] = correct(UKF_pendulum,y(i));
[PredictedState,PredictedStateCovariance] = predict(UKF_pendulum);
residBuf(i,:) = Residual;
xcorBuf(i,:) = CorrectedState';
xpredBuf(i,:) = PredictedState';
end
The rest is kept the same with respect to the Van Der Pol oscillator example at this link: https://it.mathworks.com/help/control/ref/predict_method_state_estimation.html
Unfortunately when I try to run i get this message:
Which optional input am I supposed to give to the predict command? I tried with some variables but none of them worked.
I'll upload the file in the comment.
Thank you very much,
Andrea

Answers (0)

Community Treasure Hunt

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

Start Hunting!