previous   this   next   contents   reference   index   search
A Discrete Kalman-Bucy Filtering Example

Introduction
Discrete Kalman-Bucy filtering and smoothing are important data analysis tools. A lot of time is spent designing these filters for all sorts of applications. The KBF program is a graphical user interface to a discrete Kalman-Bucy filtering and smoothing tool. This section contains a review an example filter constructed using KBF. This as an introduction both to discrete Kalman-Bucy filtering and the KBF program.

If you installed KBF in C:\KBF and you run the O-Matrix program C:\KBF\KBF.OMS, the KBF command window will be displayed. If you then load EXAMPLE.KBF file, the O-Matrix main window appear as follows: ``` ```
``` ``` The following table contains a brief description of the subwindows above. A more detailed description is contained in the other sections of this users manual.
 Name Description KBF COMMAND overall control of KBF NOTES brief description of the problem MEAS defines the measurement model TRAN defines the transition  model DATA some KBF input values SIM used to create simulated data Z1 Table table of first data column versus time index Z1 PLot plot of first data column versus time index State Table table of second state components versus time index State PLot plot of second state component versus time index

Fitting and Plotting
For this example, the State Table window contains the variable x2. The value for this variable is originally `-1e+300` because that is the bad data flag. In addition, the State Plot window is empty. ``` ``` Step 1: select the Fit button in the KBF COMMAND window and the following dialog will appear: ``` ```
``` ``` Step 2: select the Iterated smoother option and leave the Number of iterations field at 2. Then select the Ok button. ``` ``` Step 3: A dialog will be left on the screen reporting the results of the fit. Select the Close button in this dialog. ``` ``` If you now inspect the State Plot window, you will see the following plot: ``` ```
``` ``` If you inspect the Z1 Plot window, you will see the following plot: ``` ```
``` ``` This is the measurement values corresponding to the first component of the measurement vector. You can add a curve corresponding to the model for the expected value of the measurements as follows: ``` ``` Step 4: Select the Plot button in the KBF COMMAND window. The following dialog will appear: ``` ```
``` ``` Step 5: In this dialog make the following changes:,
 Old Value New Value Description z1 z1, h1 add variable corresponding to expected value for z1 na na, bl plot this variable using the color black ++ ++, so use a solid line to plot this variable
``` ``` The Z1 Plot window will now contain the following plot: ``` ```
Problem Statement
In the example, we measure the range from the ship to two shore stations at know locations. Our problem is to determine the location of the ship as a function of time. The following table defines some mathematical notation that we use to describe our filter:
 Name Description Dimension `A` position of first shore station 2 x 1 `B` position of second shore station 2 x 1 `S` position of the ship 2 x 1 `V` velocity of the ship 2 x 1 `r1` range from S to A 1 x 1 `r2` range from S to B 1 x 1
We include both the ships position and velocity in the state vector. This enable us to model the expected value of the data from the state vector and to model the expected change in the position as linear with respect to time. The corresponding state vector at time index `k` is ``` / S(1) \ x = | S(2) | | V(1) | \ V(2) /``` The KBF Notes window is used to store general comments about the particular Kalman-Bucy filter. The Notes window for our example is: ``` ```
Input Values
The following is a list of the KBF input values described in this section:
 Name Description `bad` bad data flag `xi` initial state estimate `Pi` covariance of initial state estimate `Z` matrix of measurement values
The following is a list of the rest of the KBF input values which are described in subsequent sections:
 Name Description `hk` expected measurement model `Rk` covariance of measurement noise `hk` model for expected measurement `Rk` covariance of measurement noise `gk` model for expected transition `Qk` covariance of transition noise
