Fundamentals of Kalman Filtering
Fundamentals of Kalman Filtering
Christopher DSouza
[email protected]
20 March 2013
Outline
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 3 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Why Estimate?
What Do We
Estimate?
A Brief History
of Estimation
Modern Estimation
and Rudolf Kalman
Rudolf Kalman
and His Filter
In 1960 Kalman wrote a paper in an obscure ASME journal
entitled A New Approach to Linear Filtering and Prediction
Problems which might have died on the vine, except:
In 1961, Stanley Schmidt of NASA Ames read the paper and
invited Kalman to give a seminar at Ames
Schmidt recognized the importance of this new theory and
applied it to the problem of on-board navigation of a lunar
vehicle after all this was the beginning of Apollo
This became known as the Kalman Filter
Kalmans paper was rather obtuse in its nomenclature and
mathematics
It took Schmidts exposition to show that this filter could be
easily mechanized and applied to a real problem
The Kalman Filter became the basis for the on-board
navigation filter on the Apollo CSM and LM
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 7 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Types of Estimation
Types of Sensors
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 10 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Claude Shannon
Concepts from
Probability Theory
A random variable is one whose value is subject to
variations due to chance (randomness) it does not have a
fixed value; it can be discrete or continuous
A coin toss: can be heads or tails discrete
The lifetime of a light bulb continuous
A probability density function (pdf), p (x ), represents the
likelihood that x occurs
Always non-negative
Satisfies
Z
p () d = 1
Concepts from
Probability Theory Mean and Variance
The mean (or first moment) of a random variable x, denoted
by x, is defined as
Z
x = E [x ] = p () d
h i
The mean-square of a random variable x, E x 2 , is defined
as
Z
h i
E x2 = 2 p () d
The variance (or second moment) of a random variable x,
denoted by 2x , is
Z
h 2
i
2x = E [x E (x )] = ( E ())2 p () d
h i
= E x 2 x2
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 12 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Concepts from
Probability Theory Mean and Variance
of a Vector
, is defined as
The mean of a random nvector x, x
Z Z Z
= E [x]
x = p () d
ellipsoid.
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 13 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Concepts from
Probability Theory The Gaussian
Distribution
The Gaussian probability distribution function, also called
the Normal distribution1 or a bell curve, is at the heart of
Kalman filtering
We assume that our random variables have Gaussian pdfs
We like to work with Gaussians because they are completely
characterized by their mean and covariance
Linear combinations of Gaussians are Gaussian
The Gaussian distribution of random nvector x, with a mean
and covariance Px , is defined as
of x
1 x)T P
(x 1
x (x
x)
pg (x) = e 2
(2)n/2 |Px |
1
Physicist G. Lippman is reported to have said, Everyone believes in the
normal approximation, the experimenters because they think it is a mathematical
theorem, the mathematicians because they think it is an experimental fact.
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 14 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Concepts from
Probability Theory The Gaussian
Distribution
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 16 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Linear Systems
Nonlinear Systems
and the Linearization Process
f
!
X (t ) = f (X? , t ) + (X X? ) +
X X=X?
Nonlinear Systems
and the State Transition Matrix
If we let x(t ) = X X? and let F(t ) = Xf
, then we get
X=X?
2
In cases of fast dynamics, we can approximate the STM to second-order as:
(t , t0 ) I + F(t0 ) (t t0 ) + 21 F2 (t0 ) (t t0 )2
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 19 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 20 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
y = Hx +
J 1
" #
= T
(y Hx) (y Hx) )T H = 0
= (y Hx
x x 2
x=x
, is
Therefore, the optimal solution, x
1
= HT H
x HT y
The Weighted
Least Squares (WLS) Problem
Suppose now we are given measurements y, whose error has a
measurement covariance of R. How can we get the best estimate,
which minmizes the errors weighted by the accuracy of the
x
measurement error (R1 )? The problem can be posed as
1 T 1 1
min J = R = (y Hx)T R1 (y Hx)
2 2
Once again, we take the first derivative of J with respect to x and
set it equal to zero as
J 1
" #
= T 1
(y Hx) R (y Hx) )T R1 H = 0
= (y Hx
x x 2 x=
x
, is
Therefore, the optimal solution, x
1
= HT R1 H
x HT R1 y
, is
Therefore, the optimal solution, x
1 h i
x 1
= HT R1 H + P 1 x
HT R1 y + P
Nonlinear Batch
Estimation
Yk = h(Xk , tk ) + k
h
h(X? h(X? Xk X?
Yk = + xk , tk ) + k = k) + + + k
k
X Xk =X?k k
k = h
Defining H X Xk =X?
we get the following equation
k
k xk + k
yk = H
Nonlinear Batch
Estimation at an Epoch
In batch estimation, we are interested in estimating a state at an
epoch, say X0 , with measurements taken after that epoch say, at
tk . How can we obtain this? Well, we use the state transition matrix
as follows
Xk X? ?
k = (tk , t0 ) Xk Xk xk = (tk , t0 )x0
so that we can map the measurements back to the epoch of
interest as
k (tk , t0 )x0 + k = Hk x0 + k
yk = H
The least squares solution (over all the p measurements) is
p 1 p
0 X?
X T 1 X
1 H R yi + P
0 = Hi Ri Hi + P
x
T 1 x
1 = X
0 i i 0 0 0
i =1 i =1
The Nonlinear
Batch Estimation Algorithm
x (t ) = u0 (t t0 ) + x0
y (t ) = v0 (t t0 ) + y0
" #
1 y (t )
(t ) = tan
x (
t )
Something
to remember
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 32 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Six months in the lab can save you a day in the library
Stochastic Processes
The Linear First-Order
Differential
Equation
Let us look at a first-order differential equation for x (t ), given
f (t ), g (t ), w (t ) and x0 as
x (t ) = f (t )x (t ) + g (t )w (t ) with x (t0 ) = x0
The solution of this equation is
Rt Z t Rt
f ()d f ()d
x (t ) = e t0
x0 + e g ()w ()d
t0
Rt
f ()d
Suppose now we define (t , t0 ) = e t0
, we can write the
above solution as
Z t
x (t ) = (t , t0 )x0 + (t , )g ()w ()d
t0
The Mean of
a Linear First-Order Stochastic Process
Given a first-order stochastic process, (t ), with constant f
and g and white noise, w (t ), which is represented as
(
t ) = f (t ) + g w (t ) with (t0 ) = 0
and the mean and covariance of w (t ) expressed as
E [w (t )] = 0 and E [w (t )w ()] = q (t )
The mean of the process,
(t ) is
Rt Z t Rt
f d f d
(t ) = E [(t )] = e t0
0 + e g ()E [w ()]d
t0
Rt
f d
= e t0
0
= e f (t t0 )
0
Stochastic Processes
The Mean-Square and
Covariance
of a Linear First-Order Stochastic Process
Stochastic Processes
The Vector First-Order
Differential
Equation
A first-order vector differential equation for x(t ), given x(t0 ) and
white noise with E (w(t )) = 0, and E (w(t )w(T )) = Q (t ), is
t , t0 ) = F(t )(t , t0 ),
( with (t0 , t0 ) = I
The Covariance
of a Linear, Vector Process
The covariance of x(t ), Pxx (t ), given Pxx (t0 ), is expressed as
h i
(t ))T
(t )) (x(t ) x
Pxx (t ) = E (x(t ) x = E [x(t )xT (t )] x T (t )
(t )x
= (t , t0 )Pxx (t0 )T (t , t0 )
Z t
+ (t , )G() Q GT ()T (t , ) d
t0
A Discrete Linear,
Vector Process
Given the continuous process (x (t ) = F(t )x(t ) + G(t )w(t )), whose
solution is
Z tk
x(tk ) = (tk , tk 1 )x(tk 1 ) + (t , )G()w()d
tk 1
whose mean is
k = (tk , tk 1 )x
x k 1
The Covariance
of a Discrete Linear, Vector Process
where
Z t
Qk = (tk , )G() Q GT ()T (tk , ) d
t0
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 41 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Considerations
Albert Einstein
Prediction
Measurement
Compute Residual
Correction
The Derivation
of the Kalman Filter (I)
k be an unbiased a priori estimate (the prediction) of xk with
Let x
covariance Pk so that the a priori estimate error, ek is
T
ek = xk x
k with E (ek ) = 0, E (ek ek ) = Pk
We hypothesize an unbiased linear update (the correction) to xk ,
+
called xk
, as follows (with Kk as yet unknown)
+
xk
=x k
k + Kk yk Hk x
The Derivation
of the Kalman Filter (II)
So far we havent said anything about Kk . We now choose Kk to
minimize the a posteriori error as1
1
T 1 T 1 T
min J = E e+k
e+k
= tr E e+ k
e+k
= E tr e+k
e+
k
2 2 2
1
T
1 T
1
= E tr e+ e+
k k
= tr E e+ e+
k k
= tr P+k
2 2 2
so we obtain K by2
h i
tr P+ = tr (I Kk Hk ) P
( I K k Hk ) T
+ K k Rk K T
k = 0
Kk k Kk k
1
The cyclic invariance property of the trace is: tr(ABC) = tr(BCA) = tr(CAB)
2
Recalling that
tr(AXBXT ) = AT XBT + AXB; tr(AXB) = AT BT ; tr(AXT B) = BA
X X X
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 49 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
The Derivation
of the Kalman Filter (III)
This results in the following condition
T
Pk HTk Pk HTk + Kkopt Hk Pk HTk + Rk + Kkopt Hk Pk HTk + Rk = 0
which gives
1
Kkopt = Pk HTk Hk Pk HTk + Rk
A Kalman Filter
Example
Given a spring-mass-damper system governed by the following
equation
r (t ) = 0.001r (t ) 0.005r (t ) + w (t )
the system can be written (in first-order discrete form,
xk = (tk , tk 1 )xk 1 + k wk ) as
" # (" # )" # " #
r (tk ) 0 1 r (tk 1 ) 0
= exp t + wk
r (tk ) 0.001 0.005 r (tk 1 ) 1
with measurements
yk = r (tk ) + k with E [k ] = 0, E [j k ] = 0.0012 jk
and
" #
1 0
P0 = and Q = 0.0052
0 0.12
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 52 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
A Kalman Filter
Example (II)
A Kalman Filter
Example (III)
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 55 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Considerations
The Extended
Kalman Filter
Xk = X?
b
k + xk
The Development
of the Extended Kalman Filter (I)
Begin with the nonlinear state equation
, t ) + f
X(t ) = f(X X + + w(t )
X
X X=X
(t ), neglecting higher than first-order terms,
so that X
, t)
(t ) = f(X
X
The Development
of the Extended Kalman Filter (II)
i
)(X X
)T h
Recalling the definition of P = E (X X , we find that
f
P(t ) = F(t )P(t ) + P(t )FT (t ) + Q where F =
X X=X
The Development
of the Extended Kalman Filter (III)
Likewise, the measurement equation can be expanded in a Taylor
, the a priori state, as
series about X k
h
Yk = h(Xk ) + k = h(X
) + + + k
Xk X
k
Xk Xk =X k k
The Extended
Kalman Filter (EKF) Algorithm
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 61 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Considerations
Practical Matters
Processing Multiple Measurements
In general, more than one measurement will arrive at the
same time
Usually the measurements are uncorrelated and hence they
can be processed one-at-a-time
However, even if they are correlated, they can usually be
treated as if they were uncorrelated by increasing the
measurement noise variance
If the measurements are processed one-at-a-time, then
1 Pk HTk
Kk = Pk HTk Hk Pk HTk + Rk =
Hk Pk HTk + Rk
Thus there is no need for a matrix inverse we can use scalar
division
This greatly reduces the computational throughput, not
to
mention software complexity
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 62 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Matters
Processing Non-Gaussian
Measurements
Practical Matters
Dealing with Measurement Latency
Measurements arent so polite as to be time-tagged or to
arrive at the major cycle of the navigation filter (tk )
Therefore, we need to process the measurements at the time
they are taken, assuming that the measurements are not too
latent
Provided they are less than (say) 3 seconds latent
The state is propagated back to the measurement time using,
say, a first-order integrator
f
Xm = Xk + f(Xk )t + (Xk )f(Xk )t 2
X
The measurement partial mapping is done in much the same
way as it was done in batch estimation
Map the measurement sensitivity matrix at the time of the
measurement(H(Xm )) to the filter time (tk ) using the state
transition matrix, (tm , tk ).
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 64 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Matters
Measurement Underweighting
Sometimes, when accurate measurements are introduced to
a state which isnt all that accurate, filter instability results
There are several ways to handle this
Second-order Kalman Filters
Sigma Point Kalman Filters
Measurement Underweighting
Since Apollo, measurement underweighting has been used
extensively
What underweighting does is it slows down the rate that the
measurements decrease the covariance
It approximates the second-order correction to the covariance
matrix
Underweighting is typically implemented as
1
Kk = Pk HTk (1 + )Hk Pk HTk + Rk
The scalar is a tuning parameter used to get good
filter
performance
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 65 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Matters
Filter Tuning (I)
Practical Matters
Filter Tuning (II)
Sensor parameters (such as bias) are modeled as zero-mean
Gauss-Markov parameters, xp , which have two tuning
parameters
The Steady State Variance (Ppss )
The Time Constant ()
d 1
xp = xp + wp , where E [wp (t )wp ()] = Qp (t )
dt p
Ppss
Qp = 2
p
All of these are tuned in the Monte Carlo environment so that
The state error remains mostly within the 3- bounds of the
filter covariance
The filter covariance represents the computed sample
covariance
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 67 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Practical Matters
Filter Tuning (III)
Practical Matters
Invariance to Measurement Ordering
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 70 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Advanced Topics
Introduction and Background
Concepts from Probability Theory
Linear and Nonlinear Systems
Conclusions
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 71 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
Conclusions
Kalman Filtering and Least Squares Estimation are at the
heart of the spacecraft navigation
Ground-based navigation
On-board navigation
Its purpose is to obtain the best state of the vehicle given a
set of measurements and subject to the computational
constraints of flight software
It requires fluency with several disciplines within engineering
and mathematics
Statistics
Numerical Algorithms and Analysis
Linear and Nonlinear Analysis
Sensor Hardware
Challenges abound
Increase demands on throughput
Image-based sensors
Christopher DSouza March 2013 Fundamentals of Kalman Filtering and Estimation 71 / 73
Introduction and Background
Least Squares Estimation
The Kalman Filter NASA / Johnson Space Center
Implementation Considerations and Advanced Topics
To put things
in perspective
References