3.5.21Guidance, Navigation & Control (GNC)

Kalman filter derivation — predict step, update step

2,286 words10 min readdifficulty · medium6 backlinks

WHY does this exist?

In GNC you never observe the true state xx (position, velocity, attitude) directly. You have:

  • A model of how the state evolves ("if I fire the thruster, velocity increases by…") — but the model is imperfect.
  • Sensors (GPS, IMU, star tracker) — but they are noisy.

Neither alone is trustworthy. The Kalman filter answers: given a shaky prediction AND a shaky measurement, what is the single best estimate? The answer is a precision-weighted average, and the filter tracks not just the estimate but also how confident it is.


The core intuition: combining two Gaussians

Derivation of the 1-D fusion (from first principles)

Two independent Gaussians multiply. Their exponents add: (xa)22σa2(xb)22σb2.-\frac{(x-a)^2}{2\sigma_a^2} - \frac{(x-b)^2}{2\sigma_b^2}. Minimise over xx (the peak of a Gaussian = its mean). Differentiate, set to zero: xaσa2+xbσb2=0    x ⁣(1σa2+1σb2)=aσa2+bσb2.\frac{x-a}{\sigma_a^2} + \frac{x-b}{\sigma_b^2} = 0 \;\Rightarrow\; x\!\left(\tfrac{1}{\sigma_a^2}+\tfrac{1}{\sigma_b^2}\right) = \tfrac{a}{\sigma_a^2}+\tfrac{b}{\sigma_b^2}. Solve → the weighted average above. Why this step? The product of Gaussians is Gaussian, so finding its mean = finding where the log-likelihood is maximal.

Rewrite in "correction" form. Let K=σa2σa2+σb2K = \dfrac{\sigma_a^2}{\sigma_a^2+\sigma_b^2} (the gain): x^=a+K(ba),σ2=(1K)σa2.\hat x = a + K(b-a), \qquad \sigma^2 = (1-K)\sigma_a^2. This is the seed of the full Kalman update: old estimate + gain × (measurement − prediction).


PREDICT step (time update)

Mean. Take expectation of xk=Fxk1+Buk+wkx_k = Fx_{k-1}+Bu_k+w_k, with E[wk]=0\mathbb E[w_k]=0: x^k=Fx^k1+Buk\boxed{\hat x_k^- = F\hat x_{k-1} + B u_k}

Covariance. Define the prior error ek=xkx^ke_k^- = x_k - \hat x_k^-. Substitute: ek=(Fxk1+Buk+wk)(Fx^k1+Buk)=Fek1+wk.e_k^- = (Fx_{k-1}+Bu_k+w_k) - (F\hat x_{k-1}+Bu_k) = F e_{k-1} + w_k. Then Pk=E[ekek]=E[(Fek1+wk)(Fek1+wk)].P_k^- = \mathbb E[e_k^- e_k^{-\top}] = \mathbb E[(Fe_{k-1}+w_k)(Fe_{k-1}+w_k)^\top]. Expand. Cross terms vanish because wkw_k is independent of the previous error: Pk=FPk1F+Q\boxed{P_k^- = F P_{k-1} F^\top + Q}


UPDATE step (measurement update)

We have a prior (x^k,Pk)(\hat x_k^-, P_k^-) and a fresh measurement zkz_k. Correct the estimate.

Innovation (surprise): yk=zkHx^ky_k = z_k - H\hat x_k^- — how far the measurement is from what we predicted.

Corrected estimate: old + gain × surprise: x^k=x^k+Kkyk.\hat x_k = \hat x_k^- + K_k\, y_k.

Derive the gain KkK_k. We choose KkK_k to minimise the posterior error variance tr(Pk)\mathrm{tr}(P_k).

Posterior error: ek=xkx^ke_k = x_k - \hat x_k. Since zk=Hxk+vkz_k = Hx_k + v_k: ek=xkx^kKk(Hxk+vkHx^k)=(IKkH)ekKkvk.e_k = x_k - \hat x_k^- - K_k(Hx_k + v_k - H\hat x_k^-) = (I-K_kH)e_k^- - K_k v_k. Compute covariance (using eke_k^- independent of vkv_k): Pk=(IKkH)Pk(IKkH)+KkRKk.()P_k = (I-K_kH)P_k^-(I-K_kH)^\top + K_k R K_k^\top. \quad(\star) This is the Joseph form (always valid, numerically stable).

Minimise tr(Pk)\mathrm{tr}(P_k). Differentiate w.r.t. KkK_k and set to zero (using tr(KAK)/K=2KA\partial\,\mathrm{tr}(KAK^\top)/\partial K = 2KA): tr(Pk)Kk=2(IKkH)PkH+2KkR=0.\frac{\partial\,\mathrm{tr}(P_k)}{\partial K_k} = -2(I-K_kH)P_k^-H^\top + 2K_kR = 0. Solve: KkPkHH...Kk(HPkH+R)=PkHK_k P_k^- H^\top H^{... } \Rightarrow K_k(HP_k^-H^\top + R) = P_k^-H^\top Kk=PkH(HPkH+R)1\boxed{K_k = P_k^- H^\top (H P_k^- H^\top + R)^{-1}}

