22
NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9 th February 2006

Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

Embed Size (px)

Citation preview

Page 1: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

NPL Time and Frequency User Club

A Beginner’s Guide to Kalman Filters

J.A.Davis

9th February 2006

Page 2: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · 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

Page 3: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 4: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 5: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 6: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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̂

Page 7: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 8: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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.

Page 9: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

STATE PROPAGATION MATRIX

• State propagation matrix is used to extrapolate current estimate:

100

102

1

2

τ

ττ

Page 10: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 11: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 12: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

HOW IT ALL WORKS

• State vector extrapolation (1)

• Parameter covariance matrix extrapolation (2)

)(ˆ)()(ˆ1

+

−Φ= nn txtx τ

)()()()()( 1 n

T

nn tQtPtP +ΦΦ=+

−ττ

Page 13: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 14: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 15: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 16: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 17: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 18: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 19: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 20: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 21: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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

Page 22: Presentation 6 NPL USER CLUB A BEGINNERS GUIDE TO KALMAN FILTERS … · NPL Time and Frequency User Club A Beginner’s Guide to Kalman Filters J.A.Davis 9th February 2006

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