The Measurement window contains an O-Matrix function that defines the Measurement model for the study. The Measurement window is an O-Matrix editor and as such you can perform standard editing commands within the window and using the Edit option from the O-Matrix menu bar. A specification of the Measurement function follows:

The integer scalar k specifies the current time index. The double-precision column vector xk specifies the estimated State vector value, x , at time index k. The length of xk is the same as the length of the INITIAL STATE ESTIMATE in the Data window.

The input value of hk does not matter. Its output value is equal to the Measurement function h evaluated at the specified values for the State vector and time index; i.e.,
      h (x )
       k  k
It is as a double-precision column vector with length equal to the number of columns in the file specified below DATA VALUES in the Data window.

The input value of dhk does not matter. Its output value is equal to the derivative of the Measurement function h with respect the State vector; i.e.,
      --  h (x )
      dx   k  k
It is a double-precision matrix with the same number of rows as hk and the same number of columns as xk has rows.

The input value of Rk does not matter. Its output value is equal to the Measurement variance R at the specified time index; i.e.,
the variance of the noise in the measurements. It is a double-precision positive definite matrix with the same number of rows as hk.

Ignoring Data Values
If one of the elements of the output value of hk is equal to the bad value , the corresponding element of the Measurement vector at time index k is not used. This enables you to use a computable condition to ignore certain data values. It also enables you to plot data that is in the data file without having it included in the fitting process. Note that the bad value is a double precision value and you should use the double-precision exponential format to specify this value. For example, if the bad value is -1d300 or -1e300 in the Data window, you should use the same representation in the Measurement function to avoid roundoff error problems.

The following is a picture of the Measurement window for the example in EXAMPLE.KBF .

# location of the two shore stations
local A = {0., -100.}
local B = {0., +100.}
These statements define the variables A and B to be the locations of the two shore stations. Because they begin with the word local, the variables A and B can be accessed anywhere within the Measurement window and only within the Measurement window. Because they appear outside the meas function, they are only executed once, instead of every time the function meas is called.

function meas(k, xk, hk, dhk, Rk) begin
This line begins the definition of the O-Matrix meas function and specifies the name its parameters will have inside of the function.

# location of the ship
S = xk(1::2)
This statement sets S to the subvector consisting of the first two elements of the vector xk. This is the ship position that corresponds to the State vector value being xk.

# model for range to stations 1 and 2
# is the Eculidean distance to the ship
r1 = |S - A|
r2 = |S - B|
hk = {r1, r2}
The first statement sets r1 to the Euclidean distance between the ship location and the shore station A. This is equal to the square root of the sum of the squares of the vector difference between S and A. The second statement sets r2 to the Euclidean distance between the ship location and the shore station B. The third statement assign hk to the Measurement function value corresponding to State vector being xk.

# derivative of range model with
# respect to ship location
dr1 = (S - A)' / r1
dr2 = (S - B)' / r2
These statements set dr1 and dr2 to the derivative of r1 and r2 with respect to ship position. The values r1 and r2 are scalars, so there derivatives are row vectors (note that ' is the transpose operator in O-Matrix). The value r1 can be written as
     r1(S) = \/ (ship(1) - A(1))^2 + (ship(2) - A(2))^2 )
Taking the derivative of the expression on the right with respect to S(1) we have
     d           1           2 (S(1) - A(1))
     --------- = -  --------------------------------------
     d S(1)      2    ____________________________________
                    \/ (S(1) - A(1))^2 + (S(2) - A(2))^2 )
cancelling the factors of 2 and noting that the denominator is equal to r1 you obtain
     d            S(1) - A(1)
     --------- =  ---------- 
     d S(1)           r1
which is the first element of the two element row vector dr1 defined by the assignment statement above. A similar line of reasoning can be used to verify that second element of dr1 and both elements of dr2 are the derivatives claimed above.

# derivative of range model with respect
# to the state vector xk (note derivative
# with respect to speed is zero)
dhk = {[dr1, 0, 0], [dr2, 0, 0]}
This statement sets dhk to the derivative of hk with respect to the State vector xk. Note that the derivatives with respect to the velocity components are all zero.

# variance of measurement noise
Rk = diag({2d0, 2d0}^2)
This statement sets Rk to a double-precision diagonal matrix with two 2 along the diagonal.

This statement terminates the meas function definition.