Block 7: Extended Kalman Filter for GPS#

By the end of this block you should be able to:

  1. Distinguish between loose-coupling and tight-coupling GPS/INS integration.

  2. Apply the standard linear Kalman filter when GPS provides a position measurement.

  3. Explain why pseudorange measurements require an Extended Kalman Filter.

  4. Compute the pseudorange Jacobian \(\mathbf{H}\) from the receiver-to-satellite geometry.

  5. Trace through one complete EKF predict-update cycle with GPS pseudoranges.

Two Ways to Fuse GPS into a Filter#

There are two architectural choices for integrating GPS into a navigation filter, and the difference comes down to whether the filter sees the GPS solver’s output or the raw pseudoranges.

Side-by-side architecture diagram. Left: pseudoranges → GPS solver → position → linear KF. Right: pseudoranges → EKF directly → 5-state output.

Fig. 1.1. The two GPS/filter integration patterns. Loose coupling pre-solves the four-unknown GPS problem and feeds the result to a linear KF. Tight coupling skips the pre-solve and lets the EKF process raw pseudoranges, taking over the clock-bias estimation as part of its state.

Loose coupling#

In the loose-coupling pattern, a GPS solver runs first (the same NLLS routine from Block 6), produces a solved position \(\hat{\mathbf{p}}\) and a covariance, and the filter ingests that as a linear position measurement:

\[ \mathbf{z}_k = \hat{\mathbf{p}}_k + \mathbf{v}_k, \qquad \mathbf{v}_k \sim \mathcal{N}(\mathbf{0}, \mathbf{R}). \]

The observation matrix \(\mathbf{H} = [\mathbf{I}\ |\ \mathbf{0}]\) is the same one we used for the position-only sensor in Block 5. No extra math, no Jacobians: it is a standard linear Kalman filter update. \(\mathbf{R}\) is set from the GPS accuracy specification. Block 6’s \(\sigma_{\text{horiz}}^2 = (\mathrm{HDOP}\times\sigma_\rho)^2\) is the total horizontal variance (north plus east), so a 2D filter splits it per axis, \(\mathbf{R} \approx \tfrac{1}{2}(\mathrm{HDOP}\times\sigma_\rho)^2\,\mathbf{I}_2\); more exactly, \(\mathbf{R}\) is the position block of the solver’s covariance \(\sigma_\rho^2(\mathbf{H}^{\top}\mathbf{H})^{-1}\), where \(\mathbf{H}\) here is the solver’s stacked pseudorange geometry, not the filter’s \([\mathbf{I}\ |\ \mathbf{0}]\).

Tight coupling#

In the tight-coupling pattern, the filter ingests raw pseudoranges directly:

\[ \tilde{\rho}_i = \lVert \mathbf{p} - \mathbf{s}^{(i)} \rVert + b + \epsilon_i. \]

This measurement model is nonlinear in user position, so the standard KF, which requires \(\mathbf{z} = \mathbf{H}\mathbf{x} + \mathbf{v}\), cannot be applied directly. The fix is the Extended Kalman Filter (EKF): linearize \(h_i(\mathbf{x})\) around the current best estimate, and run the standard KF update with that linearized \(\mathbf{H}\).

Tight coupling is preferred in practice because:

  • The filter degrades gracefully when only one or two satellites are visible. A loose-coupling GPS solver needs four satellites just to produce an output; an EKF can update on whatever satellites it sees.

  • The clock bias becomes part of the navigation state, so the filter learns the clock dynamics over time.

  • The error model is more honest: the filter uses the real pseudorange uncertainty rather than the post-solve position uncertainty, which has been smoothed by the NLLS solver.

The demo in this block (and its optional MATLAB companion, ExtendedKalmanFilter5D.m) runs the tight-coupling case. The 4-state Block 5 demo with a position-only sensor IS the loose-coupling case, just relabeled.

The Tight-Coupling Challenge#

The standard Kalman update equation requires a linear measurement model:

