Skip to content

The Loop Filter

Every tracking loop in doppler — carrier, code, symbol timing, gain — is the same three pieces: a discriminator that says how wrong, a filter that turns a noisy sequence of those into a stable estimate, and an oscillator or interpolator that applies it. The discriminators are all different, because what "wrong" means is different every time. The oscillators are the NCO and the resampler. The filter is one object, embedded by value in seven of them.

This page is the why: what the filter promises, what its one parameter bn actually means, the condition under which that promise holds — which is the part that is easy to violate and invisible when you do — and what it deliberately does not do.

The contract lives in native/inc/doppler/loop_filter/loop_filter_core.h and the C-level evidence in native/tests/loop_filter/test_loop_filter_core.c. This page does not restate either; it explains the reasoning they assume.

Related: The Exponential Moving Average, The NCO, RateSync — timing, MPSK Receiver.

Status. The loop filter is certified: its validation report (src/doppler/track/tests/validation/loop_filter/results.md, generated by the validate.py beside it) measures the claims below through the binding, and native/validation/loop_filter_noise_bw.c measures the closed loop's bandwidth. Sections 1–5 describe the shipped object and the reasoning behind its present form. Section 6 states the boundaries the header declares. Section 8 is the list of questions this page set before the characterization existed, kept with what the measurement answered so the questions stay visible beside their answers.


1. What it is for

One question, asked once per loop update: given a noisy sequence of "how wrong am I" measurements, what is my best running estimate of the error's rate of change, and what correction should I apply right now?

Two answers are wanted at once, and that is why the filter is second order rather than a smoother:

  • the accumulated estimate — a carrier offset, a symbol rate, a code rate. This is memory: it must persist when the error goes to zero, because zero error is exactly what a correct estimate produces. A loop whose correction decays to nothing when it stops seeing error cannot hold a frequency.
  • the instantaneous nudge — the immediate response to this update's error, which is what gives the loop its speed and its damping.

The integrator is the first, kp*e is the second, and control = integ + kp*e is the sum. That is the whole object.

Seven objects embed it by value, through dp_loop_filter_init() or dp_loop_filter_configure():

object what its integrator holds update period
costas carrier frequency offset one symbol
carrier_mpsk carrier frequency offset one symbol
carrier_nda carrier frequency offset one discriminator look
dll code rate one code period
symsync symbol timing rate one symbol
ratesync symbol timing rate one symbol
burst_despreader carrier and code, one each per burst update

mpsk_receiver embeds it twice more through mpsk_rx_loops_t, once for carrier and once by way of ratesync_loop_t.

Seven consumers, one recursion — for the same reason the EMA is one function. A property established for one private copy says nothing about the others, and a defect fixed in one silently leaves the rest wrong; that history is written up in The NCO, which had three copies of a phase-word conversion with one of them fixed.


2. Theory of operation

The recurrence is two lines:

integ   += ki * e
control  = integ + kp * e

The gains are not free parameters. They are derived from a loop noise bandwidth bn, a damping factor zeta and an update period t, so that a caller specifies the loop's behaviour in units it can reason about rather than by tuning two numbers with no physical meaning.

2.1 Where the gains come from

For the continuous-time second-order loop, the noise bandwidth and the natural frequency are related by the standard result

Bn = wn * (zeta + 1 / (4*zeta)) / 2

dp_loop_filter_init() inverts it — that single line is the entire reason the parameter is called a noise bandwidth:

wn = 8 * zeta * bn / (4*zeta^2 + 1)

The discrete gains then follow the canonical bilinear-mapped form, with th = wn*t and den = 4 + 4*zeta*th + th^2:

kp = 8 * zeta * th / den
ki = 4 * th^2      / den

2.2 It is the textbook form, written differently

That last pair does not look like the form in the standard reference (Rice, Digital Communications: A Discrete-Time Approach, App. C), which is usually quoted as

theta = 4 * zeta * Bn * T / (4*zeta^2 + 1)
kp    = 4 * zeta * theta        / (1 + 2*zeta*theta + theta^2)
ki    = 4 * theta^2             / (1 + 2*zeta*theta + theta^2)

The two are the same expression. doppler's th is exactly 2*theta, and substituting it through turns one into the other identically — not approximately, and not only for small bandwidths. Confirmed to machine precision across bn from 0.001 to 0.2.

This matters for a practical reason: it means the implementation can be checked against an independently written expression rather than against a transcription of itself. A test that re-types 8*zeta*th/(4 + 4*zeta*th + th*th) beside the implementation's own 8*zeta*th/(4 + 4*zeta*th + th*th) proves only that the file was copied correctly. Asserting the Rice parameterisation instead is a real check, because a sign or factor error in one form does not reproduce in the other.


3. The promise holds only in the loop's own units

bn is the noise bandwidth of the closed loop, and the derivation above assumes the rest of the loop has unit gain: the textbook condition Kd * K0 = 1. The filter never sees the discriminator or the oscillator, so that condition is the caller's to deliver.

The contract is stated once, on dp_loop_filter_create() in loop_filter_core.h (and on dp_state_filter_create_why() for the third-order filter), and it reaches the Python class docstring and the C reference from there: what the caller delivers (a unit-slope detector in the unit the control is applied in, a unit-gain actuator once per update, the linear region, no extra delay), and what a gain K other than 1 does to the bandwidth. This page does not repeat it. A gain K scales wn and zeta each by the square root of K, so the bandwidth is (4*K*zeta^2 + 1) / (4*zeta^2 + 1) times bn: 5/3 at K = 2 and 3 at K = 4, not K, at zeta = 0.707. The tests that hold it are native/validation/loop_filter_noise_bw.c (the promise), src/doppler/track/tests/test_loop_filter_contract.py (the gain formula, and the contract's sentences on every face) and src/doppler/track/tests/test_loop_detector_contract.py (the callers' side).

It is the single most consequential thing about this object. A discriminator whose slope is 2 delivers a loop 5/3 times wider than the bn its constructor was handed, and nothing anywhere reports the discrepancy: the loop still tracks, just with the wrong bandwidth, the wrong settling time and the wrong noise.

This is why doppler's discriminators normalise by their own contribution, and it is worth seeing that the rule was arrived at independently three times before it was recognised as one rule:

  • carrier_nda_disc() divides out its own |z|^M, so its slope does not depend on the amplitude reaching it;
  • ratesync scales by dp_symsync_ted_slope() — the TED's only normalisation is its own slope, which is MPSK Receiver §6.1;
  • the AGC exists in front of both so the amplitude a discriminator sees is one.

Read together, those are not three tuning decisions. They are three instances of making Kd * K0 = 1 true so that bn means what it says.

The corollary is the failure mode to look for first when a loop is wider or narrower than it was configured to be: suspect the discriminator's slope before suspecting these six lines of arithmetic.


4. The embedding contract

The state struct is public, and that is a design decision rather than an oversight. A tracker holds one by value — often two — and a heap allocation per loop inside an object that already owns its own allocation buys nothing and costs an indirection in the hot path. dp_loop_filter_create() exists for the Python binding, and is calloc plus dp_loop_filter_init().

The contract that follows from embedding is small and sharp:

dp_loop_filter_init() does not touch integ. That is what makes it double as a retune (§5) — but it also means an embedder is responsible for the integrator's initial value, and a dp_loop_filter_state_t on the stack starts with whatever was there.

Every embedder in the tree honours this, and — audited rather than assumed — they do it in three different ways:

