Skip to main content

Module detection

Module detection 

Source
Expand description

Detection-theory primitives for the spoof monitor.

A clock-aided spoof monitor forms a test statistic y — the discrepancy between the GNSS-asserted time and the clock’s own coasted prediction over a window — with 1σ uncertainty σ. The two hypotheses are

  H0 (no spoof):  y ~ N(0, σ²)
  H1 (spoof):     y ~ N(μ, σ²)

where μ is the spoof offset present at the decision. Because the spoof can drag time in either direction, the deployed detector is the two-sided energy test T = (y/σ)² > λ, with T ~ χ²₁ under H0 — so the threshold λ is read straight off the inverse χ²₁ CDF for a target false-alarm probability P_fa. For a known-sign shift this is the Neyman–Pearson-optimal test (the log-likelihood ratio llr is monotone in |y|); the two-sided form keeps it optimal against either attack direction.

From the threshold the operating characteristics are closed form:

  γ      = σ · Φ⁻¹(1 − P_fa/2)              (the |y| detection boundary)
  P_md   = Φ((γ−μ)/σ) − Φ((−γ−μ)/σ)         (missed detection at offset μ)

monte_carlo_pfa_pmd re-derives P_fa and P_md empirically by drawing noise-only and signal-plus-noise realisations and applying the same test, so the analytic and simulated probabilities can be cross-checked.

Functions§

analytic_pd
Closed-form detection power P_d = 1 − P_md.
analytic_pmd
Closed-form missed-detection probability for a spoof offset mu against noise sigma with the two-sided boundary gamma: P_md = Φ((γ−μ)/σ) − Φ((−γ−μ)/σ).
chi2_1_threshold
The χ²₁ energy-detector threshold λ for a target P_fa: λ = [Φ⁻¹(1−P_fa/2)]², so that P(χ²₁ > λ) = P_fa. Detect when (y/σ)² > λ.
chi2_inv_cdf
Inverse CDF (quantile) of the χ² distribution with dof degrees of freedom, via the Wilson–Hilferty cube-root-normal approximation: χ²_p(k) ≈ k·(1 − 2/(9k) + z·√(2/(9k)))³, with z = Φ⁻¹(p).
detection_boundary
The two-sided |y| detection boundary γ = σ·Φ⁻¹(1 − P_fa/2) for a target false-alarm probability — equivalently σ·√λ for the χ²₁ energy threshold λ.
erf
Error function via Abramowitz & Stegun 7.1.26 (max abs error 1.5e-7).
llr
Log-likelihood ratio log[p(y|H1)/p(y|H0)] for a mean shift mu in Gaussian noise of standard deviation sigma (equal variance under both hypotheses): LLR(y) = (y − 0)²/(2σ²) − (y − μ)²/(2σ²) = (μ·y)/σ² − μ²/(2σ²). Monotone in y, so thresholding the LLR is equivalent to thresholding y (the deployed detector uses the two-sided energy form to catch either-sign offsets).
monte_carlo_pfa_pmd
Monte-Carlo estimate of (P_fa, P_md) for the two-sided detector: draw n noise-only (H0) and n signal-plus-noise (H1, mean mu) realisations of a N(·, σ²) statistic and apply |y| > gamma. Deterministic in seed.
normal_cdf
Standard normal cumulative distribution function Φ(x).
normal_inv_cdf
Standard normal inverse CDF (probit) Φ⁻¹(p) for p ∈ (0,1) — Acklam’s rational approximation (relative error ≲ 1.15e-9). Saturates at ±∞ for p at the ends.