1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: Examples of (extended) Kalman filtering</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="navpath"><a class="el" href="manual.html">User Manual</a> |
---|
60 | </div> |
---|
61 | </div> |
---|
62 | <div class="contents"> |
---|
63 | <h1><a class="anchor" name="kalman">Examples of (extended) Kalman filtering </a></h1>Kalman filtering and Extended Kalman filtering are special cases of Bayesian filtering. The Kalman filter is optimal for linear state space model with Gaussian disturbances, the extended Kalman filter is derived as linearization of non-linear state space models with Gaussian noises. Hence it is only sub-optimal filter.<p> |
---|
64 | More advanced filtering algorithms for non-linear non-Gaussian models can be derived, see ...<h2><a class="anchor" name="klm"> |
---|
65 | Kalman Filtering</a></h2> |
---|
66 | Kalman filtering is optimal estimation procedure for linear state space model: <p class="formulaDsp"> |
---|
67 | <img class="formulaDsp" alt="\begin{eqnarray} x_t &= &A x_{t-1} + B u_{t} + v_t,\\ y_t &= &C x_{t} + D u_{t} + w_t, \end{eqnarray}" src="form_92.png"> |
---|
68 | <p> |
---|
69 | where <img class="formulaInl" alt="$ x_t $" src="form_93.png"> is the state, <img class="formulaInl" alt="$ y_t $" src="form_6.png"> is the system output, <img class="formulaInl" alt="$ A, B, C, D$" src="form_94.png"> are state matrices of appropriate dimensions, <img class="formulaInl" alt="$v_t, w_t$" src="form_95.png"> are zero mean Gaussian noises with covariance matrices <img class="formulaInl" alt="$Q, R$" src="form_96.png">, respectively.<p> |
---|
70 | Both prior and posterior densities on the state are Gaussian, i.e. of the class enorm.<p> |
---|
71 | There is a range of classes that implements this functionality, namely:<ul> |
---|
72 | <li><a class="el" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices (education purpose only)! Will be deleted...">bdm::KalmanFull</a> which implements the estimation algorithm on full matrices,</li><li><a class="el" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">bdm::KalmanCh</a> which implements the estimation algorithm using choleski decompositions and QR algorithm.</li></ul> |
---|
73 | <h2><a class="anchor" name="ekf"> |
---|
74 | Extended Kalman Filtering</a></h2> |
---|
75 | Extended Kalman filtering arise by linearization of non-linear state space model: <p class="formulaDsp"> |
---|
76 | <img class="formulaDsp" alt="\begin{eqnarray} x_t &= &g( x_{t-1}, u_{t}) + v_t,\\ y_t &= &h( x_{t} , u_{t}) + w_t, \end{eqnarray}" src="form_97.png"> |
---|
77 | <p> |
---|
78 | where <img class="formulaInl" alt="$ g(), h() $" src="form_98.png"> are general non-linear functions which have finite derivatives. Remaining variables have the same meaning as in the Kalman Filter.<p> |
---|
79 | In order to use this class, the non-linear functions and their derivatives must be defined as an instance of class <code>diffbifn</code>.<p> |
---|
80 | Two classes are defined:<ul> |
---|
81 | <li><a class="el" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">bdm::EKFfull</a> on full size matrices,</li><li><a class="el" href="classbdm_1_1EKFCh.html" title="Extended Kalman Filter in Square root.">bdm::EKFCh</a> on Choleski decompositions and using QR algorithm.</li></ul> |
---|
82 | <h2><a class="anchor" name="exa"> |
---|
83 | Examples of Use</a></h2> |
---|
84 | The classes can be used directly in C++ or via User Info. The latter example is illustrated in file estimator. A very short example of the former follows:<p> |
---|
85 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="libKF_8h.html" title="Bayesian Filtering for linear Gaussian models (Kalman Filter) and extensions.">estim/libKF.h</a>></span> |
---|
86 | <span class="keyword">using namespace </span>bdm; |
---|
87 | |
---|
88 | <span class="comment">// estimation of AR(0) model</span> |
---|
89 | <span class="keywordtype">int</span> main() { |
---|
90 | <span class="comment">//dimensions</span> |
---|
91 | <span class="keywordtype">int</span> dx=3, dy=3, du=1; |
---|
92 | <span class="comment">// matrices</span> |
---|
93 | mat A = eye(dx); |
---|
94 | mat B = zeros(dx,du); |
---|
95 | mat C = eye(dx); |
---|
96 | mat D = zeros(dy,du); |
---|
97 | mat Q = eye(dx); |
---|
98 | mat R = 0.1*eye(dy); |
---|
99 | <span class="comment">//prior</span> |
---|
100 | mat P0 = 100*eye(dx); |
---|
101 | vec mu0 = zeros(dx); |
---|
102 | <span class="comment">// Estimator</span> |
---|
103 | KalmanCh KF; |
---|
104 | KF.set_parameters(A,B,C,D,<span class="comment">/*covariances*/</span> Q,R); |
---|
105 | KF.set_statistics(mu0,P0); |
---|
106 | <span class="comment">// Estimation loop</span> |
---|
107 | <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i<100;i++){ |
---|
108 | KF.bayes(randn(dx+du)); |
---|
109 | } |
---|
110 | <span class="comment">//print results</span> |
---|
111 | cout << <span class="stringliteral">"Posterior estimate of x is: "</span> << endl; |
---|
112 | cout << <span class="stringliteral">"mean: "</span><< KF.posterior().mean()<< endl; |
---|
113 | cout << <span class="stringliteral">"variance: "</span><< KF.posterior().variance()<< endl; |
---|
114 | } |
---|
115 | </pre></div> </div> |
---|
116 | <hr size="1"><address style="text-align: right;"><small>Generated on Fri Mar 6 15:01:37 2009 for mixpp by |
---|
117 | <a href="http://www.doxygen.org/index.html"> |
---|
118 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
119 | </body> |
---|
120 | </html> |
---|