\[ \mathbf{z} = \mathbf{H}\mathbf{x} + \mathbf{v}. \]

There is no matrix \(\mathbf{H}\) that exactly represents a Euclidean range. That is what “nonlinear” means. The way out is to approximate the nonlinear function with a tangent hyperplane at every step and let the filter run on the approximation. As long as the approximation error is small relative to the measurement noise, the filter behaves nearly identically to the linear case.

EKF Key Idea: Linearization#

Replace \(h(\mathbf{x})\) with its first-order Taylor expansion around the current predicted state:

\[ h(\mathbf{x}) \approx h(\hat{\mathbf{x}}^-) + \underbrace{\frac{\partial h}{\partial \mathbf{x}}\bigg|_{\hat{\mathbf{x}}^-}}_{\mathbf{H}} \big(\mathbf{x} - \hat{\mathbf{x}}^-\big). \]

The matrix \(\mathbf{H}\) is the Jacobian of \(h\) evaluated at \(\hat{\mathbf{x}}^-\). The innovation now uses the nonlinear function while the gain and covariance updates use the linearized \(\mathbf{H}\):

\[ \nu_k = z_k - h(\hat{\mathbf{x}}_k^-), \qquad z_k = \tilde{\rho}_k. \]

Keep the two terms straight: \(z_k\) is what the receiver measured (here the pseudorange \(\tilde{\rho}_k\)), and \(h(\hat{\mathbf{x}}_k^-)\) is what the filter predicted it would measure from its prior estimate. The innovation is measured minus predicted.

After that, every other equation is identical to the linear KF of Block 5. The only addition is that the Jacobian must be re-evaluated at every step, because \(\hat{\mathbf{x}}^-\) changes from cycle to cycle. That re-evaluation is what people mean when they say the EKF “re-linearizes” at every step.

A nonlinear curve h(x) with a tangent line drawn at the operating point x-hat. The slope of the tangent is labeled H.

Fig. 2.1. The EKF replaces \(h(x)\) by its tangent line at \(\hat{x}^-\). The slope of the tangent is the Jacobian \(\mathbf{H}\). As the estimate moves between cycles, the tangent point moves with it; this is why the EKF is non-optimal in general (it ignores higher-order terms) and why filter divergence is a real failure mode if the linearization is bad.

Key Concept

The EKF reuses the entire Kalman filter machinery; the only change is that \(\mathbf{H}\) is recomputed at every step from a Jacobian, and the innovation uses the nonlinear measurement function.

Extending the State for GPS#

To use pseudoranges directly, we have to add the receiver clock bias \(b\) as a state. Building on the 4-state filter from Block 5, the 2D tight-coupling state vector becomes

\[ \mathbf{x} = \begin{bmatrix} p_x & p_y & v_x & v_y & b \end{bmatrix}^{\top}. \]

The clock bias \(b\) has units of meters (range-equivalent receiver timing error). We typically model it as a random walk or a slow Gauss-Markov process: the time constant of receiver-clock drift is much longer than the navigation update interval, so the bias is essentially constant from one fix to the next but drifts measurably over minutes to hours.

Every pseudorange equation includes \(b\) in the same way: \(\tilde{\rho}_i = \lVert \mathbf{p} - \mathbf{s}^{(i)} \rVert + b + \epsilon_i\). With one extra state and the same predict-update cycle, the EKF estimates \(b\) automatically alongside position and velocity. The full 3D version uses a 7-state vector \([p_x, p_y, p_z, v_x, v_y, v_z, b]^{\top}\): same idea, bigger matrices.

These are the Block 6 quantities under shorter names: the receiver position \(\mathbf{p}\) is Block 6’s \(\mathbf{r}_u\), the satellite position \(\mathbf{s}^{(i)}\) is \(\mathbf{r}^{(i)}\), and the clock bias \(b = c\,\delta t_u\) is the receiver clock offset expressed in meters.

