# 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

current and future measurements .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.

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 .

• xˆ + is the state vector with the current measurements include • xˆ − 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. Linear frequency drift) .ELEMENTS OF THE KALMAN FILTER • Physical parameters being estimated represented by the components of the state vector. Normalised frequency offset.

Composite)(ns) 200 H M 1 .C o m p o s ite 150 100 b5 0 0 -5 0 53020 53060 53100 M JD 53140 53180 .C o m p o s ite H M 2 .C o m p o s ite H M 3 .DETERMINISTIC CLOCK CHARACTERISTICS (ACTIVE HYDROGEN MASERS) 100 - (Clock .

K is determined by the Kalman filter. • H is the design matrix that relates the measurements to the physical parameters being estimated y =Hx. the higher the “weighting” of current measurements used to estimates the physical parameters.0. • In our simple example we have phase measurements and H = (1.0). • K is the Kalman gain.ELEMENTS OF THE KALMAN FILTER • y is the measurement vector. .

STATE PROPAGATION MATRIX • State propagation matrix is used to extrapolate current estimate:  1  Φ = 0 0   τ 1 0   2  τ  1    τ 2 .

• P is the parameter covariance matrix. This is the clock noise • R is the measurement noise covariance matrix.COVARIANCE MATRICES • Process covariance matrix Q: • Describes the process noise added at each measurement. P+ and P. Noise is assumed to be white and may be correlated.is the matrix after and before the measurement update . describes the uncertainties in the state vector estimates.

SIMPLE MEASUREMENT SET CURRENT POINT = 3 250 Measurement 200 150 100 50 0 0 1 2 3 4 P oint N o 5 6 7 8 .

HOW IT ALL WORKS • State vector extrapolation (1) − n xˆ (t ) = Φ (τ ) xˆ (t + n −1 ) • Parameter covariance matrix extrapolation (2) − n + n −1 T P(t ) = Φ(τ ) P(t )Φ (τ ) + Q(tn ) .

HOW IT ALL WORKS • Kalman gain determination (3) − n T [ T − n K ( t n ) = P ( t ) H H P (t ) H + R ( t n ) ] −1 • Incorporating current measurements (4) + n − n [ − n xˆ ( t ) = xˆ ( t ) + K ( t n ) y ( t n ) − H xˆ ( t ) • Parameter covariance matrix update (5) + n [ ] − n P (t ) = I − K (t n ) H P (t ) ] .

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 .

the measurement matrix H and the number of iterations • Kalman gain has similar properties . and do not include actual measurements • Uncertainty of the state vector determination depends only on the covariance matrices Q and R. 3 and 5 may be run independently of the rest.PROPERTIES OF THE KALMAN FILTER • Equations 2.

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 .

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 ensemble algorithm – Input from three or more clock.

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 .WHERE DO WE USE KALMAN FILTER CLOCK ALGORITHMS? • Clock steering algorithm – Steers a hardware or software clock to stay close to a reference timescale.

8 -1 5 .8 2 2 .1 4 .1 5 .1 4 .6 .1 5 .2 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 i te O p t im a l C o m p o s i t e .6 .5 3 3 .4 σ y) Log10(σ .APPLICATION TO NPL’S CLOCK ENSEMBLE ALGORITHM .1 4 .2 .5 L o g 10(τ) 4 4 .4 .5 5 .1 5 .1 4 .1 5 .

APPLICATION TO NPL’S CLOCK ENSEMBLE ALGORITHM P lo ts o f L o g 10 ( σ ) a g a in s t L o g y 10 (τ(s )) -1 4 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 i te O p t im a l C o m p o s i t e σ y) Log10(σ .5 5 .5 -1 6 2 2 .5 -1 5 .1 5 .5 3 3 .5 L o g 10(τ) 4 4 .1 4 .

CLOCK PREDICTOR APPLICATION C lo c k P r e d ic t o r E r r o r V a r ia n c e 7 Prediction Error Variance O p t im a l P E V K a lm a n filt e r P E V S im p le l in e a r p r e d ic t o r M S E K a lm a n filt e r p r e d ic to r M S E S im p le l in e a r p r e d ic t o r P E V 6 5 4 3 2 1 0 0 200 400 600 P r e d ic tio n le n g t h ( s ) 800 1000 .

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 .