03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14.7. SEQUENTIAL NOISE REDUCTION OF REAL-TIME MEASUREMENTS BY LEAST SQUARES283<br />

we have, with gk = A T k bk, that<br />

A T k+1 Ak+1xk+1 = gk+1<br />

(A T k Ak + ak+1a T k+1 )xk+1 = gk + ak+1f(tk+1)<br />

With Mk = (A T k Ak) −1 ∈ R n×n , we derive from the Sherman-Morrison <strong>for</strong>mula, that<br />

and we also have that<br />

Mk+1 := (A T k Ak + ak+1a T k+1 )−1 = Mk − Mkak+1a T k+1 Mk<br />

1 + a T k+1 Mkak+1<br />

xk+1 = Mk+1(gk + ak+1f(tk+1)) = Mkgk + Mkak+1f(tk+1) − Mkak+1aT k+1<br />

1 + aT k+1Mkak+1 (Mkgk + Mkak+1f(tk+1))<br />

= xk +<br />

Mkak+1<br />

1 + aT k+1Mkak+1 (f(tk+1) − a T k+1xk) The Kalman method works as follows. We can use the LAPACK subroutine DGESV <strong>for</strong> com-<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

1. Solve Anxn = bn by taking the first n rows of A and b<br />

2. Let Mn = A−1 n A−T n<br />

3. For k = n + 1, . . . , m do:<br />

3.1. Compute the Kalman gain vector kk+1 = Mkak+1/(1 + aT k+1Mkak+1). 3.2. Update step: xk+1 = xk + kk+1(f(tk+1) − aT k+1xk). 3.3. Mk+1 = Mk − kkaT k+1Mk. puting A −1<br />

n .<br />

14.7.4 Software<br />

The goal is to write a function that computes the Kalman filter least squares. Because of the<br />

sequential character, we suggest to make a class with the following specifications:<br />

template <br />

class kalman {<br />

public:<br />

// Creation of the Kalman filter<br />

kalman( int n ) ;<br />

// Compute the first n observations and initialize the Kalman<br />

// filter (Steps 1 and 2 in the algorithm)<br />

// BaseFun is a binary functor.<br />

template <br />

void initialize( VIt t begin, VIt const& t end, BaseFun& base fun, F& f ) {<br />

...<br />

}<br />

template

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!