Simplify covariance. Substitute the optimal KkK_k into ()(\star) — the KRKKRK^\top term collapses: Pk=(IKkH)Pk\boxed{P_k = (I - K_k H)P_k^-}

Figure — Kalman filter derivation — predict step, update step

Worked examples


Common mistakes


Flashcards

What are the two Kalman predict equations?
x^=Fx^+Bu\hat x^- = F\hat x + Bu and P=FPF+QP^- = FPF^\top + Q.
Why does covariance grow in the predict step?
Because process noise QQ (unmodelled dynamics) is added; prediction can only reduce confidence.
Define the innovation.
yk=zkHx^ky_k = z_k - H\hat x_k^- = measurement minus predicted measurement (the "surprise").
Write the Kalman gain.
Kk=PkH(HPkH+R)1K_k = P_k^- H^\top (HP_k^-H^\top + R)^{-1}.
What is the innovation covariance SkS_k?
Sk=HPkH+RS_k = HP_k^-H^\top + R, the uncertainty of the innovation.
What criterion determines the optimal gain?
Minimising the trace of the posterior covariance PkP_k (mean-squared error).
Posterior covariance update (optimal KK)?
Pk=(IKkH)PkP_k = (I - K_kH)P_k^-.
If R0R \to 0 (perfect sensor), what happens to KK?
KH1K \to H^{-1}; the filter fully trusts the measurement.
If P0P^- \to 0 (perfect model), what happens to KK?
K0K \to 0; the filter ignores the measurement.
What is the Joseph form and when must you use it?
P=(IKH)P(IKH)+KRKP=(I-KH)P^-(I-KH)^\top + KRK^\top; use it for any non-optimal KK or for numerical stability.
The 1-D fusion of two Gaussians combines variances how?
Precisions add: 1/σ2=1/σa2+1/σb21/\sigma^2 = 1/\sigma_a^2 + 1/\sigma_b^2.
Setting Q=0Q=0 causes what failure mode?
Filter divergence — P0P^-\to0, K0K\to0, measurements ignored.

Recall Feynman: explain to a 12-year-old

Imagine you're guessing where your friend is walking. Your brain says "he was going that way, so he's probably here now" — but you're not sure. Then you glance and sort of see him — but your eyes are blurry too. So you make a smart guess between the two. If your glimpse was clear, you trust your eyes more; if it was really blurry, you trust your brain-guess more. The Kalman filter is a calculator that does exactly this blending — and it also keeps score of how sure it is, so next time it knows whether to trust its memory or its eyes.

Connections

Concept Map

imperfect, gives Q

noisy, gives R

linear Gaussian assumption

inverse-variance weighted avg

coast forward

grows uncertainty via Q

correct with z

weights prediction vs measurement

prior estimate

old + K times innovation

shrinks

Physics model F,Q

Noisy sensor H,R

State-space model

Fuse two Gaussians

Kalman gain K

Predict step

Update step

Best estimate x-hat

Covariance P

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Kalman filter ka core idea bahut simple hai: tumhare paas do "guesses" hain ek hidden state (jaise position ya velocity) ke baare mein. Ek guess aata hai tumhare physics model se — "pichli baar yahan tha, itni speed thi, toh ab yahan hoga" — ye hai predict step. Doosra guess aata hai sensor se (GPS, IMU) — lekin dono hi thode galat hain, dono mein noise hai. Kalman filter dono ko uncertainty ke hisaab se weight karke ek best estimate banata hai. Jiski variance chhoti (jo zyada bharosemand), usko zyada weight milta hai.

Predict step mein tum estimate ko aage badhate ho (x^=Fx^+Bu\hat x^- = F\hat x + Bu) aur uncertainty badha dete ho (P=FPF+QP^- = FPF^\top + Q), kyunki model perfect nahi hai — isliye +Q+Q. Update step mein tum measurement lete ho, innovation nikalte ho (y=zHx^y = z - H\hat x^- = surprise, matlab kitna galat tha prediction), aur Kalman gain KK se estimate ko correct karte ho. Gain ka formula K=PH/SK = P^-H^\top/S basically bolta hai "prior uncertainty divided by total uncertainty" — bilkul 1-D wale weighted average jaisa.

Sabse important intuition: agar sensor bahut accha hai (RR chhota), KK bada ho jaata hai, filter measurement pe zyada bharosa karta hai. Agar model bahut accha hai (PP^- chhota), KK chhota, filter apni prediction pe rehta hai. Aur ek common galti — kabhi Q=0Q=0 mat karo, warna filter sochta hai "mera model perfect hai" aur saare measurements ignore karke diverge kar jaata hai.

GNC mein ye filter har jagah use hota hai — rocket, drone, satellite ki position/attitude estimate karne ke liye. Real state kabhi directly nahi dikhta, toh Kalman filter noisy sensors aur imperfect model ko blend karke best estimate deta hai, saath mein confidence bhi track karta hai. Yaad rakho loop: Predict → Update → Predict → Update, chalta rehta hai.

Go deeper — visual, from zero

Test yourself — Guidance, Navigation & Control (GNC)

Connections