|
Contents | Previous | Next | Subchapters |
| Syntax |
kalman(xin, Pin, z, R, Phi, Q, H, xout, Pout) |
| See Also | itrsmo , affinekbs , filter |
If all of the input variables have the same type,
the output values xout and Pout will have that
type and all of the calculations will be done in the corresponding precision.
The input value xout has no effect.
Its output value is set to the expected value of the state vector
at the new time (given the value of the measurement z).
The input value of Pout has no effect.
Its output value is set to the covariance of xout
as an estimate of the state at the new time.
Let xinitial and xnew denote the
true value of the state vector at the initial and new times, respectively.
The transition model is
xnew = Phi xinitial + w,
where w is a mean zero random variable with covariance Q.
The measurement model is
z = H xnew + v,
where v is a mean zero random variable with covariance R.
If the estimate xin and the random variables
w and v are independent and normally distributed,
the state estimate xout is the maximum likelihood estimate
for the state. In this case, the estimate xout
is normally distributed and Pout is its covariance matrix.
kalman to advance
the state estimate and its covariance two time steps.
The example is included as one program below to make it easier to
copy and paste into the O-Matrix command line.
A
discussion
of the example follows the program
clear
xinitial = {10., 10., 1., 1.}
alpha = 2.
Pin = alpha^2 * identity(4)
u = alpha * snormal(4, 1)
xin = xinitial + u
dt = 1.
Phi = {[1., 0., dt, 0.], ...
[0., 1., 0., dt], ...
[0., 0., 1., 0.], ...
[0., 0., 0., 1.] ...
}
beta = 1.
Q = beta^2 * identity(4)
w = beta * snormal(4, 1)
xnew = Phi * xinitial + w
H = {[1., 0., 0., 0.], ...
[0., 1., 0., 0.] ...
}
gamma = .5
R = gamma^2 * identity(2)
v = gamma * snormal(2, 1)
z = H * xnew + v
xout = novalue
Pout = novalue
kalman(xin, Pin, z, R, Phi, Q, H, xout, Pout)
print [xnew, xout]
xinitial = xnew
xin = xout
Pin = Pout
beta = .01
Q = beta^2 * identity(4)
w = beta * snormal(4, 1)
xnew = Phi * xinitial + w
gamma = .01
R = gamma^2 * identity(2)
v = gamma * snormal(2, 1)
z = H * xnew + v
kalman(xin, Pin, z, R, Phi, Q, H, xout, Pout)
print [xnew, xout]
Discussion
clear
For simulation purposes,
the true initial location is 10 units east and 10 units north,
and the initial velocity is northeast with a speed of sqrt(2):
xinitial = {10., 10., 1., 1.}
The components of the initial state estimate are independent and each
has a standard deviation alpha.
We simulate noise u,
with the corresponding covariance Pin,
and the initial state estimate xin, by entering
alpha = 2.
Pin = alpha^2 * identity(4)
u = alpha * snormal(4, 1)
xin = xinitial + u
The model for the new position is the old position plus the velocity
times the time step dt, plus noise.
The model for the new velocity is the old velocity plus noise.
The corresponding transition matrix, Phi, is
dt = 1.
Phi = {[1., 0., dt, 0.], ...
[0., 1., 0., dt], ...
[0., 0., 1., 0.], ...
[0., 0., 0., 1.] ...
}
The east and north components of the noise in the transition model are
independent and each has standard deviation beta.
We simulate noise, w,
with the corresponding covariance Q,
and the true state value at the new time xnew, by entering
beta = 1.
Q = beta^2 * identity(4)
w = beta * snormal(4, 1)
xnew = Phi * xinitial + w
The measurement has two independent components.
The first is the east position and the second is the north position.
The corresponding measurement matrix H, is
H = {[1., 0., 0., 0.], ...
[0., 1., 0., 0.] ...
}
The measurement noise is independent and each component has standard
deviation gamma.
We simulate noise v with the corresponding covariance R,
and the measurement z, by entering
gamma = .5
R = gamma^2 * identity(2)
v = gamma * snormal(2, 1)
z = H * xnew + v
In an actual tracking problem the noise values
u, v, and w and true state values
xinitial and xnew are not known.
We estimate the new state vector xnew by
xout = novalue
Pout = novalue
kalman(xin, Pin, z, R, Phi, Q, H, xout, Pout)
We can compare the true value xnew, and its estimate xout,
by entering
print [xnew, xout]
to which O-Matrix will respond
{
[ 10.456 , 10.8956 ]
[ 11.7081 , 11.0963 ]
[ -0.588691 , 2.18574 ]
[ 1.4681 , 2.66793 ]
}
The first two components of xout are the estimates of
east and north position.
The second two components are estimates of east and north velocity.
You will notice that the estimates of position are better than
the estimates of velocity.
This is because we are measuring position directly and are
inferring the velocity through the transition equation.
We begin another time step by advancing the true position,
the estimated position, and the covariance of the estimate.
xinitial = xnew
xin = xout
Pin = Pout
Next we simulate a transition with much smaller error
beta = .01
Q = beta^2 * identity(4)
w = beta * snormal(4, 1)
xnew = Phi * xinitial + w
Next we simulate a measurement with much smaller error
gamma = .01
R = gamma^2 * identity(2)
v = gamma * snormal(2, 1)
z = H * xnew + v
Then we compute our new estimate and compare it to the
true value by entering
kalman(xin, Pin, z, R, Phi, Q, H, xout, Pout)
print [xnew, xout]
to which O-Matrix will respond
{
[ 9.88414 , 9.89429 ]
[ 13.1767 , 13.1708 ]
[ -0.602134 , 0.746347 ]
[ 1.48339 , 2.02662 ]
}