Localization & SLAM · Theory · M3
M3-T7 — EKF-SLAM
The extended Kalman filter on the joint pose-and-map state, step by step.
This lesson writes down the EKF-SLAM algorithm completely enough to implement it, and then runs one update by hand so every number can be checked. The structure is the one from the previous lesson; the new content is the Jacobians, the handling of new landmarks and the failure modes of linearisation.
Learning objectives
After this lesson, you should be able to:
- Write the EKF-SLAM prediction using the extended motion Jacobian and the update with the sparse measurement Jacobian.
- Initialise a new landmark in the joint state with the correct cross-covariances.
- Carry out one prediction and one update on a small example and interpret the changes in the covariance.
- Explain the sources of inconsistency in EKF-SLAM and list mitigations.
The problem and the intuition
An EKF is the Bayes filter with Gaussians and a straight-line approximation of the models around the current estimate. For SLAM there is nothing new in the idea: one state vector, one covariance matrix, two steps. What is new is the bookkeeping. The state is long, but the models are local: moving touches only the robot, and a measurement touches only the robot and one landmark. Careful code exploits that sparsity.
Think of EKF-SLAM as the localisation EKF of M2-L3 with a map attached to the state. Everything you wrote there carries over.
The algorithm: EKF-SLAM
Problem. Maintain a Gaussian N(μ, Σ) over y = (x, m) as controls and range-bearing observations of identified landmarks arrive.
Assumptions. Known data association; Gaussian noise; models linearised at the current estimate; static landmarks; the first pose defines the origin (so its covariance starts at zero).
Prediction
Here g and its pose Jacobian Gx are the odometry motion model from M2-T6 and Rx = Gu Qu Guᵀ the odometry noise in pose space. Since G is the identity everywhere except in its top-left 3×3 block, in practice one updates only the first three rows and columns of Σ.
Update for an observation of landmark j
- Fx
- selector matrix that picks the three pose entries out of the full state.
- Hx, Hl
- Jacobians of the range-bearing model with respect to the pose and to the landmark (M2-T6).
- Q
- measurement noise covariance (2×2).
- S, K
- innovation covariance (2×2) and Kalman gain ((3+2N)×2).
Initialising a new landmark
The landmark is placed from the current pose estimate and the measurement. Its covariance and cross-covariance with the existing state follow by propagating through the initialisation function:
where Jx = ∂l/∂x and Jz = ∂l/∂(r, b). The cross-term is important: the new landmark is correlated with the robot pose and with everything the pose is correlated with.
Failure modes
- Linearisation error and inconsistency. The Jacobians are evaluated at the estimate, not the truth. After the heading estimate becomes confident, the filter creates information about heading that the data do not contain (the unobservable global rotation). Result: overconfident covariance and divergence (Julier and Uhlmann, 2001; Huang and Dissanayake, 2007).
- Wrong association. A single bad update shifts the whole state and cannot be undone.
- Wrapping errors. Unwrapped bearing innovations or heading entries give updates of size 2π.
- Numerical issues. Σ loses symmetry and positive definiteness: use the Joseph form and symmetrise.
- Scaling. O(N²) per update (previous lesson).
A worked example: one landmark, one prediction, one update
The robot starts at (0, 0, 0) with zero uncertainty (it defines the frame). The sensor has σr = 0.1 m, σb = 0.03 rad. Odometry noise: translation noise 0.05 per metre (so 5 cm for a 1 m move), rotation noise 0.02 per metre.
- First observation (new landmark). r = 5, b = 0. Place l = (5, 0). With Σxx = 0 the landmark covariance is Jz Q Jzᵀ = diag(0.1², (5 × 0.03)²) = diag(0.0100, 0.0225). The cross-covariance with the pose is zero. State size 5.
- Prediction. The robot drives u = (1 m, 0 rad). The mean becomes (1, 0, 0). The pose noise from odometry is Rx = Gu Qu Guᵀ with Qu = diag(0.05², 0.02²): Rx = [[0.0025, 0, 0], [0, 0.0001, 0.0002], [0, 0.0002, 0.0004]]. So σx = 5 cm, σy = 1 cm, σθ = 0.02 rad. The landmark block is unchanged.
- Second observation of the same landmark. The robot at (1, 0, 0) predicts r̂ = 4 and b̂ = 0. It measures r = 4.02, b = 0.01. The innovation is ν = (0.02, 0.01).
- Jacobians. dx = 4, dy = 0, r = 4: Hx = [[−1, 0, 0], [0, −0.25, −1]] and Hl = [[1, 0], [0, 0.25]]. The innovation covariance is S = H Σ̄ Hᵀ + Q = [[0.0225, 0], [0, 0.0028]].
- The update. The gain moves the pose by about (−0.002, −0.0008) m and the landmark by about (+0.009, +0.020) m: the new landmark estimate is (5.009, 0.020). The corrected standard deviations are: pose x 4.7 cm (from 5.0), y 0.91 cm, θ 0.018 rad; landmark x 7.5 cm (from 10), y 10.6 cm (from 15). The landmark’s uncertainty fell a lot, the pose’s a little.
- The correlations. After the update Σx,l = diag(0.0011, 0.00045) and the heading is correlated with the landmark’s y (0.0009): the pose and the landmark are now tied. A later observation that moves the landmark moves the pose with it.
You will implement exactly these two steps in the lab and check them against a reference.
Engineering implications and limitations
Engineering implications
- Exploit the sparsity in code. Update only the pose block in prediction; in the update, form H as a 2×(3+2N) matrix with just the relevant columns and use the structure to avoid N×N products where possible.
- Joseph form and symmetrisation keep Σ a valid covariance over long runs; check eigenvalues occasionally.
- Observability. The global position and heading of the map are unobservable from relative measurements. Do not let the filter shrink them below the initial uncertainty: a common fix is the first-estimates Jacobian (Huang et al., 2008).
- Tune the noise by consistency tests (NEES with ground truth, NIS without) as in M2-L3.
- Use it where it fits. EKF-SLAM is fine for small maps with reliable landmarks (fiducial markers, reflectors). For anything larger, use a graph-based or particle-based method.
Limits
EKF-SLAM linearises once and cannot revisit, scales as O(N²), and assumes Gaussian beliefs, so it cannot hold the multiple hypotheses of a repetitive environment. These are the reasons the field moved to graph optimisation (Module 4) and particle filters (M3-T8).
Common misconceptions
“The update only changes the landmark that was observed.”
The gain is dense: the pose and every correlated landmark change too.
“The new landmark has no correlation with the robot.”
It is placed from the pose estimate, so it is correlated with the pose and with everything correlated with the pose.
“EKF-SLAM is consistent if it converges.”
A converged EKF can still be overconfident because of linearisation error; test consistency separately.
“Covariances in the filter are rigorous probabilities.”
They are first-order approximations and often too optimistic.
Engineering takeaways
- EKF-SLAM keeps (μ, Σ) over the pose and all landmarks; prediction touches only the pose block, the update uses a sparse H but a dense gain.
- New landmarks are initialised from the pose and the measurement and must inherit the cross-covariances.
- The correlations created by the updates are what transmit a correction to the rest of the map.
- Linearisation error and unobservable global rotation cause inconsistency; the Joseph form and noise tuning help but do not cure it.
- It is a good teaching tool and a fit for small, well-identified maps, but not for large ones.
References and further reading
Established fundamentals. Consistent and invariant filters are an active research topic (Module 8).
- Thrun, S., Burgard, W. and Fox, D. (2005). Probabilistic Robotics. MIT Press, chapter 10.2: EKF-SLAM with known correspondences.
- Dissanayake, M. W. M. G. et al. (2001). A solution to the simultaneous localization and map building (SLAM) problem. IEEE Transactions on Robotics and Automation 17(3).
- Huang, G. P. and Dissanayake, G. (2007). Convergence and consistency analysis for extended Kalman filter based SLAM. IEEE Transactions on Robotics 23(5).
- Huang, G. P., Mourikis, A. I. and Roumeliotis, S. I. (2008). Analysis and improvement of the consistency of extended Kalman filter based SLAM. IEEE International Conference on Robotics and Automation.
- Julier, S. J. and Uhlmann, J. K. (2001). A counter example to the theory of simultaneous localization and map building. IEEE International Conference on Robotics and Automation.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
In the prediction step only the first three rows and columns of Σ change. Why is that correct, and what stays unchanged?
Explanation
The motion model moves only the robot, and landmarks are static. The landmark–landmark block does not change; the pose block grows with odometry noise, and the pose–landmark cross-covariance is transformed by the motion Jacobian: Σ̄xm = Gx Σxm.
Question 2
A new landmark is added with its covariance set to Jz Q Jzᵀ and zero cross-covariance with the robot, even though the robot pose is uncertain. What is wrong?
Explanation
The landmark was placed using the uncertain pose, so its position inherits the pose error and is correlated with it. Setting the cross-covariance to zero removes the correlation, so later updates do not propagate to or from the pose correctly, and the covariance is overconfident. The initialisation must include Jx Σxx Jxᵀ and the cross terms.
Question 3
After several hours the covariance of an EKF-SLAM run is tiny, but the map is visibly rotated relative to the building. What is the likely cause?
Explanation
The filter became overconfident about the unobservable global orientation because of linearisation error (spurious information gain). Its covariance claims a certainty that the data cannot give. Remedies: first-estimates Jacobians, consistent filter variants, or a different estimator (graph optimisation).
What’s next
Gaussian filters assume one hypothesis. The next lesson drops that assumption and represents the belief with samples.
Related content
Nothing below is required to finish this lesson. The last entry is a lesson of other courses on this site that teach the background or go further.
- BeforeM3-T6: Filtering-Based SLAM
State SLAM as recursive filtering over a joint pose-and-map state and explain why it scales poorly.
- LabM3-L5: Implement a Simplified EKF-SLAM
Complete the prediction and update steps of a landmark EKF-SLAM with known association.
- ProbabilityEKF Localization with Landmarks
The same filter with a known map: localization only, the step before EKF-SLAM.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.