how who
dp_loop_filter_reset() after init dll, ratesync, mpsk_receiver, burst_despreader (code loop)
assign a seeded value outright costas, carrier_mpsk, burst_despreader (carrier loop)
memset the whole enclosing struct before init symsync

The second row is the interesting one, and the reason init must not zero: costas and carrier_mpsk seed the integrator to init_norm_freq * 2*pi * tsamps, because the integrator is the frequency estimate (§1) and a caller who already knows roughly where the carrier is should not make the loop rediscover it. Zeroing on init would throw that away.

dll_core.c is the one that documents the hazard in place, having evidently met it — its dp_loop_filter_reset() carries the comment that an embedded state "would otherwise start with a garbage code rate".

So the contract is real, currently honoured everywhere, and unpinned by any test — which makes it exactly the kind of thing that holds until the eighth embedder arrives. The object could remove the hazard by zeroing in init and giving the retune its own entry point, but that would break both the seeding pattern above and the retune-preserves-lock property ratesync depends on. The split is deliberate; the burden is real; the answer is to pin it.


5. Two ways to change a running loop, and they are not the same

  • dp_loop_filter_configure(bn, zeta, t) recomputes the gains and leaves the integrator alone. This is the acquisition-to-tracking transition: run wide to pull in, then narrow to reduce noise, without losing the frequency estimate you just spent the acquisition earning. ratesync retunes exactly this way.
  • dp_loop_filter_reset() zeroes the integrator and leaves the gains alone. This is dropping lock: the estimate is now believed to be wrong, the bandwidth is still right, start again.

They are orthogonal on purpose, and every consumer uses both. Calling the wrong one is a real bug with a quiet signature — a reset where a configure was meant throws away a good frequency estimate and looks like a loop that will not hold lock.


6. The boundaries the header declares

dp_loop_filter_init()'s documentation constrains two of its three parameters: bn >= 0 and t > 0. zeta is described as "typically 0.707" without a stated range.