State count: the +1 is always the clock bias#

Tight coupling adds exactly one state to whatever navigation filter you already have, and that state is always the receiver clock bias \(b\):

Filter

Navigation states

Count

+ clock

Total

Demo (2D, this block)

\(p_x, p_y, v_x, v_y\)

4

\(+\,b\)

5

3D teaching filter

position, velocity

6

\(+\,b\)

7

Operational INS/GPS

position, velocity, attitude, accelerometer bias, gyro bias (Block 5)

15

\(+\,b\)

16

Demo vs. operational

The 5-state 2D filter in this block’s demo and Quick Exercise is a teaching model: the same equations with small matrices. The operational tightly coupled INS/GPS filter is the 16-state one: Block 5’s 15 error states plus \(b\). Its pseudorange row has the same pattern you will derive below: the unit vector under the position states, 0 under everything else, and 1 under \(b\). (Many receivers also carry the clock drift as a 17th state; the +1 we track in this course is the bias.)

The Pseudorange Jacobian#

The measurement function for satellite \(i\) is

\[ h_i(\mathbf{x}) = \lVert \mathbf{p} - \mathbf{s}^{(i)} \rVert + b = \rho_i + b. \]

where \(\rho_i\) is the geometric range,

\[ \rho_i = \sqrt{\big(p_x - s_x^{(i)}\big)^2 + \big(p_y - s_y^{(i)}\big)^2}. \]

Differentiate with respect to one state at a time:

\[ \frac{\partial h_i}{\partial p_x} = \frac{p_x - s_x^{(i)}}{\rho_i}, \qquad \frac{\partial h_i}{\partial p_y} = \frac{p_y - s_y^{(i)}}{\rho_i}, \qquad \frac{\partial h_i}{\partial v_x} = \frac{\partial h_i}{\partial v_y} = 0, \qquad \frac{\partial h_i}{\partial b} = 1. \]

The position partials come from the chain rule on the square root, the velocity partials vanish because range has no instantaneous dependence on velocity, and the bias partial is 1 because \(b\) adds straight on. Evaluated at the prior, the \(1\times 5\) Jacobian is

\[ \mathbf{H}_i = \frac{\partial h_i}{\partial \mathbf{x}}\bigg|_{\hat{\mathbf{x}}^-} = \begin{bmatrix} \hat{e}_x & \hat{e}_y & 0 & 0 & 1 \end{bmatrix}, \]

where the unit vector from satellite \(i\) to the receiver is

\[ \hat{e}_x = \frac{\hat{p}_x - s_x^{(i)}}{\rho_i},\qquad \hat{e}_y = \frac{\hat{p}_y - s_y^{(i)}}{\rho_i}. \]

The denominator is the geometric range

The denominator in \(\hat{e}_x\) and \(\hat{e}_y\) is the geometric range \(\rho_i\), not the pseudorange \(\rho_i + b\). The clock bias never enters the denominator; it appears only as the separate \(+1\) in its own column.

The structure is clean and operationally meaningful:

  • The first two entries are the unit vector from satellite \(i\) to the receiver, \(\hat{\mathbf{e}}_i = (\hat{\mathbf{p}}^- - \mathbf{s}^{(i)})/\rho_i\), the negative of the receiver-to-satellite line of sight \(\hat{\mathbf{u}}_i = (\mathbf{s}^{(i)} - \hat{\mathbf{p}}^-)/\rho_i = -\hat{\mathbf{e}}_i\). They tell the filter how a small move in user position changes the predicted pseudorange, \(\Delta h_i \approx \hat{\mathbf{e}}_i^{\top}\Delta\mathbf{p}\): stepping directly away from the satellite lengthens the range one-for-one, and stepping toward it shortens the range one-for-one.

  • The velocity entries are zero. Pseudoranges do not depend instantaneously on velocity, so the Jacobian has no velocity sensitivity.

  • The clock-bias entry is exactly 1, because the clock bias adds linearly to every pseudorange.

