Update the Kalman Filter in Simulink model
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to creat a Filter in Simulink. For example:
kf = trackingKF('MotionModel', '2D Constant Acceleration', 'State', zeros(6, 1));
Then in simulink model, I want to update the filter and predict the states after receive feedback during the simulation. The function is defined as:
function predictedState = fcn(x,y)
% Receive feedback about the present position
presentPosition = [x;y];
% Correct step: Update the filter with observed position
correct(filter, presentPosition);
% Predict future positions after receiving feedback
predictedState = predict(filter);
end
My problem is: How to define this Filter in Simulink that can be updated by using 'correct' command, and how can I build a structure that can update this filter using my above function during my simulation. Thank you for your helps !
I try to define the Kalman Filter in my Predict function but it seems not good because the filter need to be updated to become more precise. Can the callback function in Model Explorer give a help ?
0 comentarios
Respuestas (1)
MULI
el 18 de Jun. de 2024
Hi Pham,
I understand that you need to update the filter states based on feedback received during simulation. To integrate and continuously update a Kalman Filter in Simulink, you can use a "MATLAB Function" block. Within this block, utilize a "persistent" variable to maintain the filter's state across function calls, as given below:
function predictedState = fcn(x, y)
% Persistent variable to hold the filter
persistent filter
% Initialize the filter if it's the first execution
if isempty(filter)
filter = trackingKF('MotionModel', '2D Constant Acceleration', 'State', zeros(6, 1));
end
% Correct the filter's state based on new measurements
presentPosition = [x; y];
correct(filter, presentPosition);
% Predict the next state
predictedState = predict(filter);
end
You may refer to this documentation link for more information on “persistent” variable.
0 comentarios
Ver también
Categorías
Más información sobre State-Space Control Design and Estimation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!