They are one predicate, dp_loop_filter_params_ok(), which dp_loop_filter_create() and dp_loop_filter_configure() call and dp_loop_filter_init() deliberately does not (gh-740, doppler#2103). That split is the design, so it is worth stating why rather than leaving it to look like an omission:

  • create() is the untrusted boundary. LoopFilter(bn, zeta, t) hands a Python caller's arbitrary doubles straight to it. Before the guard, t = 0 produced kp = ki = 0 — a dead loop indistinguishable from the legitimate frozen bn = 0 below — and t = inf, or a NaN in any argument, produced NaN gains, which poison every subsequent update permanently. Both were one line away in Python. It now returns NULL for bn < 0, zeta <= 0, t <= 0 or any non-finite argument, and the binding raises ValueError with the component's own message. configure() is the same boundary for a retune — LoopFilter.configure(...) hands the same arbitrary doubles to it — so it returns DP_ERR_INVALID on the same domain and leaves the loop as it was.
  • init() is the by-value path, and its callers check first. An embedder that takes these numbers from a caller calls dp_loop_filter_params_ok() before init() (the header lists which); the only runtime-computed t in the tree is mpsk_receiver's 1.0/upd, safe because m_out >= 2 is checked in its own constructor. Guarding init() again would be error handling for a case its callers have already excluded.

Validating in create() also makes the arithmetic total. With bn >= 0 and zeta > 0 the intermediate th is non-negative, so den = 4 + 4*zeta*th + th^2 >= 4 — which closes the one genuinely pathological corner: for zeta >= 1 a sufficiently negative bn drives den exactly through zero and both gains to infinity.

bn = 0 remains inside the domain and is accepted: it means a frozen loop, and that is how a loop is held open.

t is an update period in samples, not a rate, and bn is normalised to cycles per sample of the update clock — so a loop updating once per symbol at 8 samples/symbol and a loop updating every sample do not mean the same thing by bn = 0.01. This is the units seam that MPSK Receiver §7 exists to pin down, and where mpsk_receiver passes 1.0/upd rather than 1.0.


7. State

The filter is a pointer-free POD, so its serialized state is a whole-struct snapshot (DP_DEFINE_POD_STATE) rather than a hand-packed field list. The practical consequence is that the blob carries the configuration as well as the memory — bn, zeta, t, kp and ki travel with integ.

For the documented use — restore into an identically-built instance — that is exactly right and costs nothing. What it means when the instance is not identically built is section 8's last question.


8. What the characterization set out to measure

Written before the characterization existed, so that the sweep would answer these rather than confirm them. Each now has an answer in the validation report:

  1. Is bn the loop's noise bandwidth? Yes, measured (report §2.2–§2.4, findings bn_loop_noise_bandwidth_claim, bandwidth_error_is_law and t_drops_out_of_error). The delivered bandwidth is always slightly wide, by a closed-form 16·zeta²/(4·zeta²+1)² · (bn·t), and only the product bn·t matters.
  2. ~~What happens outside the declared domain.~~ Answered, and the answer became a fix. t = 0 produced a dead loop indistinguishable from the legitimate frozen bn = 0, and t = inf or any NaN produced NaN gains that poison the object permanently — both reachable from Python in one line. create() and configure() now reject them (§6, gh-740); init() is deliberately still unguarded.
  3. dp_loop_filter_steps() against dp_loop_filter_step(). Pinned. test_loop_filter_core.c §8–§9 assert per-element equivalence, the integrator carrying across calls, and out aliasing x; the report's §2.10 repeats them through the binding.
  4. Does the retune actually preserve lock? The report's §2.7 measures the arithmetic half — configure leaves the estimate bit-identical. Whether a mid-track retune is transient-free in the tracking sense is a closed-loop claim this object's report does not make.
  5. Restore into a differently-configured instance — §7. Measured (report §2.9, finding restore_carries_config): the restore carries the source's configuration and retunes the target.

9. What it deliberately is not

  • It is not a smoother, and an EMA is not a substitute. The distinction is load-bearing and conflating the two costs a transient; that is The Exponential Moving Average §7, written as the diagnosis of a measured defect in the AGC's decimated loop.
  • There is no anti-windup. The integrator accumulates without bound. A loop driven by a discriminator that is saturated or meaningless will wind up, and recovering takes as long as the winding did. Every consumer that needs bounded behaviour must bound its own discriminator or its own control.
  • There is no output limit, and adding one is not free: a bound on the control can stop the oscillator, and a stopped oscillator in a strobe-driven loop never receives the update that would restart it. That is The NCO's cycle-slip argument, and it is why nco_steer_scale exists without a production caller.
  • It does not know its own update rate. t is a number it was handed. A loop whose update clock changes — a handover from a fixed-rate acquisition tap to a symbol-rate decision-directed one — must re-init, and forgetting to is MPSK Receiver §10's open item.

Part II — the state filter

Sections 1–9 describe the second-order object. Part II describes its third-order sibling, StateFilter: the use case that shaped it, its form, the exact discrete-time derivation its gains come from, the domain it is stable on, what embedding it costs, and what the sweep measured. The contract is native/inc/doppler/state_filter/state_filter_core.h and the evidence is src/doppler/track/tests/validation/state_filter/results.md.

10. Use cases

  1. A narrow loop that must also follow a frequency ramp. A carrier loop that updates once per code period (250 to 318 microseconds) on a signal whose carrier drifts at 400 Hz/s, run at a signal-to-noise ratio near 4 dB per symbol. The loop needs a narrow noise bandwidth (bn*t about 0.01) to ride out the noise and no steady phase error on a frequency ramp. The second-order filter cannot do both: its steady phase error under a ramp of r cycles per update per update is r/ki (§14), and ki falls as the square of the bandwidth. At bn*t = 0.01 the lag is tens of degrees at the ramp rates a satellite-class Doppler produces, so the loop either loses the ramp or, widened to hold it, slips on noise. The caller that needs this is the asynchronous DSSS receiver's pre-despread carrier loop; adopting the filter there is its own work, after this object is certified.
  2. A rate-aided oscillator. Any loop whose controlled quantity has a steady slope (a Doppler rate, a clock drift rate) and that would otherwise carry the lag of use case 1.
  3. Everything that is second order today stays second order. The seven embedders of §1 are not asked to change, and §13 says why that is the constraint that shapes the struct.

11. The form

Structure. The filter adds one accumulator, in cascade with the integrator. With e the error and c the control:

rate  += kr * e              the rate estimate
integ += rate + ki * e       the frequency estimate (as today, plus rate)
c      = integ + kp * e

so F(z) = kp + ki/(1-z^-1) + kr/(1-z^-1)^2. integ keeps its meaning (§1, the running frequency estimate); rate is its slope, in the caller's control units per update. A caller who knows a Doppler rate may seed it (§13).

The loop it sits in is the one the existing harness assumes (§2, and native/validation/loop_filter_noise_bw.c): a unit detector, the filter, and an oscillator that accumulates the control, plus a transport delay of d updates in the error path (d = 0 is the canonical loop and the only one the second-order header's bandwidth figure describes). With u = z^-1 the characteristic polynomial is

(1-u)^3 + u^(1+d) * [ kp*(1-u)^2 + ki*(1-u) + kr ] = 0

and H = L/(1+L) with L = F(z) * u^(1+d) / (1-u). At d = 0 the substitution w = z - 1 writes it as w^3 + kp*w^2 + ki*z*w + kr*z^2, so the three gains are linear in the three coefficients of any desired discrete pole polynomial: placing the roots is a linear solve, not a fit.

The shape, and why the caller gives only bn. Order 3 has no damping argument: the shape of the loop is fixed by the design and the caller gives bn and t. The shape is the analog prototype s^3 + b*w0*s^2 + a*w0^2*s + w0^3 with a = b = 2, the third-order Butterworth polynomial (s + w0)(s^2 + w0*s + w0^2): one real pole and a pair at the same radius, 60 degrees off the negative real axis. The noise bandwidth of the prototype is Bn = w0 * (a*b^2 + a^2 - b) / (4*(a*b - 1)), which is (5/6) * w0 for this shape. The two constants live in one place in the header, so another shape is a change of two numbers and a rerun of the validator. §12 compares this shape with two others on the one property the automatic case depends on.

11.1 The exact discrete derivation

Written out so it can be checked, and held against the Parseval sum by the C test and the validator (agreement to about 1e-9). It does not use the analog relation between wn and Bn.

  1. The loop. The detector reads the error w[n] - phi[n] d updates late (e[n] = w[n-d] - phi[n-d]), the filter of §11, and the oscillator phi[n+1] = phi[n] + c[n].

  2. The transfer function. With u = z^-1, L = F(z) u^(1+d) / (1-u) and H = L / (1 + L). At d = 0, with `N(z) = kp (z-1)^2 + ki z (z-1)

    • kr z^2for order 3 (N = kp (z-1) + ki zfor order 2),H = N / DwithD = (z-1)^3 + N(D = (z-1)^2 + N`).
  3. The noise bandwidth is Parseval on the impulse response. Bn = (1/2) * sum_n h[n]^2, cycles per update, exactly (the harness computes this sum by running the real step). Write the loop as a linear system x[n+1] = A x[n] + b w[n], y = c x + d w whose state is what the simulation carries: the oscillator phase, the frequency estimate, the rate estimate and the detector's delay line. Then sum h^2 = d^2 + c P c^T where P solves the discrete Lyapunov equation P = A P A^T + b b^T. That is a finite linear solve, so the answer is algebraic in the gains, not a series. Written this way a slow loop is a matrix close to the identity, every entry a small combination of the gains and of 1; the polynomial form D(z) above holds the same loop as large coefficients that nearly cancel, and loses the digits the small gains live in (a companion-form solve read 0.0008 for a loop of bandwidth 0.001).

    Which phase. The bandwidth is that of the oscillator phase at the detector instant, phi[n]. A phase read after the kp*e step of the same update is a different signal: the Costas lane, running this same loop, measured the sum of squares of that later phase 1% to 7% under 2*Bn, so a figure compared with Bn must say where the phase is read.

  4. Stability is the decay of one sum. The pair (A, b) is controllable, so A is stable exactly when P = sum_k A^k b b^T (A^T)^k converges, and that sum is the solution of the Lyapunov equation of the previous item. One computation gives both the bandwidth and the verdict.

    Conditioning, and where the verdict is trusted. The gains of a slow loop span many decades (kr is about 1e-9 where kp is 4e-3 at bn*t = 1e-3), and a Cholesky pivot of P in the raw coordinates can flip negative on a loop that is stable with a margin of 1e-4. That is what happened to gains off the design manifold, the ones a converging Kalman filter holds (Part III): the verdict was erratic, a false "not stable" at isolated updates of a stable trajectory. Balancing the coordinates alone left 2 disagreements in 1404 judged cases, and a solve in extended precision alone left 5; and extended precision is not on every platform (long double is double on MSVC and on Apple's arm64). So the function no longer solves for P and tests it for positivity. It sums P = sum_k A^k b b^T (A^T)^k by doubling, P <- P + A P A^T with A <- A A, in balanced coordinates (a diagonal similarity by powers of two, which changes only the conditioning), all in double: every term of the sum is positive semidefinite (single entries may be negative), so the sum cannot lose definiteness by cancellation at any scale the gains span, and the loop is stable exactly when A^(2^j) goes to zero (the largest entry of the balanced power under 1e-12 is the stable verdict; non-finite or above 1e150 is not stable; 64 passes without either is not stable), which a pole at radius 1 - delta does in about log2 (40/delta) passes (36 at delta 1e-9). An unstable loop overflows or stalls at order one, and a marginal one (a gain at zero, a pole at z = 1) never goes to zero, which is the "not controllable reads as not stable" rule falling out of the same test. What the tests run: the exact bandwidth at delay 0 and loop gain 1 against the bandwidth asked for from bn*t 1e-6 to STATE_FILTER_BNT_MAX (1203 cells, within 1e-9; not claimed below 1e-6, which is above STATE_FILTER_BNT_MIN); the verdict and the bandwidth against a simulation of the real step at bn*t 0.03 for delays 0, 0.5, 1, 1.25, 2 and 3 and loop gains 1, 0.7 and 1.6; and a simulation of the loop's own state recursion over the Kalman recursion's gains at bn*t from 1e-3 to 0.08, starts of 1 to 5 times, at the four corners K in {0.5, 2} by delay in {0, 2}: 1404 cases judged, no disagreement, the same on every platform because there is one code path. The sweep over every bn*t from the floor to the bound, delays 0 to 4 and loop gains 0.5 to 2 is not run. Two limits are stated, not hidden. A loop within about 1e-12 of the unit circle is within rounding of the edge, and either answer is within that rounding. A gain at or below zero reads as not stable by rule, which is the correct frozen verdict and is why a Kalman gain that crosses zero in a transient is reported as outside the rectangle there. The gains themselves (create, the blob check) come from the closed-form bisection and do not pass through this function, so a blob written on one platform is accepted on another to the last bit of the gains.

  5. Order 2, solved. The Lyapunov equation gives Bn = (2 kp^2 + (2 + kp) ki) / (2 kp (4 - 2 kp - ki)) and the loop is stable exactly when kp > 0, ki > 0 and 2 kp + ki < 4 (Jury; the denominator is the last condition).

  6. Order 3, solved. With d1 = kp + ki + kr - 3, d2 = 3 - 2 kp - ki, d3 = kp - 1, the loop is stable exactly when kr > 0, 4 kp + 2 ki + kr < 8, |d3| < 1 and |d3^2 - 1| > |d3 d1 - d2|, and

    Bn = ( 2 ki^2 kp + 4 ki^2 + 4 ki kp^2 + 3 ki kp kr + 4 ki kr
           + 4 kp^2 kr + kp kr^2 - 4 kp kr + kr^2 )
         / ( 2 (ki kp + kp kr - kr) (8 - 2 ki - 4 kp - kr) )
    
  7. The gains. The design fixes a shape, the two constants a and b; the gains are kp = b*th, ki = a*th^2, kr = th^3, the analog coefficients at th = w0*t. The scale th is then solved so that the exact Bn above equals bn*t: one monotone equation in one unknown, started from th = 1.2 * bn*t (the prototype's w0 = bn / (5/6)). The gains come from the closed-form order-3 bandwidth (sf_bn3, the delay-free expression of step 3) by bisection on th; the general exact function of §12, with its delay and gain arguments, is the independent check on that expression and is not what the gains are solved from. The delivered bandwidth is bn by construction, at d = 0, and the discretization only moves the shape. A matched-pole family (z = exp(s*t) on the analog roots) is the alternative way to fix the shape; §15 lists the choice.

  8. A delay. An integer d replaces u by u^(1+d) in L: the companion form grows to 3 + d states and step 3 is unchanged. A fractional d = k + f replaces u^(1+d) by u^(1+k) * ((1-f) + f*u), linear interpolation of the detector's error between the two nearest updates; step 3 is unchanged on the larger polynomial, and the answer is exact for that model (§12), and for a real delay at integer d.

  9. The check. Steps 1 to 4 applied to order 2 give the closed form above, the expression #3121's exact second-order design is built on.

What this means for order 2. The shipped gains are the bilinear map of the analog relation, and the closed form of step 4 evaluates their exact delivered bandwidth, which becomes the stated figure in place of the fitted closed form in the header: at zeta 0.707 the shipped loop is wide by 0.9% at bn*t = 0.01 and 3.6% at 0.04. The default does not change, and nothing in the second-order struct, blob or any embedder moves with this work. #3121 asks for a second, exact design for order 2 as an option for callers past the bn*t budget; the exact bandwidth function of §12 is what it is built on, and its interface is that issue's.

11.2 Cross-check against the legacy discrete-time design

3121 carries a legacy design: a cubic in kp with ki = kp^2 / (4 zeta^2),

reported not exact when measured (-0.018% at bn 0.01, -0.44% at 0.05, -6.2% at 0.2). Its filter differs from this object's. Written as c[n] = c[n-1] + kp (e[n] - e[n-1]) + ki e[n-1] it is F = kp + ki u / (1 - u), one update more delay on the integral path than F = kp + ki / (1 - u). The steps of §11.1 applied to each topology, with g = 1 / (4 zeta^2) and B = bn*t:

topology H = N / D, D = (z-1)^2 + N exact Bn
this object N = kp (z-1) + ki z (2 kp^2 + (2 + kp) ki) / (2 kp (4 - 2 kp - ki))
legacy (issue's recipe) N = kp (z-1) + ki (ki^2 - 3 ki kp + 2 ki + 2 kp^2) / (2 (kp - ki) (4 - 2 kp + ki))
  • The issue's measurement is the exact Bn of the legacy topology. The closed form reproduces its -0.0178%, -0.4403% and -6.2039% at bn 0.01, 0.05 and 0.2 to the digits printed, so the residual is not a measurement artifact and not a model mismatch.
  • The legacy cubic is the exact solution of its own topology with one coefficient wrong. Setting Bn = B with ki = g kp^2 in the second row gives (1 + 2B) kp^3 - 12 zeta^2 (1 + 2B) kp^2 + (4 zeta^2 (8B + 2) + 16 zeta^4 (4B + 2)) kp - 128 B zeta^4 = 0. The legacy recipe has the same kp and constant coefficients and a different kp^2 coefficient, a = -4 zeta^2 (2B + 3) / (2B + 1) where the exact one is a = -12 zeta^2. With that one coefficient replaced, the root measures zero error by Parseval to rounding (below 1e-11 percent at bn from 0.001 to 0.2). The residual is therefore one coefficient of the formula, not a different loop.
  • This object's topology has an exact design under the same damping definition, and it is a quadratic, not a cubic. Setting Bn = B with ki = g kp^2 in the first row gives g (1 + 2B) kp^2 + (2 + 2g + 4B) kp - 8B = 0, solved by the positive root. Measured by the issue's reproducer (Parseval on LoopFilter's recurrence), its error is zero to rounding at bn from 0.001 to 0.2 (below 1e-10 percent). At zeta 0.707 and bn 0.05 it gives kp = 0.12241, against 0.12455 for the legacy cubic as issued, 0.12507 for its corrected root and 0.12473 for the shipped bilinear gains.

12. The domain, the stability bound, and the gain a loop may have

One predicate. The third-order create and configure refuse outside a domain defined once, as dp_loop_filter_params_ok does for order 2 (bn >= 0, t > 0, finite, finite gains), plus a bound on bn*t. The bound is not a tuning figure. It is derived from a stated requirement: the loop at its nominal gain is stable, with its poles inside the unit circle, and stays stable for every loop gain K (the discriminator slope times the oscillator gain; §3) in a stated range, for a stated delay budget.

A third-order loop is conditionally stable in K. Scaling the loop gain scales all three coefficients, and the Routh condition on the analog prototype becomes K > 1/(a*b): 0.25 of nominal is the lower edge for every bandwidth, and nothing in the analog loop bounds K above. In the sampled loop the delay bounds it above, roughly in proportion to 1/(bn*t*(1+d)), and a delay also nudges the lower edge up. A second-order loop has no lower edge at all, so an order-2 embedder never had to ask.

The range to design for. K_min is the detector's slope at the lowest per-update signal-to-noise ratio the caller specifies. The owner of the caller sets that ratio; the slope at it comes from the detector's own model, which is the embedder's, not this object's. A detector's slope falls below 1 as the ratio falls, so K presents on the low side, which is the conditional side of a third-order loop. One caller measures 0.58 at its floor and 0.72 to 0.76 in the mode it will use. The rectangle K from 0.5 to 2, d from 0 to 2 is the claim, with that reason: K_MIN = 0.5 is the floor the automatic case covers. The measured lower edge at the bound is 0.236 of nominal at a delay of zero and 0.310 at two updates, 4.1 dB under that floor at the worst delay and 5.4 dB under the 0.58 one caller measures.

The shape is judged first by its downward margin at d_max, and only then by its transient. Arithmetic from the exact H(z) of §11.1 (gains solved to the exact bn*t) gives the lower edge K_low of three shapes at d of 0, 1 and 2, and the price each pays in steady acceleration error (the gain kr / (bn*t)^3, larger is better). The first row is a less damped shape whose constants are chosen for the comparison; the other two are the Butterworth polynomial of the design and the triple real pole (s + w0)^3:

shape (a, b) Bn/w0 K_low at bn*t 0.01 at 0.04 at 0.08 kr/(bn*t)^3
less damped (1.5, 2), chosen 0.7812 0.331, 0.334, 0.337 .323 .335 .348 .314 .337 .363 2.00
Butterworth (2, 2), the design 0.8333 0.249, 0.252, 0.255 .244 .256 .268 .240 .262 .288 1.65
triple real pole (3, 3) 1.0312 0.111, 0.112, 0.113 .110 .114 .118 .109 .117 .126 0.86

Read against a detector that reaches 0.58: the less damped shape has about 4.6 dB of downward margin at best; the Butterworth shape has about 7 dB at zero delay and 5.4 dB at the worst delay at the bound, and costs 18% of the acceleration gain against the less damped shape (the steady error under a given acceleration is 21% larger); the triple pole gives 14 dB and costs more than half of it. That cost is what "stable in the automatic case" buys in noise-bandwidth efficiency. The Butterworth shape is the design.

At the bound itself (bn*t = 0.12, Butterworth), the stable gain interval [K_low, K_high] is [0.236, 7.8] at d = 0, [0.268, 3.6] at 1 and [0.310, 2.1] at 2 (and [0.251, 7.3] at 0.5, [0.288, 2.9] at 1.5 in the interpolation model). The margin that is left at the bound is 0.58 / 0.310, 5.4 dB downward, at the worst delay, and 2.1 upward: the bound is set by the upward side, and the downward side has room.

What the object can and cannot detect. It can check, from its own gains, that the nominal loop and the declared K range are stable at the declared delay budget (a predicate on bn*t). It cannot see K or the caller's delay: a detector of slope 0.3 delivers an unstable loop with no error anywhere. The page's section 3 promise (unit gain) is therefore stronger for order 3: for order 2 a wrong K changes the bandwidth, for order 3 below an edge it breaks the loop.

One function, one home. The exact bandwidth and stability function takes the gains and the order of the loop it describes (2 or 3), so it serves order 2 as well. It lives with the state filter: a new component, so the certified loop filter's code does not change in this work, and the loop filter's header points to it. A second home would be a second copy of the Lyapunov solve.

The delay is not told to the object. Two options: tell it (a delay argument, gains and predicate accounting for it), or have the page tell the embedder to budget it. The object is not told. A told delay makes bn*t mean something different per caller, and the caller's delay is rarely an integer (a mean-over-window detector contributes a fraction of an update, and its window also narrows the loop). Instead the object owns the exact expression: a public function that, for a given (bn, t, order), a delay in updates (exact at an integer, and the interpolation model of §11.1 between integers) and a gain K, returns the delivered noise bandwidth and whether the loop is stable. It is the tool a caller sizes from, and the validator's sweep over d and K runs through the same function, so the figures the page quotes come from the shipped code. This applies to order 2 as well: the header's delay-free figure is d = 0; a caller with one update of delay is wider than the header says, which is the leading hypothesis for a measured shortfall in loop SNR at the DSSS caller, and the page owes both orders as a function of d in 0, 1, 2.

13. What is preserved, and the embedding cost

The sibling form changes no byte of the second-order state, step or benchmark, and the second-order gains stay as they are. #3121 asks for an exact second-order design as an option; that is a change to LoopFilter of its own, and a re-derivation of the shipped gains would move every embedder's numbers and every blob.

The cost of changing the shared struct. The second-order state is public and embedded by value (§4). Adding kr, rate and an order to it changes its size, and every embedder that snapshots it whole moves:

embedder how it packs the filter blob that moves
the filter itself whole struct LPFL v1
costas whole-struct snapshot COSTAS v3
carrier_mpsk whole-struct snapshot CARRIER_MPSK v1
carrier_nda whole-struct snapshot CARRIER_NDA v5
symsync whole-struct snapshot SYMSYNC v5
dll whole snapshot, plus held_lf DLL v15
burst_despreader whole snapshot, two filters BURST_DESPREADER v3
ratesync field-wise, nests the filter's blob loop v2, state v2 (via LPFL)
mpsk_receiver loops field-wise, nests the filter's blob loops v7, receiver v7 and its real variant

and every composition that nests those (the despreaders and the receivers that compose them, through despreader, dsss_receiver, async_dsss_receiver) changes size with them. The honest answer to "does every composed blob in the library move" is yes, if the struct grows, and the step would also gain a branch on the order in the hot path of every tracking loop (JM_FORCEINLINE JM_HOT), which a benchmark row has to prove costs nothing and could not be guaranteed to.

The alternative: a sibling object, StateFilter. The second-order struct, its step, its blob magic (LPFL) and every embedder stay as they are. The third-order filter is its own public struct (kp, ki, kr, integ, rate, bn, t), its own step (the three lines of §11, JM_FORCEINLINE JM_HOT, no order test), its own state triplet with its own magic, its own create, configure, reset and predicate. An embedder adopts it by holding that struct in place of, or beside, the second-order one, and its blob moves then and only then: each adoption is a version bump of one object, in the work that adopts it, with the benchmark's order-2 rows unmoved by construction. This also keeps the "certify the object, then the composition" order.

Order is a choice of type, not a mode. There is no create-time order argument, no reject key, and no configure across orders, because there is nothing for an order to switch. Within order 3, configure(bn, t) retunes the gains and leaves integ and rate, as order 2 does (§5); reset zeroes both accumulators and leaves the gains; the blob carries gains, bn, t, integ and rate, and set-state accepts only a filter a live one could be (the same rule as dp_loop_filter_state_ok). integ and rate are public fields: a caller seeds integ (a known frequency) and rate (a known rate) exactly as the second-order embedders seed integ today, and a writable Python property for either is a mutator the #2022 gate probes, so both are in the blob. The header states the unit of rate as it states integ's: integ is the control per update, rate is its change per update, so a Doppler rate of R Hz/s at an update period T seconds is rate = R * T^2 in cycles per update per update, when the control is in cycles per update.

An embedder that holds both orders. Acquiring on order 2 and tracking on order 3 is the obvious use, and at the switch the embedder carries integ (the frequency estimate the acquisition earned, as configure does in §5), zeroes rate, and seeds it only if it has an independent estimate. Zeroing is the default because a rate learned by a wide second-order loop is not available to carry. Whether pull-in (§15, unknown 3) needs a seeded rate is for the measurement to say.

The name. The sibling is StateFilter: a filter over an explicit state vector (the frequency estimate and its rate), not "LoopFilter3". The house pattern is the loop filter's own (component loop_filter, header loop_filter/loop_filter_core.h, C names dp_loop_filter_*, class LoopFilter in the track module), so the component is state_filter, with C names under the dp_state_filter_ prefix and the class StateFilter in the same module. Nothing in the tree is named StateFilter, state_filter or kalman, in any case or spelling, so there is nothing to collide with or reuse. The second-order blob stays byte-identical, and the question of an order= argument on LoopFilter is closed: there is none.

Reuse check. Nothing in the tree is a second integrator. The bn_fll assist in costas and carrier_mpsk is a first-order frequency-error term fed into the same integrator; the dll aid adds an external rate to a nominal code rate; the burst capture's rate hypotheses are a search, not a tracker. The third-order filter is new.

13.1 One recurrence, two flavors

A Kalman flavor of the same object is planned and is not built. The fixed-gain object is shaped so that adding it is a view and some fields, not a reshaping.

The recurrence. The filter estimates the state x = (integ, rate) of the quantity being tracked, with the oscillator's accumulated phase correction as the third state of the loop. Each update predicts, then corrects with the error e through a gain vector g = (kp, ki, kr):

predict   rate' = rate ;  integ' = integ + rate
correct   rate  = rate' + kr * e ;  integ = integ' + ki * e + kr * e
control   c     = integ + kp * e

(the three lines of §11 are this recurrence with the prediction folded in). The fixed-gain flavor holds g constant, solved from bn (§11.1). A Kalman flavor computes g each update from a covariance recursion given a process-noise and a measurement-noise level. For a constant-acceleration model the recursion converges to a constant g, the steady-state Kalman gain of an alpha-beta-gamma tracker, which depends only on the ratio of the two noise levels. So the fixed-gain loop is the steady-state case of the Kalman recurrence at some noise ratio, and that ratio is what bn selects. That correspondence is proved in the continuous limit and measured in discrete time in §19: the two flavors meet exactly as bn*t goes to zero and differ by a stated amount at the bounds.

What the two share: the state (integ, rate), the step's signature (e in, c out), the blob envelope and its reset, the caller's units (§13), the seeding of integ and rate, and the exact bandwidth and stability function of §12 evaluated at the CURRENT gains, which is what lets a caller ask what a Kalman filter's gains deliver at any moment. What the Kalman flavor adds: the covariance matrix as state, its constructor's arguments (the two noise levels and an initial covariance), and the per-update gain refresh. Nothing for it is added now: no covariance field, no argument, no code.

The hot step does not pay for the flavor. The fixed-gain step stays the three lines of §11, inline, with no flavor test: an embedder compiles that and nothing else. A Kalman flavor does not change that step. It refreshes the gain fields from its covariance recursion in its own function, called before the same inline step, so the step reads the gains it always reads. A view shares methods verbatim, so the binding's step cannot be both; the binding path may call an out-of-line step that tests the flavor, which costs a branch on the Python path only (a call that already costs a Python dispatch) and leaves every C embedder's inline step and its benchmark rows untouched. Whether jm lets a view's method call a differently named C function is a question for phase 2 to answer against the manifest, not for this page to assume; if it does not, the Kalman flavor is a separate type (a difference in method signature is a separate type, and a gain refresh that takes the noise levels per update is one).

The blob carries a flavor key from version 1. What a state filter's blob describes depends on its flavor (a covariance has its own payload), which is the case the state-serialization page calls a reject key: set-state into a filter of one flavor refuses a blob of another, never reinterprets it. So version 1 carries a flavor word in its extra header, 0 for fixed-gain, and set-state refuses any other value. A Kalman flavor later adds flavor = 1 with its own payload under the same version, because it changes no byte of flavor 0; without the key the first Kalman blob would need a version bump to be told apart. The key is written, not stored in the struct: the type implies it until a second flavor exists.

14. Closed forms a caller sizes from

Owned by the object, as dp_loop_filter_wn is for order 2, so nobody re-derives them. All are exact for the discrete loop at d = 0, from the final-value theorem on 1/(1 + L): the steady phase error to an input of polynomial order m.

input order 2 order 3
phase step, frequency step 0 0
frequency ramp r (cycles/update/update) r / ki 0
frequency acceleration a (per update^3) a*n / ki a / kr

Under an acceleration a the second-order phase error is a ramp, growing by a / ki per update, so a caller sizes a dwell from the time it takes that ramp to reach the error it can tolerate. r / ki is the exact discrete form of 2*pi*R / wn^2; the two differ in the first order of wn*t, and the exact one takes the gains the object holds. The function takes the state and the input's order, so a caller does not choose between the analog and the discrete form. In the units of use case 1: a ramp of R Hz/s at an update period of T s is r = R * T^2 cycles per update per update.

Settling time. dp_loop_filter_settle_time(bn, zeta, eps) is the last time the error of a unit phase step is larger than eps, from the second-order loop's closed-form step response (under-damped, critical and over-damped). It scales as 1 / bn:

zeta eps = 0.1 eps = 0.02 eps = 0.001
0.5 2.01 / bn 3.75 / bn 7.04 / bn
0.707 1.96 / bn 2.59 / bn 4.91 / bn
1.0 1.87 / bn 3.37 / bn 5.62 / bn
2.0 0.53 / bn 5.36 / bn 17.24 / bn

test_settle_time (test_loop_filter_core.c) holds it against the filter closed around a unit-gain integrator, to 1% and two updates over seven dampings. DP_LOOP_FILTER_SETTLE_EPS, 0.02, is the residual the library's objects report their settle_time at: RateSync for its timing loop, and MpskReceiver, AsyncDsssReceiver and DsssReceiver for the timing and carrier loops added. It is the linear loop's figure: a detector slope of K scales the decay rate by K (§3), and a frequency offset's transient is not in it.

15. The unknowns, and what the sweep measured

Written before the sweep, so that it answered them rather than confirmed a decision. The sweep is native/validation/state_filter_loop.c, and the report src/doppler/track/tests/validation/state_filter/results.md measures the same through the binding.

  1. Delivered noise bandwidth against requested, as a function of bn*t and d. Zero excess at d = 0, to 1e-8 or better across bn*t 0.001 to 0.12. A detector delay widens the loop: at bn*t = 0.04 the delivered bandwidth is 1.12 times bn*t at one update and 1.26 at two, and 1.42 and 2.31 at the bound. No closed form in bn*t*d was found; dp_state_filter_loop_bandwidth is the expression.
  2. The transient to a frequency step: at the same bn the third-order loop settles in about 3.3 times the updates of the second-order loop and peaks about 9% higher (report §2.5). The price of the rate state; the ramp it nulls is the use case.
  3. Pull-in range with a real discriminator is a property of the composition and is not measured on the filter (#3123).
  4. The steady error under a frequency acceleration is a/kr against the simulated loop to 1e-4 (C test §8).
  5. Behavior at the stability bound. Past the lower gain edge the unstable mode grows by 1e-5 to 4e-3 per update at the delay-1 cells swept, a slow growth; past the upper edge it grows too fast to measure over the window.
  6. Behavior at the lower gain edge, under noise, with a detector whose slope compresses with signal-to-noise ratio is the composition's (#3123).
  7. Delay as a range. The edges are not monotone in the interpolation model of §12, so the rectangle is verified on a grid; a pure fractional delay is not modeled (#3123).
  8. A detector that averages over its window is the embedder's model; the object certifies the canonical loop and gives the embedder the expression for the rest.
  9. The gain family. The gains are the analog coefficients at the solved scale; matched poles are the other way to fix the shape and are not compared (#3123).

Part III — the Kalman flavor

Part II is a fixed-gain third-order loop. This part describes its second flavor, KalmanStateFilter: the same loop, with the gains computed each update from a covariance recursion instead of held constant. What it measured is in its validation report (src/doppler/track/tests/validation/state_filter_kalman/results.md); what that report does not cover is #3136.

17. Use cases

  1. Acquire fast, then track narrow. A fixed-gain loop has one bandwidth: wide enough to pull in or narrow enough to ride out noise. The Kalman gain is high while the state is uncertain and falls as the filter learns, to the steady-state gain of the noise it is given. A loop that starts with a frequency error of a few bin widths and must settle to a narrow bandwidth gets both from one object.
  2. A loop sized from the signal, not from a bandwidth. The fixed-gain flavor is sized from bn, a design number. A caller who knows the detector's noise and how fast the carrier's rate can change gives those two figures and gets the bandwidth that is optimal for them (§18).
  3. The fixed-gain case stays. The fixed-gain flavor's step, struct and blob do not move (§21); a caller who wants a constant loop keeps it.

18. The model, and what the caller gives

The model. The tracked quantity has a phase, a frequency and a rate: s = (theta, f, a), advancing as theta' = theta + f, f' = f + a and a' = a + w, where w is white with variance q per update (a rate that random-walks: the dynamics figure). The detector measures the phase error e = theta - phi with white noise of variance r per update (the measurement figure), phi being the oscillator's phase. The loop filter of §11 is the observer form of this model. With the predicted state x = (phi, f_bar, a_bar) it is

x' = F x + K e,      F = [[1,1,0],[0,1,1],[0,0,1]],
                     K = (kp + ki + kr,  ki + 2*kr,  kr)

(checked: F - K*H with H = (1,0,0) has the characteristic polynomial of §11.1 for every (kp, ki, kr)). A Kalman filter is the same recurrence with K chosen each update:

S  = P[0][0] + r                     innovation variance
K  = F P[:,0] / S
P' = F P F^T - S K K^T + Q,           Q = diag(0, 0, q)

with P the covariance of the predicted state. The three gains the step reads are kp = K0 - K1 + K2, ki = K1 - 2*K2, kr = K2. The step itself is Part II's three lines; the Kalman flavor adds the covariance update that sets the gains before them.

What the caller gives, in the loop's units. Two numbers, both about the loop's own error signal, so nothing has to be invented as a matrix:

given meaning units
sigma_e rms of the detector error when locked the error's units, per update
sigma_a rms change of the rate per update (the dynamics figure) control units per update, per update

so r = sigma_e^2 and q = sigma_a^2. A caller who knows a C/N0 and a maximum jerk turns them into these two the way it already turns them into a detector variance. The steady-state bandwidth follows from their ratio alone: in the continuous limit Bn = (5/6) * (q/r)^(1/6) per update (§19), and exactly by the solve of §11.1 applied to the steady-state gains.

The automatic case: bn and t alone, as the fixed-gain flavor takes them. The noise ratio is solved so the steady-state loop's exact bandwidth is bn*t, and the covariance starts at its steady state. The filter is then a constant-gain loop at the Riccati steady-state gains, which are not the fixed-gain flavor's: they differ by the percentages of §19. Its stability is therefore shown for those gains and not inherited from the fixed-gain flavor's (§20 does it, and the flavor has its own constants). From the first sample it behaves as the fixed-gain loop does to within about 1% in settling time (measured below), the difference being the few percent of a gain.

A larger start, and its cap. A caller who gives a frequency uncertainty sigma_f0 larger than the steady state's sigma_f (the square root of the steady-state covariance's frequency entry) starts with larger covariance and therefore larger gains for a while. The constructor refuses a start whose gains, at ANY update of the covariance's trajectory (not only the first), leave the exact stability rectangle of §12 (K 0.5 to 2, delays 0 and 2). That rule caps the start, and the cap is the object's own property, measured by the validator from the shipped constructor (the report, src/doppler/track/tests/validation/state_filter_kalman/results.md, §2.5), not typed here: it is about 6 times sigma_f for every bn*t up to 0.04 and then falls (3.8 at 0.06, 2.4 at 0.08, 1.2 at the bound 0.12). The constructor also has a ceiling, START_MAX = 5, so the ceiling is what binds up to bn*t 0.04 and the rule binds past it: a fast loop gets the least acquisition from a start, which is the opposite of where a caller might want it. The rule is checked by sampling the trajectory (each test 1% of the elapsed updates after the last, and at least one update, so every update of the first 100 is tested), and the report's sampling table measures that choice against the dense walk: the same cap to the bisection at every bn*t of the grid, 0.4% higher at a 10% step and 5% higher at a 50% step. The exact stability test is reliable off the design manifold (§11.1), so a sample does not step over an excursion.

What it buys, for a noise-free frequency step and the same final bn*t, is in the report's §2.6: at bn*t 0.01 a start of 5 settles in 0.56 of the fixed-gain loop's updates, and a start of 4 in 0.59; at 0.04, 0.51 and 0.56. Inside the ceiling the Kalman flavor settles a frequency step about 1.8 times faster than the fixed-gain loop and peaks at about half the error: use case 1 is served by a factor under two. A caller whose start is several bin widths off (a hundred times sigma_f) is refused; the fixed-gain answer to that case is to start wide and configure narrower (§5), which keeps the estimates.

What relaxing the ceiling buys, measured and not shipped. The rule stays as designed for the first version. The report's §2.6 measures starts of 10, 30 and 100 times sigma_f (built through the embedder's unguarded init_qr, which the validated constructors do not accept, so nothing shipped accepts them and an embedder that passes one is outside the certified range): at bn*t 0.01 a start of 30 settles a frequency step in 0.27 of the fixed-gain loop's updates, against 0.56 at the ceiling, and no closed loop diverged or failed to settle across starts 1 to 100, slopes 0.6, 0.76 and 1 and delays 0 to 2 at bn*t 0.01 and 0.04. Frozen at the gains in force the loop does leave the rectangle for a few updates past the cap; the converging loop did not diverge. That is a measurement, not a guarantee, and whether to relax the ceiling is the owner's.

19. The claim of §13.1, proved and corrected

§13.1 said the fixed-gain loop is the steady state of the Kalman recurrence at some noise ratio. In the continuous limit that is exact; in discrete time it is not, and the difference grows with bn*t.

Continuous limit. The steady-state Kalman-Bucy filter of a triple integrator driven by white noise of intensity q, measured in noise of intensity r, has its poles where the symmetric root locus 1 - (q/r) / s^6 = 0 puts them: s^6 = q/r, six roots on a circle of radius w0 = (q/r)^(1/6), of which the three in the left half plane are -w0 and w0 * (-1/2 +- j*sqrt(3)/2). That is (s + w0)(s^2 + w0*s + w0^2), the Butterworth polynomial of §11, with a = b = 2. So the shape of the fixed-gain loop is the optimal-filter shape, and bn selects the noise ratio through Bn = (5/6) * w0.

Discrete time. The steady-state gains of the discrete recursion above are the solution of its Riccati equation, and they differ from the fixed-gain loop's (analog coefficients at the solved scale) at the first order in th = w0*t. Arithmetic from the Riccati solution in scratch (a number a C oracle replaces: the implementation's test produces them and this table is regenerated from it), at the noise ratio whose exact bandwidth is bn*t, as the relative difference of each gain from the fixed-gain flavor's:

bn*t kp ki kr
0.01 -0.5% -0.2% +0.7%
0.04 -2.0% -0.7% +3.0%
0.12 -5.3% -1.5% +9.3%

The same to the third digit for process noise diag(0, 0, q) and for the exact sampling of a continuous white jerk. So the two flavors meet at the limit and are separate objects in the finite loop: the fixed-gain flavor is the Butterworth loop, the Kalman flavor's steady state is the optimal one for the discrete model, and they differ by a few percent of a gain at the bandwidths the loop is used at. Two tests follow, and neither is equality: the Kalman steady state equals an independent solution of the Riccati equation (the oracle), and its difference from the fixed-gain gains falls as bn*t falls, at the first order (a ratio bounded by a stated constant over a decade).

20. Stability and bandwidth where the gains move

The exact function of §12 is a statement about a loop with gains held constant. Evaluated at the Kalman flavor's current gains it says what the loop would be if they stopped changing: its delivered bandwidth and its stability over a detector delay and a loop gain. That is the one thing it says. It does not say the time-varying loop is stable, and the page does not claim it, with two stated exceptions.

  • The constants of its own. The first flavor's rectangle was derived for the Butterworth gains and does not transfer to the Riccati ones: at the bound kr is 9% larger and kp 5% smaller. The harness derives the flavor's own from the exact function at its steady-state gains (the report, §2.2). At bn*t = 0.12 the upper gain edge at a delay of two updates is 2.18 (the first flavor: 2.08) and the lower edge is 0.274, 0.314 and 0.365 at delays 0, 1 and 2 (the first flavor: 0.236, 0.268 and 0.310). The largest bn*t stable at K = 2, d = 2 is 0.1302 (the first flavor: 0.1248), and the lower edge at the bound sits 2.7 dB under K_MIN = 0.5 at the worst delay (the first flavor: 4.1 dB), 3.3 dB under the 0.58 one caller measures. So the Kalman flavor has its own named constants, and the rectangle (bn*t 0.12, gains 0.5 to 2, delay 2) is inside both bounds; the lower margin is the smaller and is stated beside the constant.
  • A matched model at unit gain. The Kalman filter's error dynamics are exponentially stable when the model is observable and controllable, which the triple integrator with noise on its rate is, so the loop is stable throughout convergence when the noise figures describe the signal and the detector slope is 1.
  • The gains along the start are bounded. The constructor refuses a start whose gains, at any update of the covariance's trajectory, fall outside the exact stability rectangle; §18 states the cap.

What is not claimed: stability during convergence at a detector slope other than 1 or with a detector delay, where the covariance is wrong about the loop. The report measures noise-free closed loops through slopes 0.6, 0.76 and 1 and delays 0 to 2 (§2.6); that is a measurement, not a promise, and the converging loop's stability against the frozen-gain prediction is open (#3136).

21. How a flavor is built

Its own component, calling the base. The Kalman flavor is state_filter_kalman, a component of its own with its own class, KalmanStateFilter. It is not a view of state_filter: jm builds a view's step, steps and state blob from its parent's and has no way to override them (an override is refused as a duplicate member, just-makeit gh-1092, on the pinned jm 0.126.1 and on 0.130.1), and the Kalman step and blob are exactly what differ. Nothing is copied across: the Kalman struct holds the base dp_state_filter_state_t by value as its first member, and the loop's three lines, the exact stability and the exact bandwidth are the base's own functions (dp_state_filter_step, dp_state_filter_loop_stable, dp_state_filter_loop_bandwidth). The read surface the two classes share (kp, ki, kr, integ, rate, bn, t, bandwidth, stable) is shared by forwarding: each is a thin C function or a field read through the base member, so the two classes cannot drift.

The state, typed, public, and embeddable by value. The Kalman filter is its own C type, whose first member is the base, followed by the six distinct entries of the covariance P, its start P0, and the two figures q and r. It is public, as the base is, because the same embedders (the DSSS carrier loop among them) hold their filter by value: it has an init that needs no heap, and create/destroy for the heap path. Its functions (init, create, destroy, configure, reset, step, steps and the state triplet) take the Kalman pointer, so the compiler refuses a C caller who hands a Kalman filter to the base's configure or set_state; the base's functions that only read (stable, bandwidth and the fields) accept &k->base. The step is out of line: its covariance update runs once per loop update, at a rate far under the sample rate, so there is no hot path to protect.

What a caller states. The caller's figures: the rms detector error when locked sigma_e, the rms change of the rate per update sigma_a, and an optional frequency uncertainty sigma_f0 (0 = absent), all in the loop's own units; the automatic case is bn and t alone. In C these are two typed constructors (create from the figures, create_bn from a bandwidth) over the internal (q, r, start) form. In Python they are one class with optional arguments: the figures, or bn alone, and both or neither is refused with an error that names the two forms. No carrier-to-noise-density or jerk argument and no detector model is in the filter; the guide shows the conversion a caller with a C/N0 and a jerk figure makes, as an example and not an API.

The hot step. The fixed-gain step is untouched, and the fixed-gain struct, its inline step and every embedder's size do not move: the Kalman type is a different type. The Kalman step is its own function: the loop's three lines on the gains in force, then the covariance update and the gain refresh. The fixed-gain rows cannot move, since every file under native/*/state_filter/ and its generated binding is byte-identical to the fixed-gain component's; the Kalman rows are kalman_step, kalman_configure, create_start_1e2 and create_start_1e4.

Telemetry. Neither flavor has set_telemetry, and that is decided, not missed. A leaf filter has no probes of its own to publish: the loop that embeds it attaches telemetry and publishes the loop's outputs (the control value, the phase error, the frequency estimate), and the filter's state is readable (kp, ki, kr, integ, rate, and for this flavor sigma_f and the covariance start through the blob). One thing differs for the Kalman flavor, and a composing loop must act on it: the fixed-gain filter's kp, ki and kr are constants, so an embedder can publish them once at attach, but the Kalman flavor's gain schedule moves, so they are running values and an embedder that wants them as probes publishes them per update. That is a line in the embedder's adoption (#3136), not code here.

The blob. The Kalman blob has its own magic and version, so a fixed-gain blob and a Kalman blob refuse each other at the envelope. The fixed-gain blob's flavor and pad words (eight bytes, reserved at version 1) are read as zero there and stay as built; the Kalman blob does not use them. Its payload is the base's seven numbers, then P, P0, q and r. P is not checkable by the gains-from-bandwidth rule the fixed-gain blob uses, so a Kalman set-state accepts a blob only if P and P0 are finite and positive definite (a Cholesky), the figures are inside the flavor's domain, the gains in force are the ones P and r give, and the bandwidth is the figures'.

22. Reuse

A search of the tree for a covariance or Riccati step (covariance, Riccati, Kalman, innovation, Cholesky, the Lyapunov solve) finds only state_filter's own exact-bandwidth solve. There is nothing to reuse. The Lyapunov solve of §11.1 and the Riccati update are different equations; the 3-by-3 update here is new and small.

23. Where each question is answered

Each question the design raised, and where its answer is. Every number is in the report (src/doppler/track/tests/validation/state_filter_kalman/results.md); none is typed here.

  1. Convergence time against the fixed-gain loop's pull-in. A start of 4 times sigma_f settles a frequency step in 0.58 of the fixed-gain loop's updates at bn*t 0.02 (§2.6); the table of settling by start, slope and delay is the report's record.
  2. Wrong noise figures. The delivered bandwidth goes as the sixth root of the noise ratio to 1.1% over ratios 0.01 to 100 (§2.3).
  3. Conditioning of the covariance update for slow loops. The plain update is kept: against a copy in long double it stays positive definite at every update and its gains stay within 3e-11 down to bn*t 1e-6 (§2.7); the entry that loses digits is the small p12, which the gains do not feel.
  4. r and the slope both move with the signal-to-noise ratio. The effective loop gain is the Kalman gain times the detector slope, so a slope of 0.6 to 0.76 is the loop gain K of the stability map (§2.4); what the filter does when r is wrong in the joint way a compressed detector makes it is a closed loop with noise and a real discriminator, which is open (#3136).
  5. The slope and delay range. The filter at its steady state is stable at slopes 0.6, 0.76 and 1 and delays 0 to 2 at bn*t 0.04 (§2.4); the converging loop is measured noise-free (§2.6) and its stability against the frozen-gain prediction is open (#3136).
  6. The step's cost. About 9 ns per update; a retune about 0.29 ms; a create with a start above 1 1.2 ms at bn*t 1e-2 and 5.7 ms at 1e-4 (bench rows kalman_step, kalman_configure, create_start_1e2, create_start_1e4, single runs on one machine).