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

Revision 651, 7.0 kB (checked in by mido, 15 years ago)

\doc directory cleaned a bit

Line 
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.9 -->
8<script type="text/javascript">
9<!--
10function 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}
22function 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}
46window.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&nbsp;Page</span></a></li>
53      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
54      <li><a href="annotated.html"><span>Classes</span></a></li>
55      <li><a href="files.html"><span>Files</span></a></li>
56    </ul>
57  </div>
58  <div class="navpath"><a class="el" href="dev_guide.html">BDM Use - in C++</a>
59  </div>
60</div>
61<div class="contents">
62<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>
63More advanced filtering algorithms for non-linear non-Gaussian models can be derived, see ...<h2><a class="anchor" name="klm">
64Kalman Filtering</a></h2>
65Kalman filtering is optimal estimation procedure for linear state space model: <p class="formulaDsp">
66<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">
67<p>
68 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>
69Both prior and posterior densities on the state are Gaussian, i.e. of the class enorm.<p>
70There is a range of classes that implements this functionality, namely:<ul>
71<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><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>
72<h2><a class="anchor" name="ekf">
73Extended Kalman Filtering</a></h2>
74Extended Kalman filtering arise by linearization of non-linear state space model: <p class="formulaDsp">
75<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">
76<p>
77 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>
78In order to use this class, the non-linear functions and their derivatives must be defined as an instance of class <code>diffbifn</code>.<p>
79Two classes are defined:<ul>
80<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>
81<h2><a class="anchor" name="exa">
82Examples of Use</a></h2>
83The 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>
84<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="kalman_8h.html" title="Bayesian Filtering for linear Gaussian models (Kalman Filter) and extensions.">estim/kalman.h</a>"</span>
85<span class="keyword">using namespace </span>bdm;
86
87<span class="comment">// estimation of AR(0) model</span>
88<span class="keywordtype">int</span> main() {
89        <span class="comment">//dimensions</span>
90        <span class="keywordtype">int</span> dx = 3, dy = 3, du = 1;
91        <span class="comment">// matrices</span>
92        mat A = eye ( dx );
93        mat B = zeros ( dx, du );
94        mat C = eye ( dx );
95        mat D = zeros ( dy, du );
96        mat Q = eye ( dx );
97        mat R = 0.1 * eye ( dy );
98        <span class="comment">//prior</span>
99        mat P0 = 100 * eye ( dx );
100        vec mu0 = zeros ( dx );
101        <span class="comment">// Estimator</span>
102        KalmanCh KF;
103        KF.set_parameters ( A, B, C, D,<span class="comment">/*covariances*/</span> Q, R );
104        KF.set_statistics ( mu0, P0 );
105        <span class="comment">// Estimation loop</span>
106        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; 100; i++ ) {
107                KF.bayes ( randn ( dx + du ) );
108        }
109        <span class="comment">//print results</span>
110        cout &lt;&lt; <span class="stringliteral">"Posterior estimate of x is: "</span>  &lt;&lt; endl;
111        cout &lt;&lt; <span class="stringliteral">"mean: "</span> &lt;&lt; KF.posterior().mean() &lt;&lt; endl;
112        cout &lt;&lt; <span class="stringliteral">"variance: "</span> &lt;&lt; KF.posterior().variance() &lt;&lt; endl;
113}
114</pre></div> </div>
115<hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 7 17:34:44 2009 for mixpp by&nbsp;
116<a href="http://www.doxygen.org/index.html">
117<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
118</body>
119</html>
Note: See TracBrowser for help on using the browser.