The bad data flag for our example is ` -1d+300` Before the Fit or Sim commands are executed, some of the variables are not yet defined. These variables appear in the Table windows with the value `-1e+300` and they do not appear in the Plot windows. The estimate for the value of the state vector at time index `k = 1` is ``` / S(1) \ / 50 \ xi = | S(2) | = | 0 | | V(1) | | 1 | \ V(2) / \ 0 /``` The accuracy of this initial estimate is specified by the covariance matrix ``` / 16 0 0 0 \ Pi = | 0 16 0 0 | | 0 0 1 0 | \ 0 0 0 1 /``` Note that because the matrix `Pi` is diagonal, the components of `xi` are independent. Using `delta` to denote the corresponding standard deviations, ``` delta S(1) = 4 delta S(2) = 4 delta V(1) = 1 delta V(2) = 1``` Neither of the measurement columns are modulo a base value so the corresponding field in the Data window is ` 0 0` The file ```      ``` KBF\DATA\TMP\DATA.VAL ``` ``` contains the values ``` 119.372 107.759 122.161 104.008 120.752 104.096 121.608 108.792 114.187 114.778 109.812 120.034 106.191 124.459 108.104 121.789 110.782 121.566 115.898 115.941``` The first column corresponding to the measurements for `r1` and the second column corresponds to the measurements for `r2`. The `k`th row corresponds to the measurements for the `k`th time point. ``` ``` The Data window for our example is: ``` ```
Measurement Model
Each Kalman-Bucy filter has a model that relates the state vector to the measurements. The general form of this model is ``` z = h (x ) + v k k k k``` where the last term is the mean zero random measurement noise. For our example, the covariance of the measurement noise is given by ``` / 4 0 \ R = | | k \ 0 4 /``` Note that because this matrix is diagonal, the components of the measurement noise are independent. Using `delta` to denote the corresponding standard deviations, ```      delta v (1) = 2             k      delta v (2) = 2             k ```The expected value of the measurements are modelled by ``` r1(x) = |S - A| __________________________________ = \/ [x(1) - A(1)]^2 + [x(2) - A(2)]^2 r2(x) = |S - B| __________________________________ = \/ [x(1) - B(1)]^2 + [x(2) - B(2)]^2 / r1(x) \ h(x) = | | \ r2(x) /``` (Note that we are able to drop the dependence of `h` on `k` for our example.) We use the notation `D_j` to denote the partial derivative with respect to the `j`th component of `x`. Using this notation and the fact that ``` d __ 1 -- \/ s = ---------- ds ___ 2 \/ s``` we obtain ``` D_1 r1(x) = [S(1) - A(1)] / r1(x) D_2 r1(x) = [S(2) - A(2)] / r1(x) D_3 r1(x) = 0 D_4 r1(x) = 0``` A similar formula holds for the partial derivatives of `r2(x)`. It follows that ``` d / D_1 r1(x) D_2 r1(x) D_3 r1(x) D_4 r1(x) \ -- h(x) = | | dx \ D_1 r2(x) D_2 r2(x) D_3 r2(x) D_4 r2(x) / / [S(1)-A(1)]/r1(x) [S(2)-A(2)]/r1(x) 0 0 \ = | | \ [S(1)-B(1)]/r2(x) [S(2)-B(2)]/r2(x) 0 0 / ``` This measurement model is specified by a function called `meas` in the Measurement window of the KBF program. The function `meas` has the following input and output:
 Name Description Dimension Type `k` time index 1 x 1 Input `xk` current state value 4 x 1 Input `hk` `h(xk)` 2 x 1 Output `dhk` derivative of `h(xk)` 2 x 4 Output `Rk` covariance of measurement noise 2 x 2 Output
The Measurement window for our example is: ``` ```
Transition Model
A Kalman-Bucy filter also has a model that relates the state vector at one time to its value at the next time. The general form of this model is ``` x = g (x ) + w k+1 k k k``` where the last term is the mean zero random transition noise. For our example, the covariance of the transition noise is given by ``` / 1 0 0 0 \ Q = | 0 1 0 0 | k | 0 0 .4 0 | \ 0 0 0 .4 /``` Note that because this matrix is diagonal, the components of the transition noise are independent. Using `delta` to denote the corresponding standard deviations, ```      delta w (1) = 1             k      delta w (2) = 1             k        __      delta w (3) = \/.4             k        __      delta w (4) = \/.4             k ```Let `Dt` spacing between time point in our example. The expected value of the next state vector as a function of the current is modelled as ``` / x(1) + x(3) Dt \ g(x) = | x(2) + x(4) Dt | | x(3) | \ x(4) /``` (Note that we are able to drop the dependence of `g` on `k` for our example.) It follows that ``` d / 1 0 Dt 0 \ -- g(x) = | 0 1 0 Dt | dx | 0 0 1 0 | \ 0 0 0 1 /``` This transition model is specified by a function called `tran` in the Transition window of the KBF program. The function `tran` has the following input and output:
 Name Description Dimension Type `k` time index 1 x 1 Input `xk` current state value 4 x 1 Input `gk` `g(xk)` 4 x 1 Output `dgk` derivative of `g(xk)` 4 x 4 Output `Qk` covariance of transition noise 4 x 4 Output
The Transition window for our example is: ``` ```