02-kalman-filter.mdWork through these sequentially. Section A tests conceptual understanding, Section B builds a complete 1D filter from scratch, and Section C ties everything back to robot code parameters.
A1. The Kalman gain K is computed as K = P⁻Hᵀ(HP⁻Hᵀ + R)⁻¹.
What happens to K (and to the resulting state estimate) when:
- (a) The measurement is perfect: R → 0
- (b) The measurement is useless: R → ∞
- (c) We have no prior information at all: P⁻ → ∞
K = P⁻Hᵀ (HP⁻Hᵀ + 0)⁻¹ = P⁻Hᵀ (HP⁻Hᵀ)⁻¹
For 1D with H=1: K = P⁻ / P⁻ = 1
x̂ = x̂⁻ + 1 × (z - x̂⁻) = z
K = P⁻Hᵀ (HP⁻Hᵀ + ∞)⁻¹ → 0
x̂ = x̂⁻ + 0 × (z - x̂⁻) = x̂⁻
K = ∞ × (∞ + R)⁻¹ → 1 (∞ dominates the denominator)
x̂ = x̂⁻ + 1 × (z - x̂⁻) = z
A2. After a predict step, the covariance is P⁻ = 0.09 m². After an update step using
a measurement with noise R = 0.04 m², what is the posterior covariance P?
(Assume 1D, H = 1)
K = P⁻ / (P⁻ + R) = 0.09 / (0.09 + 0.04) = 0.09 / 0.13 ≈ 0.692
P = (1 - K) × P⁻ = (1 - 0.692) × 0.09 = 0.308 × 0.09 ≈ 0.0277 m²
σ_posterior = √0.0277 ≈ 0.166 m
1/P = 1/P⁻ + 1/R = 1/0.09 + 1/0.04 = 11.11 + 25.00 = 36.11
P = 1/36.11 ≈ 0.0277 m² ✓
A3. Explain in one sentence each the physical meaning of: (a) the innovation, (b) the innovation covariance S = HP⁻Hᵀ + R, (c) the condition when Mahalanobis gating rejects an update.
A4. The AMR shortcut adds the term min(cov_theta, 1e5) * delta_trans² to the lateral
variance at each prediction step. Under what robot motion scenario does this term become the
dominant contributor to lateral uncertainty growth?
A5. AMR does not read the pose.covariance field from the /odom ROS message. Why is
this a deliberate and reasonable engineering choice, rather than a bug?
A robot moves along a 1D corridor at approximately constant velocity. It carries a GPS receiver (noisy position measurements only — no velocity from GPS). You will run 3 complete predict/update cycles and track how the estimate evolves.
All matrices and initial conditions:
State vector: x̂ = [position (m), velocity (m/s)]ᵀ
Initial state: x̂₀ = [0.0, 0.5]ᵀ (start at 0 m, going 0.5 m/s)
Initial covariance:
P₀ = ┌ 1.0 0.0 ┐ (σ_x = 1.0 m, σ_v = 0.2 m/s, uncorrelated)
│ 0.0 0.04┘
Time step: Δt = 1.0 s
State transition:
F = ┌ 1 1.0 ┐ (position += velocity × Δt)
│ 0 1.0 ┘ (velocity unchanged)
Process noise:
Q = ┌ 0.1 0.0 ┐ (small model uncertainty)
│ 0.0 0.01┘
Measurement matrix: H = [1 0] (GPS measures position only)
Measurement noise: R = [0.5] (σ_GPS = √0.5 ≈ 0.707 m)
Measurements:
z₁ = 0.4 m (at t = 1s)
z₂ = 1.1 m (at t = 2s)
z₃ = 1.6 m (at t = 3s)
For each cycle k = 1, 2, 3, compute:
x̂⁻ₖ = F x̂ₖ₋₁ and P⁻ₖ = F Pₖ₋₁ Fᵀ + Qνₖ = zₖ - H x̂⁻ₖSₖ = H P⁻ₖ Hᵀ + RKₖ = P⁻ₖ Hᵀ Sₖ⁻¹x̂ₖ = x̂⁻ₖ + Kₖ νₖPₖ = (I - Kₖ H) P⁻ₖFill in the table:
| Step | x̂_pos | x̂_vel | P_xx | P_vv | ν | K_pos |
|---|---|---|---|---|---|---|
| 0 (init) | 0.0 | 0.5 | 1.00 | 0.04 | — | — |
| 1 predict | ? | ? | ? | ? | — | — |
| 1 update | ? | ? | ? | ? | ? | ? |
| 2 predict | ? | ? | ? | ? | — | — |
| 2 update | ? | ? | ? | ? | ? | ? |
| 3 predict | ? | ? | ? | ? | — | — |
| 3 update | ? | ? | ? | ? | ? | ? |
x̂⁻₁ = F x̂₀ = ┌1 1┐ ┌0.0┐ = ┌0.0 + 1×0.5┐ = ┌0.5┐
│0 1┘ │0.5┘ │0.0 + 1×0.5┘ │0.5┘
F P₀ = ┌1 1┐ ┌1.00 0.0 ┐ = ┌1.00+0.04 0.04 ┐ = ┌1.04 0.04┐
│0 1┘ │0.0 0.04┘ │0.00+0.04 0.04 ┘ │0.04 0.04┘
F P₀ Fᵀ = ┌1.04 0.04┐ ┌1 0┐ = ┌1.04+0.04 0.04┐ = ┌1.08 0.04┐
│0.04 0.04┘ │1 1┘ │0.04+0.04 0.04┘ │0.04 0.04┘
P⁻₁ = F P₀ Fᵀ + Q = ┌1.08+0.1 0.04 ┐ = ┌1.18 0.04┐
│0.04 0.04+0.01┘ │0.04 0.05┘
ν₁ = z₁ - H x̂⁻₁ = 0.4 - [1 0]×[0.5, 0.5]ᵀ = 0.4 - 0.5 = -0.1 m
S₁ = H P⁻₁ Hᵀ + R = [1 0]┌1.18 0.04┐[1]ᵀ + [0.5] = 1.18 + 0.5 = 1.68
│0.04 0.05┘[0]
K₁ = P⁻₁ Hᵀ S₁⁻¹ = ┌1.18┐ × (1/1.68) = ┌0.702┐
│0.04┘ │0.024┘
x̂₁ = x̂⁻₁ + K₁ ν₁ = ┌0.5┐ + ┌0.702┐ × (-0.1) = ┌0.5 - 0.0702┐ = ┌0.430┐
│0.5┘ │0.024┘ │0.5 - 0.0024┘ │0.498┘
I - K₁H = ┌1 0┐ - ┌0.702┐[1 0] = ┌1-0.702 0┐ = ┌0.298 0┐
│0 1┘ │0.024┘ │0-0.024 1┘ │-0.024 1┘
P₁ = (I - K₁H) P⁻₁ = ┌0.298 0 ┐ ┌1.18 0.04┐
│-0.024 1 ┘ │0.04 0.05┘
= ┌0.298×1.18 0.298×0.04 ┐ = ┌0.352 0.012┐
│-0.024×1.18+0.04 -0.024×0.04+0.05┘ │0.012 0.049┘
x̂⁻₂ = F x̂₁ = ┌1 1┐ ┌0.430┐ = ┌0.430 + 0.498┐ = ┌0.928┐
│0 1┘ │0.498┘ │0.498 ┘ │0.498┘
F P₁ = ┌1 1┐ ┌0.352 0.012┐ = ┌0.352+0.012 0.012+0.049┐ = ┌0.364 0.061┐
│0 1┘ │0.012 0.049┘ │0.012 0.049 ┘ │0.012 0.049┘
F P₁ Fᵀ = ┌0.364 0.061┐ ┌1 0┐ = ┌0.364+0.061 0.061┐ = ┌0.425 0.061┐
│0.012 0.049┘ │1 1┘ │0.012+0.049 0.049┘ │0.061 0.049┘
P⁻₂ = ┌0.425+0.1 0.061 ┐ = ┌0.525 0.061┐
│0.061 0.049+0.01┘ │0.061 0.059┘
ν₂ = 1.1 - [1 0]×[0.928, 0.498]ᵀ = 1.1 - 0.928 = 0.172 m
S₂ = 0.525 + 0.5 = 1.025
K₂ = ┌0.525┐ / 1.025 = ┌0.512┐
│0.061┘ │0.060┘
x̂₂ = ┌0.928┐ + ┌0.512┐ × 0.172 = ┌0.928 + 0.088┐ = ┌1.016┐
│0.498┘ │0.060┘ │0.498 + 0.010┘ │0.508┘
P₂ ≈ (1 - 0.512) × 0.525 = 0.488 × 0.525 ≈ 0.256 m² (P_xx approx)
P_vv ≈ 0.059 - 0.060×0.061 ≈ 0.055 (m/s)²
x̂⁻₃ = ┌1.016 + 0.508┐ = ┌1.524┐
│0.508 ┘ │0.508┘
P⁻₃ ≈ ┌0.256 + 0.055 + 0.1 ...┐ ≈ ┌0.411 ...┐
│... 0.065 ┘ │... 0.065┘
(Using simplified scalar update for P_xx: new_xx ≈ old_xx + old_vv + Q_xx)
ν₃ = 1.6 - 1.524 = 0.076 m
S₃ = 0.411 + 0.5 = 0.911
K₃ = 0.411 / 0.911 = 0.451
x̂₃_pos = 1.524 + 0.451 × 0.076 = 1.524 + 0.034 = 1.558 m
x̂₃_vel ≈ 0.508 (very little update from GPS, which only measures position)
P₃_xx = (1 - 0.451) × 0.411 = 0.549 × 0.411 ≈ 0.226 m²
Cycle P_xx (after update) σ_x
1 0.352 0.593 m
2 0.256 0.506 m
3 0.226 0.476 m
Given:
- Current P(x,x) = 0.0025 m² (σ_x = 0.05 m, a tight estimate after a line-sensor hit)
- P(θ,θ) = 0.0010 rad² (σ_θ ≈ 1.8°, well-constrained heading)
- Robot moves forward delta_trans = 0.5 m in this time step
- delta_rot = 0.0 rad (straight-line motion)
- AMR noise parameters:
- k_trans_noise = 0.01
- k_trans_lat_noise = 0.005
- k_time_trans_noise = 0.0 (ignore time component)
- No measurement update this step
Question: What is P(x,x) after the prediction step?
(Assume the robot is driving along the x-axis so “longitudinal” ≈ x and “lateral” ≈ y.)
ΔP(x,x) = k_trans_noise × delta_trans
+ min(P_θθ, 1e5) × delta_trans²
= 0.01 × 0.5
+ min(0.0010, 1e5) × 0.5²
= 0.005
+ 0.0010 × 0.25
= 0.005 + 0.00025
= 0.00525 m²
P(x,x)_new = P(x,x)_old + ΔP(x,x)
= 0.0025 + 0.00525
= 0.00775 m²
σ_x_new = √0.00775 ≈ 0.088 m
Question: For a 1D filter with measurement matrix H = [1] (direct position measurement),
what is the minimum ratio P⁻ / R such that the Kalman gain K > 0.5?
Derive algebraically and verify with a numerical example using R = 0.04 m² (σ = 0.2 m,
typical line-sensor uncertainty).
K = P⁻ Hᵀ (H P⁻ Hᵀ + R)⁻¹
For H = 1 (1D):
K = P⁻ / (P⁻ + R)
Set K > 0.5:
P⁻ / (P⁻ + R) > 0.5
P⁻ > 0.5 × (P⁻ + R)
P⁻ > 0.5 P⁻ + 0.5 R
0.5 P⁻ > 0.5 R
P⁻ > R
P⁻ = 0.03 m² (< R): K = 0.03 / (0.03 + 0.04) = 0.03/0.07 = 0.429 < 0.5 ✓
P⁻ = 0.04 m² (= R): K = 0.04 / 0.08 = 0.500 = 0.5 (boundary) ✓
P⁻ = 0.05 m² (> R): K = 0.05 / 0.09 = 0.556 > 0.5 ✓
P⁻ = 0.10 m² (> R): K = 0.10 / 0.14 = 0.714 > 0.5 ✓
Back to main notes: 02-kalman-filter.md
Next exercises: 03-measurement-models-exercises.md