root/library/doc/html/kalman.html @ 616

Revision 616, 7.3 kB (checked in by smidl, 15 years ago)

doc, sorted related pages

Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>mixpp: Examples of (extended) Kalman filtering</title>
6<link href="tabs.css" rel="stylesheet" type="text/css"/>
7<link href="doxygen.css" rel="stylesheet" type="text/css"/>
8</head>
9<body>
10<!-- Generated by Doxygen 1.6.1 -->
11<script type="text/javascript">
12<!--
13function changeDisplayState (e){
14  var num=this.id.replace(/[^[0-9]/g,'');
15  var button=this.firstChild;
16  var sectionDiv=document.getElementById('dynsection'+num);
17  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
18    sectionDiv.style.display='block';
19    button.src='open.gif';
20  }else{
21    sectionDiv.style.display='none';
22    button.src='closed.gif';
23  }
24}
25function initDynSections(){
26  var divs=document.getElementsByTagName('div');
27  var sectionCounter=1;
28  for(var i=0;i<divs.length-1;i++){
29    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
30      var header=divs[i];
31      var section=divs[i+1];
32      var button=header.firstChild;
33      if (button!='IMG'){
34        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
35        button=document.createElement('img');
36        divs[i].insertBefore(button,divs[i].firstChild);
37      }
38      header.style.cursor='pointer';
39      header.onclick=changeDisplayState;
40      header.id='dynheader'+sectionCounter;
41      button.src='closed.gif';
42      section.id='dynsection'+sectionCounter;
43      section.style.display='none';
44      section.style.marginLeft='14px';
45      sectionCounter++;
46    }
47  }
48}
49window.onload = initDynSections;
50-->
51</script>
52<div class="navigation" id="top">
53  <div class="tabs">
54    <ul>
55      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
56      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
57      <li><a href="annotated.html"><span>Classes</span></a></li>
58      <li><a href="files.html"><span>Files</span></a></li>
59    </ul>
60  </div>
61  <div class="navpath"><a class="el" href="dev_guide.html">Howto Use BDM in C++ for your needs</a>
62  </div>
63</div>
64<div class="contents">
65
66
67<h1><a class="anchor" id="kalman">Examples of (extended) Kalman filtering </a></h1><p>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>
68<p>More advanced filtering algorithms for non-linear non-Gaussian models can be derived, see ...</p>
69<h2><a class="anchor" id="klm">
70Kalman Filtering</a></h2>
71<p>Kalman filtering is optimal estimation procedure for linear state space model: </p>
72<p class="formulaDsp">
73<img class="formulaDsp" alt="\begin{eqnarray} x_t &amp;= &amp;A x_{t-1} + B u_{t} + v_t,\\ y_t &amp;= &amp;C x_{t} + D u_{t} + w_t, \end{eqnarray}" src="form_119.png"/>
74</p>
75<p> where <img class="formulaInl" alt="$ x_t $" src="form_120.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_121.png"/> are state matrices of appropriate dimensions, <img class="formulaInl" alt="$v_t, w_t$" src="form_122.png"/> are zero mean Gaussian noises with covariance matrices <img class="formulaInl" alt="$Q, R$" src="form_123.png"/>, respectively.</p>
76<p>Both prior and posterior densities on the state are Gaussian, i.e. of the class enorm.</p>
77<p>There is a range of classes that implements this functionality, namely:</p>
78<ul>
79<li><a class="el" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices.">bdm::KalmanFull</a> which implements the estimation algorithm on full matrices,</li>
80<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>
81</ul>
82<h2><a class="anchor" id="ekf">
83Extended Kalman Filtering</a></h2>
84<p>Extended Kalman filtering arise by linearization of non-linear state space model: </p>
85<p class="formulaDsp">
86<img class="formulaDsp" alt="\begin{eqnarray} x_t &amp;= &amp;g( x_{t-1}, u_{t}) + v_t,\\ y_t &amp;= &amp;h( x_{t} , u_{t}) + w_t, \end{eqnarray}" src="form_124.png"/>
87</p>
88<p> where <img class="formulaInl" alt="$ g(), h() $" src="form_125.png"/> are general non-linear functions which have finite derivatives. Remaining variables have the same meaning as in the Kalman Filter.</p>
89<p>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>
90<p>Two classes are defined:</p>
91<ul>
92<li><a class="el" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">bdm::EKFfull</a> on full size matrices,</li>
93<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>
94</ul>
95<h2><a class="anchor" id="exa">
96Examples of Use</a></h2>
97<p>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>
98<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;<a class="code" href="kalman_8h.html" title="Bayesian Filtering for linear Gaussian models (Kalman Filter) and extensions.">estim/kalman.h</a>&quot;</span>
99<span class="keyword">using namespace </span>bdm;
100
101<span class="comment">// estimation of AR(0) model</span>
102<span class="keywordtype">int</span> main() {
103        <span class="comment">//dimensions</span>
104        <span class="keywordtype">int</span> dx = 3, dy = 3, du = 1;
105        <span class="comment">// matrices</span>
106        mat A = eye ( dx );
107        mat B = zeros ( dx, du );
108        mat C = eye ( dx );
109        mat D = zeros ( dy, du );
110        mat Q = eye ( dx );
111        mat R = 0.1 * eye ( dy );
112        <span class="comment">//prior</span>
113        mat P0 = 100 * eye ( dx );
114        vec mu0 = zeros ( dx );
115        <span class="comment">// Estimator</span>
116        KalmanCh KF;
117        KF.set_parameters ( A, B, C, D,<span class="comment">/*covariances*/</span> Q, R );
118        KF.set_statistics ( mu0, P0 );
119        <span class="comment">// Estimation loop</span>
120        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; 100; i++ ) {
121                KF.bayes ( randn ( dx + du ) );
122        }
123        <span class="comment">//print results</span>
124        cout &lt;&lt; <span class="stringliteral">&quot;Posterior estimate of x is: &quot;</span>  &lt;&lt; endl;
125        cout &lt;&lt; <span class="stringliteral">&quot;mean: &quot;</span> &lt;&lt; KF.posterior().mean() &lt;&lt; endl;
126        cout &lt;&lt; <span class="stringliteral">&quot;variance: &quot;</span> &lt;&lt; KF.posterior().variance() &lt;&lt; endl;
127}
128</pre></div> </div>
129<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Sep 13 23:08:55 2009 for mixpp by&nbsp;
130<a href="http://www.doxygen.org/index.html">
131<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
132</body>
133</html>
Note: See TracBrowser for help on using the browser.