Use of Kalman filters in time and frequency analysis John Davis 1st May 2011 Overview of Talk Simple example of Kalman filter Discuss components and operation of filter Models of clock and time transfer noise and deterministic properties Examples of use of Kalman filter in time and frequency Predictors, Filters and Smoothing Algorithms Predictor: predicts parameter values ahead of current measurements Filter: estimates parameter values using current and previous measurements Smoothing Algorithm: estimates parameter values using future, current and previous measurements What is a Kalman Filter ? A Kalman filter is an optimal recursive data processing algorithm The Kalman filter incorporates all information that can be provided to it. It processes all available measurements, regardless of their precision, to estimate the current value of the variables of interest Computationally efficient due to its recursive structure Assumes that variables being estimated are time dependent Linear Algebra application Simple Example 1.5E-08 1.0E-08 Offset 5.0E-09 0.0E+00 0 2 4 6 8 10 12 -5.0E-09 -1.0E-08 Date Truth Measurement 14 16 18 20 Simple Example (Including Estimates) 1.5E-08 1.0E-08 5.0E-09 0.0E+00 0 2 4 6 8 10 12 14 -5.0E-09 -1.0E-08 Truth Measurement Filter Estimate 16 18 20 Estimation Errors and Uncertainty 6.0E-09 4.0E-09 Error 2.0E-09 0.0E+00 0 2 4 6 8 10 12 14 -2.0E-09 -4.0E-09 -6.0E-09 Date Error Uncertainty (lower) Uncertainty (upper) 16 18 20 Operation of Kalman Filter Provides an estimate of the current parameters using current measurements and previous parameter estimates Should provide a close to optimal estimate if the models used in the filter match the physical situation World is full of badly designed Kalman filters What are the applications in time and frequency? Analysis of time transfer / clock measurements where measurement noise is significant Clock and time scale predictors Clock ensemble algorithms Estimating noise processes Clock and UTC steering algorithms GNSS applications Starting point for iteration 11 of filter 1.4E-08 1.2E-08 1.0E-08 Offset 8.0E-09 6.0E-09 4.0E-09 2.0E-09 0.0E+00 -2.0E-09 0 2 4 6 8 10 12 Date Measurement Filter Estimate 14 16 18 20 Five steps in the operation of a Kalman filter (1) State Vector propagation (2) Parameter Covariance Matrix propagation (3) Compute Kalman Gain (4) State Vector update (5) Parameter Covariance Matrix update Components of the Kalman Filter (1) State vector x Contains required parameters. These parameters usually contain deterministic and stochastic components. Normally include: time offset, normalised frequency offset, and linear frequency drift between two clocks or timescales. State vector components may also include: Markov processes where we have memory within noise processes and also components of periodic instabilities Components of the Kalman Filter (2) State Propagation Matrix F(t) Matrix used to extrapolate the deterministic characteristics of the state vector from time t to t+t Steps in the operation of the Kalman Filter Step 1: State vector propagation from iteration n-1 to n xˆ (tn ) F(t ) xˆ (tn1 ) xˆ (tn ) Estimate of the state vector at iteration n not including measurement n. F(t ) spacing t State propagation matrix calculated for time xˆ (tn1 ) Estimate of the state vector at iteration n-1 including measurement n-1. Step 1: State Vector Extrapolation 1.4E-08 1.2E-08 1.0E-08 Offset 8.0E-09 6.0E-09 4.0E-09 2.0E-09 0.0E+00 0 2 4 6 8 10 12 14 -2.0E-09 Date Measurement Filter Estimate State Vector Extrapolation 16 18 20 Components of the Kalman Filter (3) Parameter Covariance Matrix P Contains estimates of the uncertainty and correlation between uncertainties of state vector components. Based on information supplied to the Kalman filter. Not obtained from measurements. Process Covariance Matrix Q(t) Matrix describing instabilities of components of the state vector, e.g. clock noise, time transfer noise moving from time t to t+t Noise parameters s Parameters used to determine the elements of the process covariance matrix, describe individual noise processes. Steps in the operation of the Kalman Filter Step 2: Parameter covariance matrix propagation from iteration n-1 to n P (tn ) F(t ) P (tn1 )F (t ) Q(tn ) T Parameter covariance matrix, at iteration n1 including measurement n-1 T F(t ) F (t ) State propagation matrix and transpose calculated for time spacing t P (tn ) Parameter covariance matrix, at iteration n not including measurement n Q(tn ) Process covariance matrix Uncertainty Extrapolation 6.0E-09 Error / Uncertainty 4.0E-09 2.0E-09 0.0E+00 0 2 4 6 8 10 12 14 16 18 -2.0E-09 -4.0E-09 -6.0E-09 Error Uncertainty (upper) Date Uncertainty Extrapolation (upper) Uncertainty (lower) Uncertainty Extrapolation (lower) 20 Components of the Kalman Filter (4) Design Matrix H Matrix that relates the measurement vector and the state vector using y =H x Measurement Covariance Matrix R Describes measurement noise, white but individual measurements may be correlated. May be removed. Kalman Gain K Determines the weighting of current measurements and estimates from previous iteration. Computed by filter. Steps in the operation of the Kalman Filter Step 3 :Kalman gain computation K (tn ) P (tn ) H H P (tn ) H R(tn ) T T 1 P (tn ) Parameter covariance matrix, at iteration n not including measurement n T H H Design Matrix and Transpose K (tn ) Kalman Gain R(tn ) Measurement covariance matrix Components of the Kalman Filter (5) Measurement Vector y Vector containing measurements input during a single iteration of the filter Identity Matrix I Steps in the operation of the Kalman Filter Step 4 :State vector update xˆ (tn ) xˆ (tn ) K (tn ) y(tn ) H xˆ (tn ) xˆ (tn ) xˆ (tn ) Estimate of the state vector at iteration n including and not including measurement n respectively. K (tn ) Kalman Gain y (tn ) Measurement Vector H Design Matrix Step 4 :State Vector Update 1.4E-08 1.2E-08 1.0E-08 Offset 8.0E-09 6.0E-09 4.0E-09 2.0E-09 0.0E+00 0 2 4 6 8 10 12 14 16 -2.0E-09 Measurement Filter Estimate Date State Vector Extrapolation State Vector Update 18 20 Steps in the operation of the Kalman Filter Step 5 :Parameter Covariance Matrix update n n P(t ) I K (tn ) H P(t ) Kalman Gain H Design Matrix P(tn ) P(tn ) Parameter Covariance Matrix, at iteration n, including and not including measurement n respectively I Identity Matrix K (tn ) Steps in the operation of the Kalman Filter If Kalman gain is deliberately set sub-optimal, then use P(t ) I K (tn ) H P(t )I K (tn ) H n n Kalman Gain H Design Matrix P(tn ) P(tn ) Parameter Covariance Matrix, at iteration n, including and not including measurement n respectively I Identity Matrix K (tn ) T Step 5: Uncertainty Update 6.0E-09 Error / Uncertainty 4.0E-09 2.0E-09 0.0E+00 0 2 4 6 8 10 12 14 16 18 -2.0E-09 -4.0E-09 -6.0E-09 Date Error Uncertainty Extrapolation (lower) Uncertainty update (upper) Uncertainty (lower) Uncertainty Extrapolation (upper) Uncertainty (upper) Uncertainty Update (lower) 20 Constructing a Kalman Filter: Lots to think about! Choice of State Vector components Choice of Noise Parameters Choice of measurements Description of measurement noise Choice of Design Matrix Choice of State Propagation Matrix Initial set up conditions Dealing with missing data Testing out the filter Computational methods Initialising the Kalman Filter Set the initial parameters to physically realistic values If you have no information set diagonal values of Parameter Covariance Matrix high, filter will then give a high weight to the first measurement. Set Parameters with known variances e.g. Markov components of Parameter Covariance Matrices to their steady state values. Set Markov State Vector components and periodic elements to zero. Elements of H, F(t), Q(t), R are pre-determined Simulating Noise and Deterministic Processes Use the same construction of state vector components x, state propagation matrix F(t), parameter covariance matrix P, process covariance matrix Q(t), design matrix H and measurement covariance matrix R. Simulate all required data sets Simulate “true” values of state vector for error analysis May determine ADEV, HDEV, MDEV and TDEV statistics from parameter covariance matrix Simulating Noise and Deterministic Processes x(tn ) F (t ) x(tn1 ) L Q (tn )e(tn ) Where Q LQ (tn ) LQ (tn ) T Q = Process Covariance Matrix x(tn ) x(tn1 ) = State Vector at iteration n and n-1 respectively F(t ) = State Propagation Matrix calculated for time spacing t e(tn ) Vector of normal distribution noise of unity magnitude Simulating Noise and Deterministic Processes P(tn ) F(t ) P(tn1 )F (t ) Q(tn ) T P(tn ) P(tn1 ) Process Covariance Matrix at iterations n and n-1 respectively F(t ) F (t ) State Propagation Matrix and T transpose computed at time spacing t. Q (tn ) Process Covariance Matrix calculated at time spacing t Simulating Noise and Deterministic Processes y (tn ) H x(tn ) LR (tn )e(tn ) where y(tn ) H R e(tn ) R LR (tn ) L (tn ) T R Measurement Vector Design Matrix Measurement Covariance Matrix Vector of normal distribution noise of unity magnitude ADEV, HDEV, and MDEV determined from Parameter Covariance Matrix and simulation 10 -12 ADEV simulation HDEV simulation MDEV simulation ADEV theory HDEV theory MDEV theory z -13 Sigma 10 10 10 -14 -15 10 2 10 3 10 4 10 tau 5 10 6 10 7 Simulating Noise and Deterministic Processes Test Kalman filter with a data set with same stochastic and deterministic properties as is expected by the Kalman filter. Very near optimal performance of Kalman filter under these conditions. Deterministic Properties Linear frequency drift Use three state vector components, time offset, normalised frequency offset and linear frequency drift 1 t t 2 2 t 0 1 F 0 0 1 Markov Noise Process x e White Noise n Random Walk Noise n n1 Markov Noise 0 k 1 n n1 Flicker noise, combination of Markov processes with continuous range of relaxation parameters k Markov noise processes and flicker noise have memory Kalman filters tend to work very well with Markov noise processes May only construct an approximation to flicker noise in a Kalman filter x x e x kx e Markov Noise Process 6 x 10 -6 4 Time Offset 2 0 -2 -4 -6 6 6.5 7 MJD 7.5 8 Describing Measurement Noise Kalman filter assumes measurement noise introduced via matrix R is white Time transfer noise e.g TWSTFT and GNSS noise is often far from white Add extra components to state vector to describe non white noise, particularly useful if noise has “memory” e.g. flicker phase noise NPL has not had any problems in not using a measurement noise matrix R White Phase Modulation x 10 WPM Noise -10 Time Offset 0.5 0 -0.5 0 5 10 MJD 15 20 White Phase Modulation 8 x 10 -11 WPM Noise (sample) 6 Time Offset 4 2 0 -2 -4 10 10.2 10.4 10.6 MJD 10.8 11 White Phase Modulation 10 10 Sigma 10 10 10 10 ADEV, HDEV MDEV of WPM -12 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory -13 -14 -15 -16 -17 10 2 10 3 4 10 tau 10 5 10 6 Flicker Phase Modulation 2 x 10 -10 Simulated FPM Noise 1.5 1 Time Offset 0.5 0 -0.5 -1 -1.5 -2 -2.5 0 5 10 MJD 15 20 Flicker Phase Modulation 10 Sigma 10 10 10 10 ADEV, HDEV MDEV of FFM -12 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory -13 -14 -15 -16 10 2 10 3 4 10 tau 10 5 10 6 Measurement noise used in Kalman filter 2 x 10 Simulated Time Transfer Noise -10 Time Offset 1 0 -1 -2 0 5 10 MJD 15 20 Measurement noise ADEV, MDEV and HDEV ADEV, HDEV MDEV of measurements noise -12 10 Sigma 10 10 10 10 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory -13 -14 -15 -16 10 2 10 3 4 10 tau 10 5 10 6 Clock Noise White Frequency Modulation and Random Walk Frequency Modulation easy to include as single noise parameters. Flicker Frequency Modulation may be modelled as linear combination of Integrated Markov Noise Parameters White Frequency Modulation 5 x 10 WFM Noise -8 Time Offset 0 -5 -10 -15 0 5 10 MJD 15 20 White Frequency Modulation 10 ADEV, HDEV MDEV of WFM -11 Sigma ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory 10 10 -12 -13 10 2 10 3 4 10 tau 10 5 10 6 Random Walk Frequency Modulation 0 x 10 RWFM Noise -7 -1 -2 Time Offset -3 -4 -5 -6 -7 -8 -9 0 5 10 MJD 15 20 Random Walk Frequency Modulation 10 -13 Sigma 10 ADEV, HDEV MDEV of RWFM -12 10 10 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory -14 -15 10 2 10 3 4 10 tau 10 5 10 6 FFM Noise 2 x 10 FFM Noise -9 1 0 Time Offset -1 -2 -3 -4 -5 -6 -7 0 5 10 MJD 15 20 Flicker Frequency Modulation ADEV, HDEV MDEV of FFM noise -14 Sigma 10 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory 10 -15 10 2 10 3 4 10 tau 10 5 10 6 Periodic Instabilities Often occur in GNSS Applications Orbit mis-modelling Diurnal effects on Time Transfer hardware Periodicity decays over time Model as combination of Markov noise process and periodic parameter Two extra state vector component to represent periodic variations GPS Time – Individual Clock (Real Data) Input data space clock prn 9 -5 1.622 x 10 Input Data 1.6215 Time Offset 1.621 1.6205 1.62 1.6195 1.619 0 1 2 3 4 Day D 5 6 7 GPS Time – Individual Clock (Simulated Data) -8 Simulated data with similar characteristics x 10 1 GPS CV Time Offset 0.5 0 -0.5 -1 -1.5 6 7 8 9 10 MJD 11 12 13 ADEV, HDEV, MDEV Real Data 10 ADEV / HDEV / MDEV Prn 9 -11 ADEV / HDEV / MDEV ADEV HDEV MDEV 10 10 10 -12 -13 -14 10 2 10 3 4 10 Tau 10 5 10 6 ADEV, HDEV, MDEV Simulated Data ADEV, HDEV MDEV Theory and Measurement 10 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory -12 ADEV 10 -11 10 10 -13 -14 10 2 10 3 4 10 tau 10 5 10 6 Kalman Filter Residuals ( y Hxˆ ) Residuals Residual Variance (Theory) V HP H T In an optimally constructed Kalman Filter the Residuals should be white! Residual Variance obtained from Parameter Covariance matrix should match that obtained from statistics applied to residuals Kalman Filter Residuals (Simulated Data) -9 Kalman Filter Residuals (simulated data) x 10 1 Time Offset 0.5 0 -0.5 -1 -1.5 5 5.5 6 6.5 MJD 7 7.5 8 Kalman Filter Residuals (Real Data) -9 Kalman Filter Residuals (real data) 1.5 x 10 Time Offset 1 0.5 0 -0.5 -1 -1.5 2 2.5 3 3.5 MJD 4 4.5 5 Computational Issues Too many state vector components result in a significant computational overhead Observability of state vector components Direct computation vs factorisation Direct use of Kalman filter equations usually numerically stable and easy to follow. Issue of RRFM scaling if a linear frequency drift state vector component is used Clock Predictor Application May provide a close to optimal prediction in an environment that contains complex noise and deterministic characteristics If noise processes are simple e.g. WFM and no linear frequency drift then very simple predictors will work very well. Clock Predictor Equations (Prediction) xˆ (t ) F(t ) xˆ (t n n 1 ) • Repeated application of above equation. •Apply above equations with F (t ) calculated at the required prediction length t Clock Predictor Equations (PED) P(t ) F(t ) P(t )F (t ) Q(tn ) n n1 T Repeated application of above equation. Apply above equations with required prediction length t F (t ) calculated at the Example: Predicting clock offset in presence of periodic instabilities ADEV = PED/Tau Above equation exact in case of WFM and RWFM noise processes, and a reasonable approximation in other situations ADEV, HDEV, MDEV Simulated Data ADEV, HDEV MDEV Theory and Measurement 10 ADEV Measurements HDEV Measurements MDEV Measurements ADEV Theory HDEV Theory MDEV Theory -12 ADEV 10 -11 10 10 -13 -14 10 2 10 3 4 10 tau 10 5 10 6 (PED /Tau) Prediction of Space Clocks (simulated data) M ean P E D / tau -1 1 .4 P re d ictio n D e via tio n C lo ck a nd No ise P re d ictio n E rro r -1 1 .6 -1 1 .8 log P E D / tau -1 2 -1 2 .2 -1 2 .4 -1 2 .6 -1 2 .8 -1 3 -1 3 .2 -1 3 .4 2 2 .5 3 3 .5 4 lo g Ta u 4 .5 5 5 .5 ADEV, HDEV, MDEV Real Data 10 ADEV / HDEV / MDEV Prn 9 -11 ADEV / HDEV / MDEV ADEV HDEV MDEV 10 10 10 -12 -13 -14 10 2 10 3 4 10 Tau 10 5 10 6 (PED /Tau) Prediction of Space Clocks (real data) M e a n P E D / ta u -1 1 .4 P re d ic tio n D e via tio n C lo c k a nd N o is e P re d ic tio n E rro r Add plot -1 1 .6 lo g P E D / ta u -1 1 .8 -1 2 -1 2 .2 -1 2 .4 -1 2 .6 -1 2 .8 -1 3 -1 3 .2 -1 3 .4 2 2 .5 3 3 .5 4 lo g Ta u 4 .5 5 5 .5 Kalman Filter Ensemble Algorithm Most famous time and frequency application of the Kalman filter Initially assume measurements are noiseless. Measurements (Cj – C1), difference between pairs of individual clocks Estimates (T – Ci), where T is a “perfect” clock. Parameters being estimated cannot be constructed from the measurements: Badly designed Kalman filter. Problem solved using covariance x reduction Stability of Composite Timescales -14.2 Clock 1 (FFM) Clock 2 (WFM) Clock 3 (WFM) Composite Simple Composite Optimal Composite -14.4 -14.6 Log10(sy) -14.8 -15 -15.2 -15.4 -15.6 -15.8 2 2.5 3 3.5 Log10(t) 4 4.5 5 Advantage of Kalman Filter based Ensemble Algorithm Potential of close to optimal performance over a range of averaging times Clasical Ensemble Algorithms provide a very close to optimal performance at a single averaging time Combining TWSTFT and GPS Common-View measurements Time transfer noise modelled using Markov Noise processes Calibration biases modelled using long relaxation time Markov Real Time Transfer Data Example 6.5 x 10 -8 Measurements actually used GPS CV TWSTFT 6 Time-Offset (s) 5.5 5 4.5 4 3.5 3 2.5 5.4405 5.441 5.4415 MJD 5.442 5.4425 x 10 4 Kalman Filter Estimates 5.5 x 10 -8 True time-offset and estimates Estimated Time-Offset Time-Offset (s) 5 4.5 4 3.5 5.4405 5.441 5.4415 MJD 5.442 5.4425 x 10 4 Kalman Filter Residuals 8 x 10 -9 Kalman Filter Residuals GPS CV TWSTFT 6 4 Time-Offset (s) 2 0 -2 -4 -6 -8 -10 -12 5.4405 5.441 5.4415 MJD 5.442 5.4425 x 10 4 Summary Operation of the Kalman filter Stochastic and deterministic models for time and frequency applications Real examples of use Kalman Filter Title of Presentation Name of Speaker DateThe National Measurement System delivers world-class measurement science & technology through these organisations The National Measurement System is the UK’s national infrastructure of measurement Laboratories, which deliver world-class measurement science and technology through four National Measurement Institutes (NMIs): LGC, NPL the National Physical Laboratory, TUV NEL The former National Engineering Laboratory, and the National Measurement Office (NMO).