To implement an Extended Kalman Filter in Matlab, we need to define the state-space model of the system and the measurement model. The following code shows an example of a non-linear system (a pendulum) and its EKF implementation in Matlab:
main.m1635 chars76 lines
In this example, pendulum_f
is the state transition function, pendulum_h
is the measurement function, pendulum_A
is the state transition Jacobian, and pendulum_H
is the measurement Jacobian. The EKF is initialized with the initial state and covariance (x0
and P0
), as well as the process and measurement noise covariance matrices (Q
and R
). The predict
and correct
functions are used to update the EKF at each time step.
The code simulates the pendulum dynamics and measurement, and updates the EKF at each time step. The results are plotted, showing the true and measured angle over time.
gistlibby LogSnag