Fault Detection: Innovations, Mahalanobis Distance, and Sub-Filter Isolation#
This demo extends the 5-state tight-coupled EKF from Block 7 with GPS fault injection and three layers of chi-squared innovation monitoring. The scenario is the same canonical 2D GPS setup, but now one satellite gets a steadily-growing pseudorange bias that the filter has no way to know about. The job is to detect the fault from the symptom (the filter’s own innovation residuals) and isolate which satellite is responsible.
The demo is built around three coupled monitoring views, each addressing one stage of the detection-and-isolation pipeline. In the vocabulary of the Block 8 reading’s detection ladder, views ① and ② are rungs 2 and 4. The reading’s rung 3, stacking all \(N\) satellites at one epoch (\(\sum_s D^2_s \sim \chi^2(N)\)), is an optional panel on view ① (tick add rung 3):
Single \(D^2_k\) (rung 2): the Mahalanobis distance per satellite per measurement, the \(1 \times 1\) case \(D^2 = \nu^2/S \sim \chi^2(1)\), against the threshold \(\gamma_1\). Catches large faults instantly but struggles with slow ramps.
Running \(M\)-window \(\Lambda_k = \sum D^2_j\) (rung 4): temporal accumulation (one satellite over its last \(M\) samples), \(\Lambda_k \sim \chi^2(M)\), against the threshold \(\gamma_M\). A more powerful slow-ramp test.
Sub-filter isolation matrix: \(N \times N\) grid of running-window tests across \(N\) sub-filters, each excluding one satellite. Identifies which satellite is faulty by exclusion.
The headline pedagogical contrast is that the per-satellite tests in views ① and ② can detect a fault but cannot tell which sat is the source, because once the fault corrupts the filter state, every satellite’s \(h(\hat{\mathbf{x}})\) is wrong and every innovation grows. The sub-filter matrix in view ③ is the only way to isolate cleanly.
The detection statistic#
For each scalar pseudorange update at satellite \(i\), the EKF produces an innovation \(\nu_i\) and an innovation variance \(S_i = \mathbf{H}_i \mathbf{P}^- \mathbf{H}_i^\top + \sigma_\rho^2\). The Mahalanobis distance is
Under the null hypothesis (no fault), \(D^2_i \sim \chi^2(1)\) with \(\gamma_{1,\,0.95} \approx 3.84\). Under a ramp fault \(b_f(t) = \dot{b}_f \cdot (t - t_0)\) on satellite \(i\), the innovation picks up a growing bias \(\nu_i \approx v_i + b_f(t)\) while \(S_i\) stays unchanged (the filter has no idea anything is wrong), so \(D^2_i\) climbs.
The single-sample test \(D^2_i > \gamma_1\) is sensitive to large step faults but slow on ramps: at low \(\dot{b}_f\), the noise term in \(\nu_i\) dominates for many samples before the bias lifts the test statistic over the threshold. Aggregating the last \(M\) samples of the same satellite in a sliding window pools the evidence (temporal accumulation, rung 4):
with \(\gamma_M = \chi^2_{M,\,0.95}\) from the \(M\)-DOF chi-squared distribution (\(\gamma_M = 43.77\) for \(M = 30\)). Healthy innovations are white, so the \(M\) terms are independent \(\chi^2(1)\) draws. The healthy statistic therefore has mean \(M\) and standard deviation \(\sqrt{2M}\), and at 5% \(\gamma_M\) sits about 1.8 of those standard deviations above the mean (\(43.77 = 30 + 1.78\sqrt{60}\)). Its margin over the healthy mean therefore grows only like \(\sqrt{M}\), while a persistent bias adds to every one of the \(M\) terms, so its contribution grows in proportion to \(M\). That is why the windowed test is more sensitive to slow faults. Do not confuse this with spatial stacking (rung 3): \(\chi^2(5)\) for five satellites at one instant and \(\chi^2(30)\) for one satellite over 30 updates are the same test pointed along different axes. With sequential scalar updates and a linear measurement model the per-satellite \(D^2_s\) at one epoch are independent, so the rung-3 sum is exactly \(\chi^2(N)\); with the EKF’s linearization it is a close approximation.
Why the per-satellite tests are not enough#
When a fault corrupts the main filter’s state, the next prediction \(\hat{\mathbf{x}}^-\) is wrong. The predicted measurement \(h_j(\hat{\mathbf{x}}^-)\) is therefore wrong for every satellite, not just the faulted one. Innovations grow on healthy satellites too, and the per-sat windowed test starts firing on multiple sats. Detection works, but isolation fails.
The fix: run \(N\) sub-filters in parallel, each excluding one satellite from its updates. Sub-filter \(f\) never sees satellite \(f\)’s pseudorange. If satellite \(f\) is the faulted one, sub-filter \(f\)’s state stays clean, and so do all of its innovations. Every other sub-filter still ingests the bad sat’s measurement and gets corrupted. The clean column in an \(N \times N\) matrix of running \(D^2\) sums identifies the culprit.
Interactive demo#
The default scenario injects a ramp fault on SAT 3 at \(t_0 = 60\) s with \(\dot{b}_f = 3\) m/s on top of a 5-satellite, evenly spread constellation with \(\sigma_\rho = 5\) m and a window of \(M = 30\) updates (30 s at 1 Hz). The demo starts paused and plays when you scroll it into view; the trajectory, the \(|e_H|\) strip under it, and the monitoring views all follow one time cursor. The chips above the plots set the detection false-alarm rate \(P_{FA}\) (5%, 1% or 0.1%) for \(\gamma_1\), \(\gamma_M\) and the rung-3 threshold; \(\gamma_\text{iso}\) stays at 0.1%. The table under the plots counts each test’s alarms before \(t_0\). It reports the first alarm that turns on after \(t_0\), the time to detect \(T_D = t_D - t_0\), and the satellite that alarmed first. An alarm already on at \(t_0\) is a pre-fault false alarm: the table flags it and does not count it as detection. A ramp rate of 0 injects no fault, and the demo then labels every alarm after \(t_0\) as false.
The plots never color or label the faulted satellite, but the summary names the satellite each test flags and, on view ③, the satellite the matrix isolates. To work it out yourself, tick mystery fault: the demo then hides which satellite is faulted (Reseed draws a new one) and keeps the verdict hidden until you press Reveal.
Walkthrough#
The numbers below are for the default seed. Reseed draws a different noise sequence, so the times move, but the pattern holds.
Watch the pre-fault behavior (scrub to \(t = 60\) s). All five sub-filter tracks (SF1–SF5, dashed) cluster around the main filter, within 4–10 m of truth. The tests already fire. In view ①, the single \(D^2_k\) panels cross \(\gamma_1 = 3.84\) 17 times in 300 tests, spread over all five satellites; 5% of 300 is 15. In view ②, the window \(\Lambda_k\) crosses \(\gamma_M = 43.77\) in 8 of 155 tests, all on SAT 4 between 44 and 51 s. Consecutive windows share 29 of their 30 terms, so one noisy stretch trips several windows in a row. The count therefore clumps around its average of 7.8 (5% of 155). Across 3000 seeds the count averages 7.9 with a standard deviation of 10; about 36% of runs have none and about 15% have 20 or more. This is what a 5% threshold buys, and the table’s “Alarms with no fault” column counts it. All five columns of the isolation matrix are clean.
The fault injects at \(t_0 = 60\) s. The trajectory header switches from
pre-faulttoFAULT ACTIVE · bias X m, with X growing at 3 m/s. The main filter drifts away from truth: \(|e_H|\) is 6 m at 60 s, 24 m at 80 s, 109 m at 150 s and 287 m at 300 s. The strip under the trajectory plots \(|e_H|\) against the main filter’s own 95% radius on a log scale.View ① · Single \(D^2_k\). SAT 3’s \(D^2\) first crosses \(\gamma_1\) at 68 s and stays above from 71 s. But the table’s first alarm after \(t_0\) is SAT 4 at 62 s, a healthy satellite, when the bias on SAT 3 is only 6 m. SAT 4’s \(D^2\) there is 4.04; with the ramp at 0 the same sample is 2.75. So the alarm is noise plus the first trace of the fault, leaking into SAT 4’s innovation through the shared filter state. The table credits it with \(T_D = 2\) s, but it names a healthy satellite and mostly reflects luck: a small nudge pushed a noisy sample just over \(\gamma_1\). Within seconds the healthy satellites follow SAT 3 up: SAT 2 stays above from 72 s, SAT 4 from 76 s, SAT 5 from 88 s and SAT 1 from 120 s. Tick add rung 3 to see the one-epoch stack \(\sum_s D^2_s\) against \(\chi^2_{5,\,0.95} = 11.07\); its first alarm after \(t_0\) is at 68 s.
View ② · Window \(\Lambda_k\). Same five panels, now the sum over the last 30 updates (rung 4). The first window alarm to turn on after \(t_0\) is SAT 5 at 69 s (\(T_D = 9\) s), then SAT 4 at 71 s, SAT 3 at 72 s, SAT 2 at 73 s and SAT 1 at 79 s, and all five stay above to the end. Detection works; isolation fails. The first satellite to alarm is a healthy one, because once the main filter is corrupted every satellite’s innovations are wrong. At 3 m/s the window is not faster than the single test; its advantage shows on slow ramps (step 7).
View ③ · Sub-filter isolation matrix. A \(5 \times 5\) grid: row = satellite being monitored, column = sub-filter SF\(f\), which excludes SAT \(f\). The threshold is the stricter \(\gamma_\text{iso} = \chi^2_{M,\,0.999} = 59.70\) for \(M = 30\), which keeps false isolations rare when \(N\) columns are compared at once. Most cells climb after \(t_0\). Find the column where every cell stays below the threshold. SF3 becomes the only clean column at 76 s (16 s after \(t_0\)) and stays the only one to the end, so SAT 3 is the culprit. The line under the table reports the same verdict.
Verify on the trajectory. The sub-filter tracks are on by default; uncheck show sub-filter tracks to hide them. SF3, the only sub-filter that never used SAT 3, stays with truth while the other four drift off with the main filter. At 300 s SF3 is 1.1 m from truth and the others are 360–422 m away. With the default centering on the main filter, truth leaves the ±75 m window and an edge arrow shows how far away it is. Tick center the trajectory on truth to hold truth still and watch the main filter leave instead.
Slide the ramp rate. At \(\dot{b}_f = 10\) m/s, SAT 3’s single \(D^2\) stays above from 64 s and every satellite is above by 72 s; the window alarms at 63 s and SF3 isolates at 68 s. At \(\dot{b}_f = 0.5\) m/s the single test struggles: SAT 3 first crosses at 87 s but stays above only from 122 s, 62 s after \(t_0\). SAT 3’s window crosses at 93 s and stays above from 95 s, 35 s after \(t_0\), about 27 s ahead of the single test. The table’s first window alarm at 0.5 m/s (SAT 5 at 73 s) is not a detection. Set the ramp to 0 to check. The demo then says “no fault injected”, labels every alarm after \(t_0\) as false, and shows \(T_D\) and HMI exposure as n/a. The same SAT 5 window alarm still appears at 73 s. Back at 0.5 m/s, SF3 still isolates, at 121 s, and \(|e_H|\) reaches 47 m by 300 s.
Change \(P_{FA}\) (back at 3 m/s). At 1% the window’s pre-fault alarms vanish (0 of 155), and its first alarm is SAT 4 at 71 s. At 0.1% the single test drops to 1 false alarm in 300, and the window first alarms on SAT 4 at 72 s (\(T_D = 12\) s). The cost shows on the slow ramp. At 0.5 m/s and 0.1%, the first window alarm comes at 101 s on SAT 3 (\(T_D = 41\) s), and the no-fault run raises no window alarm at all. Fewer false alarms cost time to detect.
Slide the window \(M\) (3 m/s, 5%). At \(M = 5\) (\(\gamma_M = 11.07\), \(\gamma_\text{iso} = 20.52\)) the window is noisy: 24 pre-fault alarms in 280 tests, against 14 expected. Isolation comes sooner (SF3 at 72 s) but is fragile. At 220 s even the clean SF3 column crosses \(\gamma_\text{iso}\) for one epoch, and on the 0.5 m/s ramp the verdict drops out at 15 epochs between 124 and 220 s. At \(M = 60\) (\(\gamma_M = 79.08\), \(\gamma_\text{iso} = 99.61\)) the first window fills only at \(t = 60\) s, so there are just 5 pre-fault tests. Isolation waits until 79 s but never flickers. The first window alarm is at 69 s for both. There is no universally best \(M\); this is the operational tuning trade.
Change the faulted satellite. The clean column follows it: a fault on SAT 1 isolates SF1 at 76 s, and a fault on SAT 5 isolates SF5 at 74 s. Or tick mystery fault and find it yourself.
Change the number of satellites. With 4 satellites, a banner explains why the matrix cannot isolate. Each sub-filter keeps 3 satellites for 3 unknowns, so its own innovations cannot expose the fault. After \(t_0\) every cell stays under \(\gamma_\text{iso}\) (column maxima 53.2–58.0 against 59.70), and all four columns remain “clean”. Before the fault, SAT 2’s cells in SF3 and SF4 briefly reach 63.3 and 61.4, above \(\gamma_\text{iso}\) from 54 to 58 s. That pre-fault excursion knocks out two columns for a few seconds but never leaves exactly one clean. The main-filter windows still alarm. SAT 2’s window was already above \(\gamma_M\) at \(t_0\), a pre-fault run that the table flags and does not count, and the first window alarm to turn on afterward is SAT 1 at 69 s. Even so, the main filter ends 360 m from truth with a 95% radius of 5.8 m, and nothing names the culprit. With 6 satellites SF3 isolates at 74 s. In 2D, detection needs at least 4 satellites and isolation at least 5; in 3D, 5 and 6.
Read the \(|e_H|\) strip. The dark shading marks the time between \(t_0\) and \(t_D\) that \(|e_H|\) spends above the filter’s own 95% radius, which the demo counts as HMI exposure. Its header uses the current view’s first alarm: 2.0 s on view ①, where \(t_D = 62\) s is the SAT 4 alarm from step 3, and 8.0 s on view ②, where \(t_D = 69\) s. Read those numbers with care. The radius only stands in for a protection level, and a healthy filter exceeds it about 5% of the time by design; on this seed it was above 13.3% of the time before \(t_0\). At \(t_0\) the error is already 6.04 m against a 5.30 m radius, and it stays above until 64 s. With the ramp at 0, the same seed spends 1.9 s above the radius between 60 and 62 s and 3.0 s between 60 and 69 s. So view ①’s 2.0 s is essentially noise, and about 3 s of view ②’s 8.0 s would have happened without any fault.
Key observations#
Single-sample \(D^2\) (rung 2) catches step faults; the window \(\Lambda_k\) (rung 4) catches ramps. The former trades slow-fault sensitivity for instant response on big jumps; the latter trades instant response for robustness on slow drifts. Real systems run both in parallel and OR the alarms.
The filter’s covariance becomes inconsistent under an undetected fault. The main filter’s 95% covariance ellipse on the trajectory stays small while the actual position error blows up. At 300 s, \(|e_H| = 287\) m against the filter’s own 95% radius of 5.30 m (\(\sigma_p = 2.16\) m). The filter is “confidently wrong”: its \(\mathbf{P}\) is no longer a valid uncertainty estimate. This is the essence of HMI from the Block 8 reading.
Per-sat innovations are corrupted across the board. Once the fault gets into the main filter, every satellite’s predicted pseudorange \(h_j(\hat{\mathbf{x}})\) is biased, and the single and windowed tests on healthy sats start firing too. In the default run, the first satellite to alarm on either test is a healthy one. There is no way to tell from the main filter alone which channel is the actual source.
Sub-filter exclusion is the cleanest isolation strategy, given enough satellites. A sub-filter’s state stays uncorrupted only when it has excluded the faulty satellite. The matrix layout makes the answer visually obvious: scan the columns, find the one that stays uniformly low, and read off the excluded satellite. It needs two redundant measurements (5 satellites in 2D); with 4, every column stays clean.
The thresholds are tunable knobs against false-alarm rate. \(\gamma_1\) at 5% gives one false alarm per ~20 tests on each satellite (17 in 300 here). The window’s alarms come in runs, because consecutive windows overlap. \(\gamma_\text{iso}\) at 0.1% produced no false isolation in the default no-fault run. The whole game in fault-detection design is choosing where to sit on the false-alarm-vs-time-to-detect curve, and the \(P_{FA}\) chips let you move along it.
From this demo to the F-47 capstone#
The Block 8 reading frames integrity through Hazardous Misleading Information (HMI): the true error grows past the protection level while the fault is still undetected. This demo gives you the chi-squared machinery that powers HMI prevention in practice: the per-satellite test for fast detection, the windowed test for slow ramps, and sub-filter isolation for naming the offender so the system can exclude it and continue with the remaining sensors. The F-47 ANS capstone in Block 9 will require you to measure the time-to-detect \(T_D\) and the HMI exposure for a 30-event spoof dataset (Requirement 4: at least 27 of 30 events with \(T_D \le 5\) s and horizontal and vertical HMI exposure \(\le 1\) s); the same three-layer architecture above is what gets you those numbers cleanly.
Source#
MATLAB bundle · demos/FaultDetectionDemo.m↓
With the 2D covariance ellipse helper in navutils/Draw2DErrorBounds.m. The MATLAB script uses the demo’s conventions: filter at the nominal \(\hat{\mathbf{x}}_0\) with truth drawn from \(\mathbf{P}_0\), errors as estimate − truth, updates at 1 Hz, \(M\) counted in updates, and exact chi-squared thresholds set by P_FA (default 0.05) and P_FA_iso (0.001). It draws five figures: \(|e_H|\) against the 95% radius and an illustrative HPL, single \(D^2\) with the rung-3 sum, windowed \(\Lambda_k\), the sub-filter matrix, and an animated trajectory (animate = false skips it). It also prints the same detection table as the demo. Its thresholds match the demo (3.84, 11.07, 43.77, 59.70), but its random draws (rng(4)) differ from the demo’s seeded generator, so its timings differ. In the MATLAB run, SAT 3’s window is already above \(\gamma_M\) at \(t_0\), a pre-fault false alarm that the script flags and does not count. Its 20 pre-fault window alarms, against 7.8 on average, are plausible given the clumping described in step 1. The first window alarm to turn on after \(t_0\) is SAT 4 at 68 s (\(T_D = 8\) s). SAT 3’s own window is plainly fault-driven by about 65 s, so discarding its latched alarm makes \(T_D = 8\) s an upper bound here. SF3 isolates at 70 s, and the HMI exposure is 0.1 s; its error was above the radius 9.8% of the time before \(t_0\). At 300 s, \(|e_H| = 287.6\) m against a 95% radius of 5.30 m (\(\sigma_p = 2.16\) m). The demo above unifies all five figures into a single live-playback view with a synchronized scrubber.