The 3D version extends the unit-vector block to three components and pads the rest with zeros: \(\mathbf{H}_i = [\hat{e}_x, \hat{e}_y, \hat{e}_z, 0, 0, 0, 1]\).

This is the same Jacobian the GPS NLLS solver in Block 6 uses internally; the EKF is just running it inside a recursive predict-update loop instead of inside a batch optimizer.

So what? One pseudorange sees one direction#

Linearized, satellite \(i\) senses only the projection of the position error onto its own line of sight:

\[ \Delta h_i \approx \hat{\mathbf{e}}_i^{\top}\,\Delta\mathbf{p} + \Delta b. \]

Any position error perpendicular to that line is invisible to satellite \(i\). That is why a receiver needs satellites in diverse directions: stacking their rows (position and clock columns only),

\[\begin{split} \mathbf{H} = \begin{bmatrix} \hat{\mathbf{e}}_1^{\top} & 1 \\ \vdots & \vdots \\ \hat{\mathbf{e}}_m^{\top} & 1 \end{bmatrix}, \qquad \mathrm{cov}(\hat{\mathbf{x}}) = \sigma_\rho^2\,(\mathbf{H}^{\top}\mathbf{H})^{-1}, \qquad \mathrm{GDOP} = \sqrt{\operatorname{tr}\,(\mathbf{H}^{\top}\mathbf{H})^{-1}}, \end{split}\]

and the DOP figures of Block 6 measure how well those rows span every direction (HDOP, VDOP, PDOP and TDOP are square roots of the matching diagonal entries of \((\mathbf{H}^{\top}\mathbf{H})^{-1}\), summed over the horizontal or position components for HDOP and PDOP). The sign convention of \(\hat{\mathbf{e}}_i\) does not matter for DOP: flipping every \(\hat{\mathbf{e}}_i\) flips the position–clock cross terms of \(\mathbf{H}^{\top}\mathbf{H}\), but leaves the diagonal of \((\mathbf{H}^{\top}\mathbf{H})^{-1}\), and so every DOP, unchanged. Well-spread satellites give nearly orthogonal rows and small DOP; clustered satellites give nearly parallel rows and a large DOP along the cluster’s line of sight. In 3D there are four unknowns (three position components plus the clock), so a snapshot fix needs at least four satellites (three in 2D). Every row carries the same \(+1\) in the clock column, so every pseudorange is sensitive to \(b\), but \(b\) separates from position only when the stacked \(\mathbf{H}\) has full column rank: at least three satellites in 2D or four in 3D, and in 3D not all on a common cone around one axis. Two satellites in 2D, even with distinct lines of sight, leave one combination of position and clock unobserved, and the filter’s \(\sigma_b\) keeps growing. (A recursive EKF can still update with fewer satellites, because its prior carries the missing directions forward.)

The EKF Predict-and-Update Loop#

The propagation step is unchanged from the linear KF:

\[ \hat{\mathbf{x}}^- = \mathbf{F}\,\hat{\mathbf{x}}^+, \qquad \mathbf{P}^- = \mathbf{F}\,\mathbf{P}^+\,\mathbf{F}^{\top} + \mathbf{Q}. \]

The update step runs once per visible satellite. For satellite \(i\):

\[ \nu_i = z_i - h_i(\hat{\mathbf{x}}^-), \quad z_i = \tilde{\rho}_i \qquad \text{(nonlinear innovation)} \]
\[ S_i = \mathbf{H}_i\,\mathbf{P}^-\,\mathbf{H}_i^{\top} + \sigma_\rho^2, \qquad \mathbf{K}_i = \mathbf{P}^-\,\mathbf{H}_i^{\top}\,S_i^{-1} \]
\[ \hat{\mathbf{x}}^+ = \hat{\mathbf{x}}^- + \mathbf{K}_i\,\nu_i, \qquad \mathbf{P}^+ = \mathbf{P}^- - \mathbf{K}_i\,\mathbf{H}_i\,\mathbf{P}^-. \]

