summaryrefslogtreecommitdiff
path: root/KalmanIntro.mdwn
blob: b9b2b52f614fc45d16cc46a7b9f3fe63eb7dd6a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# (Yet Another) Introduction to the Kalman Filter

[[(See also our mathematical notation page)|MathSymbols]]

**Introduction to the Kalman Filter**

1. [Basics](#ChapBasics)
2. Example
3. [Derivation](#ChapDerivation)
4. Complications
5. <dl>
  <dt>Todo</dt>
  <dd>Adaptive Kalman Filtering</dd>
</dl>

----

<a name="ChapBasics" id="ChapBasics"></a>

## Basics

Given a system model, an initial system state, and a sequence of noisy measurements, a Kalman filter can be constructed to produce a sequence of state estimates that are optimal in the sense that they minimize the expected square-error between the estimates and the true system state.

<a name="TblNum1" id="TblNum1"></a> **Summary of Kalman Filter Symbols**

<div>
  <table>
    <tbody>
      <tr>
        <td>
          <p><strong>Symbol</strong></p>
        </td>
        <td>
          <p><strong>Dimension</strong></p>
        </td>
        <td>
          <p><strong>Name</strong></p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>x</strong></p>
        </td>
        <td>
          <p>n&times;1</p>
        </td>
        <td>
          <p>system state vector</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><big>&Phi;</big> (Phi)</p>
        </td>
        <td>
          <p>n&times;n</p>
        </td>
        <td>
          <p>state transition matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>P</strong></p>
        </td>
        <td>
          <p>n&times;n</p>
        </td>
        <td>
          <p>state error covariance matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>u</strong></p>
        </td>
        <td>
          <p>u&times;1</p>
        </td>
        <td>
          <p>control input vector</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><big>&Gamma;</big> (Gamma)</p>
        </td>
        <td>
          <p>n&times;u</p>
        </td>
        <td>
          <p>control input matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>w</strong></p>
        </td>
        <td>
          <p>q&times;1</p>
        </td>
        <td>
          <p>process noise vector</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><big>&Lambda;</big> (Lambda)</p>
        </td>
        <td>
          <p>n&times;q</p>
        </td>
        <td>
          <p>process noise input matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>Q</strong></p>
        </td>
        <td>
          <p>q&times;q</p>
        </td>
        <td>
          <p>process noise covariance matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>y</strong></p>
        </td>
        <td>
          <p>m&times;1</p>
        </td>
        <td>
          <p>output vector</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>H</strong></p>
        </td>
        <td>
          <p>m&times;n</p>
        </td>
        <td>
          <p>output matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><big>&nu;</big> (nu)</p>
        </td>
        <td>
          <p>m&times;1</p>
        </td>
        <td>
          <p>measurement noise vector</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>R</strong></p>
        </td>
        <td>
          <p>m&times;m</p>
        </td>
        <td>
          <p>measurement noise covariance matrix</p>
        </td>
      </tr>
      <tr>
        <td>
          <p><strong>K</strong></p>
        </td>
        <td>
          <p>n&times;m</p>
        </td>
        <td>
          <p>Kalman gain, feedback matrix</p>
        </td>
      </tr>
      <tr>
        <td colspan=3 style="text-align: center">
          <p>Table (1)</p>
        </td>
      </tr>
    </tbody>
  </table>
</div>

<a name="TblNum2" id="TblNum2"></a> **Typical Kalman Filter Equations**

<div>
  <table>
    <tbody>
      <tr>
        <td>
          <p><strong>Equation</strong></p>
        </td>
        <td>
          <p><strong>Description</strong></p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{\hat x_0} = \it E[\bf{x_0}]$</p>
        </td>
        <td>
          <p><strong>state initialization</strong></p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{P_0} = \it E[(\bf{\hat x_0 - x_0})^2]$</p>
        </td>
        <td>
          <p><strong>state error initialization</strong></p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{x_k^-} = \bf{\Phi_{k-1} \hat x_{k-1} + \Gamma_{k-1} u_{k-1}}$</p>
        </td>
        <td>
          <p><strong>state propagation</strong><br> Previous knowledge of the system is used to guess the future state.</p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{P_k<sup>-} = \bf{\Phi_{k-1} P_{k-1} \Phi_{k-1}</sup>T + \Lambda_{k-1} Q_{k-1} \Lambda_{k-1}^T}$</p>
        </td>
        <td>
          <p><strong>state error propagation</strong><br> System dynamics effect the error. Process noise increases the error.</p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{K_k} = \bf{P_k<sup>-\, H_k</sup>T (H_k P_k<sup>-\, H_k</sup>T + R_k)^{-1}}$</p>
        </td>
        <td>
          <p><strong>Kalman gain update</strong><br> Recursive least squares solution, trades off state uncertainty and measurement noise.</p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{\hat x_k} = \bf{x_k<sup>- + K_k (\tilde y_k - H_k x_k</sup>-)}$</p>
        </td>
        <td>
          <p><strong>measurement update</strong><br> New optimal state estimate</p>
        </td>
      </tr>
      <tr>
        <td>
          <p>$\bf{P_k} = \bf{((P_k<sup>-)</sup>{-1} + H_k R_k<sup>{-1} H_k)</sup>{-1}}$</p>
        </td>
        <td>
          <p><strong>state error update</strong><br> new measurements add to knowledge of system, estimated error decreases</p>
        </td>
      </tr>
      <tr>
        <td colspan=2 style="text-align: center">
          <p>Table (2)</p>
        </td>
      </tr>
    </tbody>
  </table>
</div>

Start with the discreet linear dynamic system equation <a name="EqNum1Dot1" id="EqNum1Dot1"></a>

    #!latex (-)
      $$\displaystyle (1.1)\quad
        \bf{x_{k+1}} = \bf{\Phi_k\ x_k} + \bf{\Gamma_k} \bf{u_k} + \bf{\Lambda_k} \bf{w_k}
    $$

And the measurement equation <a name="EqNum1Dot2" id="EqNum1Dot2"></a>

    #!latex (-)
      $$\displaystyle (1.2)\quad
        \bf{\tilde y_k} = \bf{H_k} \bf{x_k} + \bf{\nu_k}
    $$

Where the subscript (·<sub>k</sub>) indicates the value at time (t<sub>k</sub>)

Although the form of the system equations would seem to apply only to strictly linear systems, as usual, various linearizations and quasi-non-linear techniques can be applied to extend the Kalman filter to a variety of real world non-linear problems.

Making some key assumptions will greatly simplify what follows.<br /> Assume that

- For each time step (k); (<big>Φ</big><sub>k</sub>), (<big>Γ</big><sub>k</sub>), (<big>Λ</big><sub>k</sub>), (**H**<sub>k</sub>) and (**u**<sub>k</sub>) are known without error
- Noise components (**w**<sub>k</sub>) and (<big>ν</big><sub>k</sub>) are uncorrelated Gaussian random sequences with zero mean
- The noise covariance matrices are known, (cov[**w**<sub>k</sub>]=**Q**<sub>k</sub>), (cov[<big>ν</big><sub>k</sub>]=**R**<sub>k</sub>)

In principle these assumptions can be relaxed somewhat. For example, if any of the system matrices contain random components, those components may be factored out into the noise vectors. Similarly, any noise process that is representable as a linear combination of white Gaussian noise can be modeled by adding extra states to the system and driving those extra states with zero mean Gaussian noise. Even if the noise matrices are not known exactly, they can be estimated, or calculated on line, or discovered by system tuning.

The exact quantity minimized by a Kalman filter is the matrix (**P**), the _state error covariance matrix_ <a name="EqNum1Dot3" id="EqNum1Dot3"></a>

    #!latex (-)
      $$\displaystyle (1.3)\quad
        \bf{P} \equiv \it{E}[\bf{(\hat x-x)}^2]
    $$

Where (_E_ ) is a function returning the expectation of a random variable

The estimated state ($\\bf\{\\hat x\}$) that minimizes (**P**) is found by solving a weighted least squares problem. The weights for the computation ultimately come from the process noise covariance matrix (**Q**) and the measurement noise covariance matrix (**R**). The actual output of the filter is a sequence of linear combinations formed from the predicted state (**x**<sup>\_</sup>), and the current measurements of the system ($\\bf\{\\tilde y\}$). Technically these outputs are known as the _best linear unbiased estimates_. The existence of such estimates is guaranteed only with certain restrictions, see the section on complications. (FIXME: complications section not built yet)

Typically the Kalman filter is implemented recursively as a _predictor-corrector_ system. In the prediction step, knowledge of the past state of the system is used to extrapolate to the system's state at the next time step. Once the next time step is actually reached and new measurements become available, the new measurements are used to refine the filter's estimate of the true state like this <a name="EqNum1Dot4" id="EqNum1Dot4"></a>

    #!latex (-)
      $$\displaystyle (1.4)\quad
        \bf{\hat x_k} = \bf{x_k^-} + \bf{K_k}(\bf{\tilde y_k}-\bf{H_k}\bf{x_k^-})
    $$

Where the matrix (**K**<sub>k</sub>), the _Kalman gain_, or _feedback matrix_ , is chosen so that (**P**<sub>k</sub>) is minimized

Later there will be some [justification](#EqNum3Dot14), but for now accept that one possible choice for (**K**<sub>k</sub>) is <a name="EqNum1Dot5" id="EqNum1Dot5"></a>

    #!latex (-)
      $$\displaystyle (1.5)\quad
        \bf{K_k} = \bf{P_k^-\, H_k^T (H_k P_k^-\, H_k^T + R_k)^{-1}}
                     = \bf{\frac {P_k^-\, H_k^T}{H_k P_k^-\, H_k^T + R_k}}
    $$

Where the _measurement noise covariance matrix_ (**R**<sub>k</sub>) is defined as <a name="EqNum1Dot6" id="EqNum1Dot6"></a>

    #!latex (-)
      $$\displaystyle (1.6) \quad
        \bf{R} \equiv \mbox{\rm cov}[\bf{\nu}] = \it E[\bf{\nu}^2]
    $$

The relative magnitudes of matrices (**R**<sub>k</sub>) and (**P**<sub>k</sub>) control a trade-off between the filter's use of predicted state estimate (**x**<sub>k</sub><sup>\_</sup>) and measurement ($\\bf\{\\tilde y\_k\}$).

Consider some limits on (**K**<sub>k</sub>) <a name="EqNum1Dot7" id="EqNum1Dot7"></a>

    #!latex (-)
      $$\displaystyle (1.7a)\quad
        \lim\limits_{\bf{R_k \to 0}} \bf{{P_k^-\, H_k^T} \over {H_k P_k^-\, H_k^T + R_k}}
            = \bf{H_k^{-1}}
    $$

    #!latex (-)
      $$\displaystyle (1.7b)\quad
            \lim\limits_{\bf{P_k \to 0}} \bf{{P_k^-\, H_k^T} \over {H_k P_k^-\, H_k^T + R_k}}
            = \bf 0
    $$

Substituting the first limit into the measurement update equation [(1.4)](#EqNum1Dot4) suggests that when the magnitude of (**R**) is small, meaning that the measurements are accurate, the state estimate depends mostly on the measurements. Likewise when the state is known accurately, then (**H P**<sup>-</sup> **H**<sup>T</sup>) is small compared to (**R**), and the filter mostly ignores the measurements relying instead on the prediction derived from the previous state (**x**<sub>k</sub><sup>\_</sup>).

----

<a name="ChapExample" id="ChapExample"></a>

## Example

(FIXME: no example yet)

----

<a name="ChapDerivation" id="ChapDerivation"></a>

## Derivation

The desired Kalman filter implementation is linear and recursive, that is, given the old filter state ($\{\\cal F\}\_\{k-1\}$) and new measurements ($\{\\cal M\}\_k$) the the new filter state is calculated as <a name="EqNum3Dot1" id="EqNum3Dot1"></a>

    #!latex (-)
      $$\displaystyle (3.1a)\quad
       {\cal F}_k^- = \it g [{\cal F}_{k-1}]
    $$

    #!latex (-)
      $$\displaystyle (3.1b)\quad
       {\cal F}_k = \it f [{\cal F}_k^-\,,\ {\cal M}_k]
    $$

Where ( _f_ and _g_ ) are linear functions

Referring to [table(2)](#TblNum2), the sequence of equations shown are both linear and recursive as desired. Though so far, little explanation has been given to justify their use. In order to maintain some credibility, and to prove we aren't total mathematical wimps, we will attempt a derivation of these equations. The goal here is not mathematical perfection, rather clarity without serious error.

Fundamentally Kalman filtering involves solving a least squares error problem. Specifically, given a state estimate (**x**<sup>\_</sup>) of known covariance (**P**<sup>-</sup>) and a new set of measurements ($\\bf\{\\tilde y\}$) with covariance (**R**), find a new state estimate ($\\bf\{\\hat x\}$) such that the new state error covariance (**P**) is minimized.

For the predicted state error write <a name="EqNum3Dot2" id="EqNum3Dot2"></a>

    #!latex (-)
      $$\displaystyle (3.2) \quad
        \bf \mbox{\rm cov}[\bf{x^- - x}] = \bf P^-
    $$

Likewise the measurement error is <a name="EqNum3Dot3" id="EqNum3Dot3"></a>

    #!latex (-)
      $$\displaystyle (3.3) \quad
        \bf \mbox{\rm cov}[\bf{\tilde y - y}] = \bf R
    $$

Seek a new state vector ($\\bf\{\\hat x\}$) such that the (n+m × 1) combined state error vector <a name="EqNum3Dot4" id="EqNum3Dot4"></a>

    #!latex (-)
      $$\displaystyle (3.4)\quad
        \pmatrix{ \bf I \cr \bf H } \bf{\hat x} - \pmatrix{ \bf x^- \cr \bf{\tilde y} }
    $$

Is minimized in the weighted least squares sense

The chief difficulty with Kalman filter theory is contained in [(3.4)](#EqNum3Dot4). The errors in [(3.2)](#EqNum3Dot2) and [(3.3)](#EqNum3Dot3) are defined in terms of the true state and exact measurements, but while operating the filter, all that is available are estimates and noisy measurements. In equation [(3.4)](#EqNum3Dot4) the measurement ($\\bf\{\\tilde y\}$) and the estimated state (**x**<sup>\_</sup>) have been used where the exact values would seem to be appropriate. Here's a simple-minded explanation of why it's ok to use the imprecise values in [(3.4)](#EqNum3Dot4): The noise has been assumed to be zero-mean, therefore the _expectation_ of the approximate values are the correct true values, so using the approximate values will produce unbiased estimates. Further, since it has been assumed that the covariance of both ($\\bf\{\\tilde y\}$) and (**x**<sup>\_</sup>) are known, the weighted least squares process has enough information to properly minimize the total square error.

Whether the previous paragraph constitutes a satisfactory justification of [(3.4)](#EqNum3Dot4) is a question worth pondering. If not there are many, many, many, books that address this issue (try looking up _stochastic least squares_). (However the chances of finding a very clear explanation appear to be low.) The issue is significant in as much as once [(3.4)](#EqNum3Dot4) is accepted, Kalman filtering as a theoretical matter is essentially solved. Though, solved in this sense is still far from a practical implementation. To derive a practical filter, some clever arithmetic is required.

A weighted least squares solution minimizes a scalar cost function ($\\cal\{J\})$, here written in matrix form <a name="EqNum3Dot5" id="EqNum3Dot5"></a>

    #!latex (-)
      $$\displaystyle (3.5)\quad
        \cal{J}[\bf \epsilon , \bf W] = \bf{\epsilon}^T \, \bf W \, \bf \epsilon
    $$

Where the matrix (**W**) is the weighting for the cost function. The weighting can be any positive definite matrix.

In formulating the Kalman filter the noise statistics have been defined in terms of covariance, and since elements with large covariance should be given low weight, the correct weighting matrix for this problem is the inverse of the covariance matrix. This is appealing intuitively and not too difficult to prove, though no proof is given here.

Using the inverse covariance as the weighting function and referring to [(3.4)](#EqNum3Dot4) the cost function for the Kalman filter is <a name="EqNum3Dot6" id="EqNum3Dot6"></a>

    #!latex (-)
      $$\displaystyle (3.6)\quad
        \cal{J} =
        \pmatrix{ \bf{I\, \hat x_k} - \bf{x_k^-} \cr
                  \bf{H_k \hat x_k} - \bf{\tilde y_k} }^{\rm T}
        \pmatrix{ \bf P_k^- & \bf 0  \cr  \bf 0 & \bf R_k }^{\rm -1}
        \pmatrix{ \bf{I \, \hat x_k} - \bf{x_k^-} \cr \bf{H_k \hat x_k} - \bf{\tilde y_k} }
    $$

Where the block matrices shown have dimensions (n+m × 1) and (n+m × n+m) respectively

Using the mapping suggested by [(3.4)](#EqNum3Dot4) <a name="EqNum3Dot7" id="EqNum3Dot7"></a>

    #!latex (-)
       $$\displaystyle (3.7)\quad
         \left\{
           \pmatrix{\bf I \cr \bf H_k}             \rightarrow          \bf H,\
           \bf{\hat x_k}                           \rightarrow    \bf{\hat x},\
           \pmatrix{\bf x_k^- \cr \bf{\tilde y_k}} \rightarrow  \bf{\tilde y},\
           \pmatrix{\bf P_k^- & 0 \cr 0 & \bf R_k} \rightarrow         \bf{R}
         \right\}
    $$

The cost function can be stated in a slightly more generic form as <a name="EqNum3Dot8" id="EqNum3Dot8"></a>

    #!latex (-)
      \begin{eqnarray*}
      (3.8)\quad
    \vphantom{\frac{0}{0}}
      \cal{J} &=& \bf{(H\,\hat x - \tilde y)^T\,R^{-1} (H\,\hat x - \tilde y})\cr
    \vphantom{\frac{0}{0}}
         &=& (\bf{\hat x^T \, H^T - \tilde y^T})\,\bf R^{-1} (\bf{H\,\hat x - \tilde y})\cr
    \vphantom{\frac{0}{0}}
         &=& (\bf{\hat x^T\,H^T - \tilde y^T}) (\bf{R^{-1}\,H\,\hat x - R^{-1}\,\tilde y})\cr
    \vphantom{\frac{0}{0}}
         &=& \bf{\hat x^T\,H^T\,R^{-1}\,H\,\hat x -
             \hat x^T\,H^T\,R^{-1}\,\tilde y - \tilde y^T\,R^{-1}\,H\,\hat x +
             \tilde y^T\,R^{-1}\,\tilde y}
      \end{eqnarray*}

In [(3.8)](#EqNum3Dot8) the cost function has been expanded in anticipation of taking derivatives. Note that a matrix derivative typically involves taking a transpose.

Returning to the generic minimization problem, take the partial derivative <a name="EqNum3Dot9" id="EqNum3Dot9"></a>

    #!latex (-)
      \begin{eqnarray*}
      (3.9)\quad
    \vphantom{\frac{0}{0}}
      \frac{\partial\cal{J}} {\partial\bf{\hat x}}
        &=& \bf{H^T\,R^{-1}\,H\,\hat x + (\hat x^T\,H^T\,R^{-1}\,H)^T
          - H^T\,R^{-1}\,\tilde y - (\tilde y^T\,R^{-1}\,H)^T}\cr
    \vphantom{\frac{0}{0}}
        &=& 2\ \bf{H^T\,R^{-1}\,H\,\hat x} - 2\ \bf{H^T\,R^{-1}\,\tilde y}\cr
      \end{eqnarray*}

Set the derivative to zero and solve for ($\\bf\{\\hat x\}$) <a name="EqNum3Dot10" id="EqNum3Dot10"></a>

    #!latex (-)
      $$\displaystyle (3.10)\quad
        \bf{\hat x} = \bf{(H^T\,R^{-1}\,H)^{-1}\,H^T\,R^{-1}\,\tilde y}
    $$

This is the classic weighted least squares solution.

Mapping [(3.10)](#EqNum3Dot10) back to our original problem using [(3.7)](#EqNum3Dot7) gets <a name="EqNum3Dot11" id="EqNum3Dot11"></a>

    #!latex (-)
      \begin{eqnarray*}
      (3.11)\quad
    \vphantom{\frac{0}{0}}
        \bf{\hat x_k} &=&
          \left(
            \pmatrix{\bf I \cr \bf H_k}^T \pmatrix{\bf P_k^- & \bf 0 \cr \bf 0 & \bf R_k}^{-1}
            \pmatrix{\bf I \cr \bf H_k}
          \right)^{-1}
          \pmatrix{\bf I \cr \bf H_k}^T \pmatrix{\bf P_k^- & \bf 0 \cr \bf 0 & \bf R_k}^{-1}
          \pmatrix{\bf x_k^- \cr \bf{\tilde y_k}}\cr
    \vphantom{\frac{0}{0}}
        &=& (\bf{P_k^-}^{-1}+\bf{H_k^T\,R_k^{-1}\,H_k})^{-1}
            (\bf{P_k^-}^{-1}\,\bf{x_k^- + H_k^T\,R_k^{-1}\,\tilde y_k})
      \end{eqnarray*}

There's nothing wrong with the form given in [(3.11)](#EqNum3Dot11), but for various reasons it's desirable to exhibit the measurement update form [(1.4)](#EqNum1Dot4). To do this everyone uses the _matrix inversion lemma_

<a name="EqNum3Dot12" id="EqNum3Dot12"></a>

    #!latex (-)
      $$\displaystyle (3.12)\quad
        \bf{(A-B^T\,C^{-1}\,B)^{-1} =
        A^{-1}-A^{-1}\,B^T(B\,A^{-1}B^T-C)^{-1}B\,A^{-1}}
    $$

Using the mapping <a name="EqNum3Dot13" id="EqNum3Dot13"></a>

    #!latex (-)
      $$\displaystyle (3.13)\quad
        \left\{
          \bf A  \rightarrow  \bf{P_k^-}^{-1},\ \
          \bf B  \rightarrow  \bf H_k        ,\ \
          \bf C  \rightarrow  -\bf R_k        \ \
        \right\}\
    $$

The solution given by [(3.11)](#EqNum3Dot11) becomes <a name="EqNum3Dot14" id="EqNum3Dot14"></a>

    #!latex (-)
      \begin{eqnarray*}
      (3.14)\quad
    \vphantom{\frac{0}{0}}
        \bf{\hat x_k} &=& \bf{
          (P_k^- - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,P_k^-)
          ({P_k^-}^{-1}\,x_k^- + H_k^T\,R_k^{-1}\,\tilde y_k)
        }\cr
    \vphantom{\frac{0}{0}}
          &=&\bf{
            P_k^-\,{P_k^-}^{-1}\,x_k^- + P_k^-\,H_k^T\,R_k^{-1}\,\tilde y_k
            - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,P_k^-\,{P_k^-}^{-1}\,x_k^- -
          }\cr
    \vphantom{\frac{0}{0}}
          & &\bf{
            P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,P_k^-\,H_k^T\,R_k^{-1}\,\tilde y_k
          }\cr
    \vphantom{\frac{0}{0}}
          &=&\bf{
            x_k^- - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,x_k^- -
          }\cr
    \vphantom{\frac{0}{0}}
          & &\bf{
            P_k^-\,H_k^T(I-(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,P_k^-\,H_k^T)R_k^{-1}\,\tilde y_k
          }\cr
    \vphantom{\frac{0}{0}}
         &=&\bf{
           x_k^- - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,x_k^-\ - P_k^-\,H_k^T \cdot
         }\cr
    \vphantom{\frac{0}{0}}
         & &\bf{
           \left(
             (H_k\,P_k^-\,H_k^T + R_k)^{-1}(H_k\,P_k^-\,H_k^T\ + R_k)
             - (H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,P_k^-\,H_k^T
           \right) \cdot
         }\cr
    \vphantom{\frac{0}{0}}
         & &\bf{R_k^{-1}\,\tilde y_k}\cr
    \vphantom{\frac{0}{0}}
         &=&\bf{
           x_k^- - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,x_k^- -
         }\cr
    \vphantom{\frac{0}{0}}
         & &\bf{
           P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}
           (H_k\,P_k^-\,H_k^T + R_k - H_k\,P_k^-\,H_k^T)R_k^{-1}\,\tilde y_k
         }\cr
    \vphantom{\frac{0}{0}}
         &=&\bf{
           x_k^- - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}H_k\,x_k^- -
         }\cr
    \vphantom{\frac{0}{0}}
         & &\bf{
           P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}R_k\,R_k^{-1}\,\tilde y_k
         }\cr
    \vphantom{\frac{0}{0}}
         &=&\bf{
           x_k^- - P_k^-\,H_k^T(H_k\,P_k^-\,H_k^T + R_k)^{-1}(H_k\,x_k^- - \tilde y_k)
         }\cr
    \vphantom{\frac{0}{0}}
         &=&\bf{
           x_k^- + K_k (\tilde y_k - H_k\,x_k^-)
         }\cr
      \end{eqnarray*}

Which matches the measurement update form given in [(1.4)](#EqNum1Dot4) with (**K**<sub>k</sub>) as in [(1.5)](#EqNum1Dot5)

It's possible to derive the state error update equation directly from the definition given in [(1.3)](#EqNum1Dot3) and repeated here

<a name="EqNum3Dot15" id="EqNum3Dot15"></a>

    #!latex (-)
      $$\displaystyle (3.15)\quad
        \bf{P} \equiv \it{E}[\bf{(\hat x-x)}^2]
    $$

It would be very convenient to write the true state (**x**<sub>k</sub>) in terms of ($\\bf\{\\hat x\_k\}$), in fact the previous hand-waving argument in support of equation [(3.4)](#EqNum3Dot4) implies this must be possible.

Using the mapping defined in [(3.7)](#EqNum3Dot7), the measurement equation is <a name="EqNum3Dot16" id="EqNum3Dot16"></a>

    #!latex (-)
      $$\displaystyle (3.16)\quad
        \bf{\tilde y = H\,x + \pmatrix{\bf{x_k^- - x_k} \cr \bf \nu}}
    $$

According to our least squares solution [(3.10)](#EqNum3Dot10) <a name="EqNum3Dot17" id="EqNum3Dot17"></a>

    #!latex (-)
      \begin{eqnarray*}
    \vphantom{\frac{0}{0}}
      (3.17)\quad
      \bf{\hat x}
        &=& \bf{(H^T\,R^{-1}\,H)^{-1} H^T\,R^{-1}\,\tilde y }\cr
    \vphantom{\frac{0}{0}}
        &=& \bf{(H^T\,R^{-1}\,H)^{-1}H^T\,R^{-1}}
            \left( \bf{H\,x + \pmatrix{\bf{x_k^- - x_k} \cr \bf \nu }} \right)\cr
    \vphantom{\frac{0}{0}}
        &=& \bf{x + (H^T\,R^{-1}\,H)^{-1} H^T\,R^{-1}\pmatrix{\bf{x_k^- - x_k} \cr \bf \nu }}\cr
      \end{eqnarray*}

Putting this into the definition for (**P**) <a name="EqNum3Dot18" id="EqNum3Dot18"></a>

    #!latex (-)
      \begin{eqnarray*}
      (3.18)\quad
    \vphantom{\frac{0}{0}}
        \bf P &=&
           \it{E}[(\bf{\hat x - x})^2]
        =  \it{E} \left[ \left(\bf{(H^T\,R^{-1}\,H)^{-1} H^T\,R^{-1}
           \pmatrix{\bf{x_k^- - x_k} \cr \bf \nu }}\right)^2 \right]\cr
    \vphantom{\frac{0}{0}}
        &=&\left( \bf{(H^T\,R^{-1}\,H)^{-1}H^T\,R^{-1}} \right)
           \it{E} \left[ \pmatrix{\bf{x_k^- - x_k} \cr \bf \nu }^2 \right]
           \left( \bf{(H^T\,R^{-1}\,H)^{-1}H^T\,R^{-1}} \right)^{\bf T}\cr
    \vphantom{\frac{0}{0}}
        &=&\bf{
           \left( (H^T\,R^{-1}\,H)^{-1}H^T\,R^{-1} \right)
           \,R\,
           \left( (H^T\,R^{-1}\,H)^{-1}H^T\,R^{-1} \right)^T
        }\cr
    \vphantom{\frac{0}{0}}
        &=& (\bf{H^T\,R^{-1} H})^{-1}\cr
      \end{eqnarray*}

Substituting back the values for (**H**) and (**R**) from [(3.7)](#EqNum3Dot7) <a name="EqNum3Dot19" id="EqNum3Dot19"></a>

    #!latex (-)
      \begin{eqnarray*}
      (3.19)\quad
    \vphantom{\frac{0}{0}}
      \bf P_k &=& \bf{
        \left(
          \pmatrix{\bf I \cr \bf H_k}^T \pmatrix{\bf P_k^- & \bf 0 \cr \bf 0 & \bf R_k}^{-1}
          \pmatrix{\bf I \cr \bf H_k}
        \right)^{-1}
      }\cr
    \vphantom{\frac{0}{0}}
        &=& (\bf{{P_k^-}^{-1} + H_k^T\,R_k^{-1} H_k})^{-1}\cr
      \end{eqnarray*}

Equation [(3.19)](#EqNum3Dot19) performs the "measurement update" for the state error estimate (**P**).

It can be written as a parallel sum <a name="EqNum3Dot20" id="EqNum3Dot20"></a>

    #!latex (-)
      $$\displaystyle (3.20)\quad
        \bf{ {1 \over P_k} = {1 \over P_k^-} + H_k^T {1 \over R_k} H_k }
    $$

The last term in [(3.20)](#EqNum3Dot20) can be considered to represent the extra information added to the state because of the current measurement.

The form of [(3.20)](#EqNum3Dot20) makes sense because adding new information (positive (**R**<sub>k</sub><sup>-1</sup>)) will tend to decrease the system uncertainty.

Now all that remains is to derive the state error propagation equation, again using definition [(1.3)](#EqNum1Dot3) <a name="#EqNum3Dot21"></a>

    #!latex (-)
      $$\displaystyle (3.21)\quad
        \bf P_{k+1}^- =
        \it{E} [ ( \bf{ x_{k+1}^- - x_{k+1} } )^2 ]
    $$

Applying the state propagation equation [(1.1)](#EqNum1Dot1) to the inside of [(3.21)](#EqNum3Dot21), the control input, being common, cancels out <a name="EqNum3Dot22" id="EqNum3Dot22"></a>

    #!latex (-)
      $$\displaystyle (3.22)\quad
        ( \bf{ x_{k+1}^- - x_{k+1} } ) =
          \bf{ \Phi_k (\hat x_k - x_k) + \Gamma_k (u_k - u_k) + \Lambda_k\,w_k) }
    $$

So <a name="EqNum3Dot23" id="EqNum3Dot23"></a>

    #!latex (-)
      $$\displaystyle (3.23)\quad
      \bf{P_{k+1}^-} =
            \it{E}[ \bf{ \Phi_k (\hat x_k - x_k)^2 \Phi_k^T + \Lambda_k\,w_k^2\,\Lambda_k^T +
            \Phi_k (\hat x_k - x_k) w_k^2\,\Lambda_k^T +
            \Lambda_k\,w_k (\hat x_k - x_k)^2 \Phi_k^T } ]
    $$

In [(3.23)](#EqNum3Dot23) the expectation of the cross terms is zero because (**x**<sub>k</sub>) contains terms of (**w**<sub>k-1</sub>) only, and by the assumption that (**w**) is white noise. <a name="EqNum3Dot24" id="EqNum3Dot24"></a>

    #!latex (-)
      $$\displaystyle (3.24)\quad
        \it{E}[ \bf{ w_k\,w_{k-1} } ] = \bf 0
    $$

So finally <a name="EqNum3Dot25" id="EqNum3Dot25"></a>

    #!latex (-)
      $$\displaystyle (3.25)\quad
      \bf{P_{k+1}^-} = \bf{ \Phi_k\,P_k\,\Phi_k^T + \Lambda_k\,Q_k\,\Lambda_k^T }
    $$

The derivation of the equations in [table(2)](#TblNum2) is now complete □