Continuous vs discrete time

조회 수: 16 (최근 30일)
VAHA
VAHA 2023년 10월 2일
댓글: VAHA 2023년 11월 2일
Hello,
I am trying to design EKF in MATLAB, where my system dynamics (transition model) has this form --> (1), ​which is continuous in time, but my measurement model is discrete. So in order to convert Eq (1) to a discrete domain, I tried the ODE45 solver, and I expected the result in this form --> (2). But I have been told that the MATLAB ODE45 solver will produce only continuous results, i.e. integrating continuous-time domain differential equations using an ODE45 solver gives results in continuous-time, not in discrete, is that true? So for this reason I used forward Euler (first order RK). Which one is the correct one to transform equation (1) into Eq (2) since EKF in MATLAB expects everything in discrete?
Thanks in advance
Best
Hashir
  댓글 수: 2
Paul
Paul 2023년 10월 2일
Hi Hashir,
The function ode45 does not convert a differential equation into the form of a discrete-time, approximating difference equation. Rather, ode45 solves for an approximate numerical solution to the differential equation, which can be used in an EKF implementation.
Regarding "... since EKF in MATLAB expects everything in discrete?" Does this refer to a specific EKF function that ships with Matlab? If so, can you provided a link to the relevant doc page?
VAHA
VAHA 2023년 10월 3일
편집: VAHA 2023년 10월 3일
Hi @Paul Paul,
Regarding this statement : "since EKF in MATLAB expects everything in discrete?" what I meant is, in MATLAB the ExtendedKalmanFilter expects the vehicle model and measuement model in discrete-time. Exactly the ode45 approximates the differential equation numerically. So is there any method to convert Eq (1) into (2) completely?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2023년 10월 2일
It is difficult to follow what you are doing as you describe it. It might be best to use the Control System Toolbox functions if you have access to them, and the extendedKalmanFilter function (introduced in R2016b, improved in R2020b) might be particularly helpful. (I have limited experience with Kalman filters in general, so this reference is likely the best I can do.)
You can force the MATLAB ODE solvers to produce output at specific times by giving it a vector of (ideally a constant sampling interval) times using the linspace function.
  댓글 수: 9
Paul
Paul 2023년 10월 4일
편집: Paul 2023년 10월 4일
I was following everything, for the most part, until I got to the part about the state transition matrix. The EKF on the linked page, either the continous-discrete or the discrete-discrete, does not use a state transition matrix.
Here's an example that shows using ode45 for the state prediction is, at least, feasible using extendedKalmanFilter for a continuous system with discrete meausrements. However, I'm still not clear on how the extendedKalmanFilter estimates the Jacobian for the state equation. Also, the extendedKalmanFilter is propagating the error covariance for a discrete time system as opposed to integrating the differential equation for the error covariance. Consequently, we have to be careful about the definiton of ProcessNoise, which is a spectral density for continuous time systems and has to be converted to a covariance for discrete-time propagation, if you want ProcessNoise to represent a physical process as opposed to just a user-defined parameter. Anyway, the code below shows how to use ode45 for the state propagation, w/o worrying about any other issues.
Model the truth system and plot the solution
vdpode = @(t,x) [x(2); (1-x(1)^2)*x(2)-x(1)];
x0 = [2;0];
sol = ode45(vdpode,[0 5],x0,odeset('MaxStep',0.05));
figure
plot(sol.x,sol.y)
hold on
Define EKF measurement function
measurementfunction = @(x) x(1);
Define the state prediction function using Euler integration and the EKF with default parameters.
state1 = @(x,dt) x + vdpode(0,x)*dt;
ekf1 = extendedKalmanFilter(state1,measurementfunction,x0);
Execute the EKF. Use the truth data as measurements. Plot the result.
dt = 0.05;
tvec = 0:dt:5;
xhat1 = nan(2,numel(tvec));
for ii = 1:numel(tvec)
meas = deval(sol,tvec(ii),1);
xhat1(:,ii) = correct(ekf1,meas);
predict(ekf1,dt);
end
plot(tvec,xhat1,'o'),grid
Define state prediction function using ode45 and the EKF with default parameters.
% the vdp ode is not dependent on time, so use [0 dt] as the tspan.
state2 = @(x,dt) ode45(vdpode,[0 dt],x).y(:,end);
ekf2 = extendedKalmanFilter(state2,measurementfunction,x0);
Execute and plot
xhat2 = nan(2,numel(tvec));
for ii = 1:numel(tvec)
meas = deval(sol,tvec(ii),1);
xhat2(:,ii) = correct(ekf2,meas);
predict(ekf2,dt);
end
plot(tvec,xhat2,'x'),grid
VAHA
VAHA 2023년 11월 2일
THank you for all your valuable information

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by