Notice the innovation uses \(h_i\) (the full nonlinear function) but the gain and covariance updates use \(\mathbf{H}_i\) (the linearized Jacobian). The scalar \(S_i\) is the innovation variance: how large the filter expects \(\nu_i\) to be. It returns in Block 8 as the yardstick for deciding whether an innovation is suspicious. After processing satellite \(i\), the posterior \(\hat{\mathbf{x}}^+\) becomes the prior for satellite \(i+1\), with the Jacobian re-evaluated at the new estimate. Because the pseudorange noises are uncorrelated (diagonal \(\mathbf{R}\)), sequential processing gives exactly the same posterior as one stacked matrix update for a linear model; with the EKF’s relinearization between satellites the two differ slightly. Sequential one-satellite-at-a-time processing is much cleaner than stacking all satellites into one matrix update, and it generalizes naturally to mixed-rate sensors (each satellite can update at its own cadence).

Quick Exercise

Given a 5-state EKF in 2D with

\[ \hat{\mathbf{x}}^- = [0,\ 0,\ 10,\ -5,\ 20]^{\top}\ \text{m},\quad \mathbf{P}^- = 100\,\mathbf{I}_5,\quad \mathbf{s} = [3000,\ 4000]^{\top}\ \text{m},\quad \tilde{\rho} = 5035\ \text{m},\quad \sigma_\rho^2 = 100\ \text{m}^2, \]

walk through one full update step.

EKF / GPS Pseudorange Demo#

The 5-state EKF demo in this block runs the full tight-coupling filter on a 2D scenario: 5-state \([p_x, p_y, v_x, v_y, b]^{\top}\) with constant-velocity kinematics, a random-walk clock-bias model, and four GPS satellites delivering scalar pseudorange measurements at individually-controllable cadences. A sky compass lets you drag satellites around to change the geometry; per-satellite toggles let you turn individual satellites off and watch the filter degrade gracefully, including the operationally critical one- and two-satellite cases where the Block 6 black-box solver would collapse (a 2D fix needs three directions; with fewer, the filter coasts on its motion and clock models and its bounds grow along the unobserved direction). Each pseudorange goes through one scalar EKF update with a 1×5 Jacobian (a Last-update card shows \(\hat{\mathbf{e}}_i\), \(\mathbf{H}_i\), \(\nu_i\), \(S_i\), and \(\mathbf{K}_i\) for the most recent one, and an HDOP line tracks the geometry), and all the standard live-trajectory + per-state error panels follow the same animation pattern as the Block 5 KF demos. A MATLAB implementation is also included at demos/ExtendedKalmanFilter5D.m.

Wrap-Up#

Loose coupling pre-solves GPS into a position estimate and feeds that to a linear KF. Tight coupling feeds raw pseudoranges into the filter directly, which forces an Extended Kalman Filter to handle the nonlinear range equation. The EKF replaces \(h(\mathbf{x})\) with its tangent at the current best estimate, runs the standard KF update with that linearized Jacobian, and re-linearizes at every cycle. Adding the clock bias as a state gives the EKF a self-contained tightly-coupled GPS/INS framework. The Jacobian’s first two entries are the unit vector from the satellite to the receiver (the negative of the line of sight, over the geometric range \(\rho_i\)), the velocity entries are zero, and the clock-bias entry is one. That compact structure is the whole reason the EKF works on pseudoranges, and it is also why satellite geometry (DOP) decides what the filter can see. Whatever the filter size (the 5-state demo, a 7-state 3D filter, or the 16-state operational INS/GPS filter), the extra state is the clock bias.

The next block confronts the assumption every filter we have built so far has quietly relied on: that the sensors are well-behaved. What happens when a satellite is spoofed, when the pseudorange grows a steady bias, when a measurement starts to lie? That is the topic of Block 8: fault detection, integrity, and HMI.