NPL Time and Frequency User Club
A Beginner’s Guide to Kalman Filters
J.A.Davis
9th February 2006
WHAT IS A KALMAN FILTER
• An recursive analytical technique to estimate time dependent physical parameters in the presence of noise
processes
• Example of a time and frequency application:
Offset between two clocks
PREDICTORS, FILTERS AND SMOOTHING ALGORITHMS
• A predictor provides estimates of the physical parameter’s current values using previous
measurements
• A filter provides estimates of the physical parameter’s
using previous and current measurements
• A smoothing algorithm provides estimates of the physical parameter’s current values using previous,
current and future measurements
WHY USE A KALMAN FILTER?
• Provides optimal estimates when noise model is exact
• Computationally efficient, update filter when adding new measurements to the existing data set
• Very simple to implement
• Recursive algorithm
WHY USE A KALMAN FILTER?
• May be used as a predictor
• Easy to verify performance using simulated data
• Uncertainty estimates are provided as part of the filter
• May be easily modified to provide a steering algorithm or other application
ELEMENTS OF THE KALMAN FILTER
• Physical parameters being estimated represented by the components of the state vector.
• is the state vector with the current measurements include
• is the state vector extrapolated to next data point where the next set of measurements have not yet been included
• Example of the elements of a state vector (Phase offset, Normalised frequency offset, Linear frequency drift)
+x̂
−x̂
DETERMINISTIC CLOCK CHARACTERISTICS (ACTIVE HYDROGEN MASERS)
1 0 0
5 3 0 2 0 5 3 0 6 0 5 3 1 0 0 5 3 1 4 0 5 3 1 8 0 -5 0
0
b5 0
1 0 0
1 5 0
2 0 0
-
M J D
(
Clo
ck -
Co
mp
osit
e)(
ns)
H M 1 - C o m p o s ite
H M 2 - C o m p o s ite
H M 3 - C o m p o s ite
ELEMENTS OF THE KALMAN FILTER
• y is the measurement vector.
• H is the design matrix that relates the measurements to the physical parameters being estimated y =Hx.
• In our simple example we have phase measurements and H = (1,0,0).
• K is the Kalman gain, the higher the “weighting” of current measurements used to estimates the physical parameters. K is determined by the Kalman filter.
STATE PROPAGATION MATRIX
• State propagation matrix is used to extrapolate current estimate:
=Φ
100
102
1
2
τ
ττ
COVARIANCE MATRICES
• Process covariance matrix Q:
• Describes the process noise added at each
measurement. This is the clock noise
• R is the measurement noise covariance matrix. Noise is assumed to be white and may be correlated.
• P is the parameter covariance matrix, describes the
uncertainties in the state vector estimates. P+ and P- is
the matrix after and before the measurement update
SIMPLE MEASUREMENT SETCURRENT POINT = 3
0
50
100
150
200
250
0 1 2 3 4 5 6 7 8
Point No
Me
as
ure
me
nt
HOW IT ALL WORKS
• State vector extrapolation (1)
• Parameter covariance matrix extrapolation (2)
)(ˆ)()(ˆ1
+
−
−Φ= nn txtx τ
)()()()()( 1 n
T
nn tQtPtP +ΦΦ=+
−
−ττ
HOW IT ALL WORKS
• Kalman gain determination (3)
• Incorporating current measurements (4)
• Parameter covariance matrix update (5)
[ ] 1
)()()()(−
−−+= n
T
n
T
nn tRHtPHHtPtK
[ ])(ˆ)()()(ˆ)(ˆ −−+−+= nnnnn txHtytKtxtx
[ ] )()()(−+
−= nnn tPHtKItP
WHAT ARE THE PITFALLS?
• Literature is full of descriptions of very badly constructed Kalman filters (including time and frequency literature)
• Require a reasonably accurate model of underlying physical processes
• Require a reasonably accurate model of the noise processes
• Physical parameters must be observable
Clock ensemble algorithm physical parameters are only partly observable. Problem reported 1987, problem solved 2002
PROPERTIES OF THE KALMAN FILTER
• Equations 2, 3 and 5 may be run independently of the rest, and do not include actual measurements
• Uncertainty of the state vector determination depends
only on the covariance matrices Q and R, the
measurement matrix H and the number of iterations
• Kalman gain has similar properties
ASSUMPTIONS MADE WHEN USING THE KALMAN FILTER
• Process noise added on successive epochs does not correlate
• Measurement noise is assumed to be white, zero mean
and distributed normally
WHERE DO WE USE KALMAN FILTER CLOCK ALGORITHMS?
• Clock ensemble algorithm
– Input from three or more clock, outputs a “composite”
that should be more stable than any individual clock
• Clock predictor
– Predicts the future offset between two clocks based
on current and previous measurements
WHERE DO WE USE KALMAN FILTER CLOCK ALGORITHMS?
• Clock steering algorithm
– Steers a hardware or software clock to stay close to
a reference timescale. Trade-off of frequency stability and time offset
• Time transfer combining algorithm
– Combines measurements from several time transfer
links between the same two clocks to form an optimal composite
APPLICATION TO NPL’S CLOCK ENSEMBLE ALGORITHM
2 2 .5 3 3 .5 4 4 .5 5
-1 5 .8
-1 5 .6
-1 5 .4
-1 5 .2
-1 5
-1 4 .8
-1 4 .6
-1 4 .4
-1 4 .2
L o g 1 0 ( ττττ )
Lo
g1
0(σσ σσ
y)
C lo c k 1 (F F M )
C lo c k 2 (W F M )
C lo c k 3 (W F M )
C o m p o s ite
S im p le C o m p o s ite
O p t im a l C o m p o s ite
APPLICATION TO NPL’S CLOCK ENSEMBLE ALGORITHM
2 2 .5 3 3 .5 4 4 .5 5 -1 6
-1 5 .5
-1 5
-1 4 .5
-1 4
P lo ts o f L o g 1 0
( σ y ) a g a in s t L o g
1 0 ( τ (s ) )
L o g 1 0 ( ττττ )
Lo
g1
0(σσ σσ
y)
C lo c k 1 (F F M )
C lo c k 2 (W F M )
C lo c k 3 (W F M )
C o m p o s ite
S im p le C o m p o s ite
O p t im a l C o m p o s ite
CLOCK PREDICTOR APPLICATION
0 2 0 0 4 0 0 6 0 0 8 0 0 1 0 0 0 0
1
2
3
4
5
6
7 C lo c k P re d ic to r E rro r V a r ia n c e
P re d ic tio n le n g th (s )
Pre
dic
tio
n E
rro
r V
ari
an
ce
O p tim a l P E V
K a lm a n filte r P E V
S im p le l in e a r p re d ic to r M S E
K a lm a n filte r p re d ic to r M S E
S im p le l in e a r p re d ic to r P E V
CONCLUSIONS
• Kalman filters may be used as a very effective in time and frequency analysis
• Must understand their limitations
• Choice of noise models and the state vector
components is critical