Algorithmcore
Gardner timing error detector
Also called Gardner TED, Gardner algorithm.
A timing error detector at two samples per symbol. It multiplies the midpoint sample by the difference of the two strobes around it, needs no decisions and does not depend on the carrier phase.
- Solves
- Symbol timing recovery
- Time
- O(N) worst
- Space
- O(1) extra
- Where
- N = the number of symbols
- Model
- Real RAM
- Properties
- carrier phase invariantdeterministicnon data aidedonline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Floyd M. Gardner, 1986
The Gardner timing error detector is the most common non-data-aided detector for symbol timing recovery in digital modems. It takes two samples per symbol: the strobe , where the symbol should be read, and the midpoint halfway between two strobes. Its output is . When the data change sign between two symbols, the midpoint lies on the zero crossing of the transition if the timing is right, and it moves away from zero, with a sign that shows the direction of the error, if the timing is wrong. The product with removes the sign of the transition. The detector needs no decisions, and a carrier phase cancels in the product, so the loop can run before carrier recovery. For raised cosine pulses its mean output is with . It drives the loop filter and accumulator of a phase-locked loop, with a Farrow interpolator when the sample clock is free-running. Against the early-late gate it needs one sample fewer per symbol and has less self-noise; against the Mueller and Muller detector it needs twice the samples but no decisions and no carrier phase.
In plain words
Picture the signal moving from one symbol value to the next. If the next symbol has the opposite sign, the signal crosses zero on the way, and with correct timing it crosses exactly halfway between the two reading points. The detector reads the signal at that halfway point too. If the halfway reading is not zero, the timing is off, and whether it lies above or below zero, compared with the direction of the change, tells whether the reading points are early or late. When two neighboring symbols are equal, the difference between them is near zero and the detector says almost nothing, which is correct because there is no crossing to measure. A turn of the whole signal by the carrier does not matter, since the detector compares the signal only with itself.
The problem
Times are in symbol periods, . The receiver can sample the matched filter output
at times it chooses, with a controlled clock or with an interpolator on a fixed grid of at least two samples per symbol. The pulse is real and even (a raised cosine with roll-off in the analysis), the symbols are unknown, independent and zero-mean with (BPSK, QPSK or QAM), is an unknown carrier phase, is filtered noise with , and the delay is unknown and may drift. The loop must give estimates so that the strobes fall on the symbol instants.
The algorithm
GARDNER(y, N, Kp, Ki, tau0)- 1
tau <- tau0; s <- 0 - 2
prev <- y(-1 + tau) - 3
for k <- 0 to N - 1 do - 4
mid <- y(k - 1/2 + tau) ▷ midpoint sample - 5
cur <- y(k + tau) ▷ strobe; est[k] <- tau - 6
e <- Re(conj(mid) * (prev - cur)) ▷ Gardner detector - 7
s <- s + Ki * e ▷ loop filter - 8
tau <- tau + Kp * e + s ▷ timing accumulator - 9
prev <- cur - 10
return est, strobes
Line L6 is the detector. With this sign it is positive when the strobes are early (), so line L8 adds it. Gardner's paper writes the difference the other way and subtracts. Line L9 keeps the strobe for the next symbol, so each symbol costs two new samples. Lines L7 and L8 are the PLL loop with the delay in place of the phase. For a first-order loop with noise bandwidth , with the detector slope at unit symbol energy, which is for .
Example
Take QPSK data (seed 1), , the true delay , no noise, and , so . The loop starts at , and the samples are rounded to three decimals:
| prev | mid (L4) | cur (L5) | (L6) | (L8) | ||
|---|---|---|---|---|---|---|
| 0 | ||||||
| 1 | ||||||
| 2 |
The mean error at is , but the first output is negative: at the data pattern pulls the wrong way. The large output at comes from a full sign change in both the real and the imaginary parts, the case that carries the most timing information. The error is at , at , at and below at and . After that the loop jitters around the delay with an rms error of and peaks of , without noise. With alternating data , the output is exactly and the loop stays at .
In noise at dB with , the loop form of the MCRB is . Three runs of 2400 symbols (seeds 7, 8 and 9) measured a variance of to times this bound (measurement).
Correctness
Claim. For raised cosine pulses, independent zero-mean data and stationary noise, the mean of with held fixed is , , for every carrier phase. So the loop has stable points at and behaves near lock as a PLL with detector gain .
Key steps. A phase cancels between and . The cross terms between different symbols have mean zero, so the mean is a sum over all integer shifts of . By Poisson summation only the Fourier coefficients at and remain. The one at is zero, because both products have the same integral, the autocorrelation of at lag . The one at is , an integral over the roll-off band. The full proof is in the proofs file.
The S-curve is a closed form under assumptions: raised cosine pulses, independent data, stationary noise, and constant while the mean is taken. The jitter and the noise ratios are measurements.
Proof: The Gardner detector has the S-curve A sin(2 pi Delta) with A = 4 sin(pi beta/2) / (pi (4 - beta^2)) for raised cosine pulses, and it does not depend on the carrier phasefull
Times are in symbol periods, . The matched filter output is , with a raised cosine pulse of roll-off , independent data with and , any carrier phase , and noise independent of the data with zero mean. With held fixed, line L2 or line L9 gives the previous strobe , line L4 gives the midpoint and line L5 the current strobe . Line L6 forms
Write . is the raised cosine spectrum, and on it satisfies and .
Lemma 1 (phase invariance). does not change when is replaced by for any real .
Proof. .
Lemma 2 (mean as a periodic sum). Without noise, , where .
Proof. By Lemma 1 we can take . Each of the three samples is , with the arguments , and . The cross terms with have mean zero, and , so . As runs over all integers, so does , which gives . The result is real because is real. With noise, the extra term is with and , which is zero for a stationary noise with an even real autocorrelation.
Theorem 1 (S-curve). with
For , and the slope at lock is .
Proof. By Poisson summation, , where is the Fourier transform of . Each product of two shifted copies of has a transform supported on , so only remain.
For : . Both integrals equal the autocorrelation of at lag , because is even. So .
For : let , so . Its transform at is . The integrand is nonzero only for , , where . For the exponential is , and for it is . So
Write . The constant part gives . For the other part, put , so . Then
using . Half of this is the second part. Together,
so . Since is real, . The sum is .
Theorem 2 (lock points). In the mean, the loop of lines L7 and L8 with has stable points at and unstable points at . The linear model of the phase-locked loop with detector gain applies near lock, for every carrier phase.
Proof. As for any sine S-curve: , the slope at is and the slope at is negative. Lemma 1 removes .
Theorem 3 (alternating data). If and there is no noise, then exactly.
Proof. As in the early-late gate proof, . With , the samples are , and , so .
The S-curve is a closed form under assumptions: raised cosine pulses, independent zero-mean data, stationary noise, and constant while the mean is taken. The detector also has self-noise from the data pattern, which is zero for alternating data (Theorem 3) and not zero for random data. The tests check Theorem 1 on 1280 random QPSK symbols at three offsets, and Theorem 3 to , the error of the truncated pulse sum in the test signal.
Complexity
Each symbol needs two new samples (lines L4 and L5), one complex subtraction, the real part of one complex product (two real multiplications and one addition), and the four operations of lines L7 and L8. With an interpolator of taps, a symbol costs operations. The loop is per symbol and for symbols in the real RAM, with extra space besides the output.
Properties
- Non-data-aided and phase-free. It needs no decisions and no carrier phase, so it works from the first symbol, before the carrier loop has locked. A residual frequency offset that turns the phase slowly does not disturb it.
- Two samples per symbol. The strobe of one symbol is reused as the previous strobe of the next, so the sample rate is , as in many modems that sample at twice the symbol rate anyway.
- Needs excess bandwidth. as : at and at . With little excess bandwidth the S-curve is small and the self-noise dominates.
- Self-noise and loop offset (measurement). Without noise the rms jitter was at and at , and the mean of was about , over three seeds each. The jitter is a third of that of the square-law early-late gate with the same bandwidth.
- Gain depends on amplitude. scales with the signal power, so an automatic gain control should come first.
Variants and improvements
- Real-valued form. For BPSK, or for the real and imaginary parts of QPSK separately, , which is the same value written without complex arithmetic.
- Decision-directed form. Replacing by removes much of the self-noise at high SNR, but it needs decisions and the carrier phase.
- Feedforward use. The same products can be averaged over a block to estimate a fixed delay, but the Oerder and Meyr estimator is the usual feedforward choice.
- Interpolated loop. In Gardner's 1993 structure, the sampler runs from a fixed clock, a numerically controlled oscillator gives the basepoint and the fractional interval, and a Farrow interpolator computes the samples of lines L4 and L5.
When to use it
Use the Gardner detector when the receiver has two samples per symbol, the modulation is BPSK, QPSK or a QAM with moderate roll-off, and the timing must lock before the carrier. It is the default choice in many software and hardware modems. With a small roll-off, or when decisions are reliable and the carrier phase is known, the Mueller and Muller detector or a data-aided detector gives less jitter. For short bursts, a feedforward estimate avoids the acquisition time of the loop.
Pitfalls
- Wrong midpoint. The midpoint must be half a symbol before the current strobe, between the two strobes in the product. Taking it after the current strobe reverses the sign of the S-curve, and the loop locks half a symbol off.
- Sign convention. Gardner's paper uses and subtracts the error from the timing. Mixing one convention for the detector with the other for the update makes the loop diverge from the right point.
- Long runs of equal symbols. A run of equal symbols has no transitions and gives no timing information. Scrambling the data keeps transitions frequent.
- Small roll-off. At the slope is a fifth of that at . Use a narrow loop or another detector.
- Offset QPSK. In OQPSK the quadrature data are delayed by half a symbol, so the detector must use the matching midpoint for each arm, or it sees no S-curve.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gardner-timing-error-detector/. The authors are listed in prov/9K1C0E.jsonl.
"""The Gardner timing error detector (F. M. Gardner, 1986) in a first- or second-order loop.
Times are in symbol periods T. The receiver has a sampler y(t) for the matched
filter output (an ADC with a controlled clock, or an interpolator). The loop
takes two samples per symbol: the strobe y(k + tau_k) and the midpoint
y(k - 1/2 + tau_k). The detector is
e_k = Re{ conj(y(k - 1/2 + tau_k)) (y(k - 1 + tau_{k-1}) - y(k + tau_k)) },
which is positive when the receiver samples too early (tau_k < tau). It needs
no decisions and no carrier phase: a phase rotation of y cancels in the
product. For raised cosine pulses with roll-off beta and i.i.d. zero-mean data
with E|a|^2 = 1, the mean of e_k is A sin(2 pi delta) with
A = 4 sin(pi beta / 2) / (pi (4 - beta^2)) and delta = tau - tau_k.
(This sign convention makes tau grow when e > 0; Gardner's paper writes the
difference the other way and subtracts.)
"""
import math
from typing import Callable
Sampler = Callable[[float], complex]
def detector(prev: complex, mid: complex, cur: complex) -> float:
"""The Gardner error from the previous strobe, the midpoint and the current strobe."""
return (mid.conjugate() * (prev - cur)).real # @line L6
def s_curve_amplitude(beta: float) -> float:
"""A in E[e] = A sin(2 pi delta), for raised cosine pulses and i.i.d. data."""
return 4.0 * math.sin(math.pi * beta / 2.0) / (math.pi * (4.0 - beta * beta))
def gain_for_bandwidth(bl_t: float, kd: float) -> float:
"""kp of a first-order loop with noise bandwidth B_L T for the detector slope kd."""
return 4.0 * bl_t / ((1.0 + 2.0 * bl_t) * kd)
def gardner_loop(
sample: Sampler,
n: int,
kp: float,
ki: float = 0.0,
tau0: float = 0.0,
) -> tuple[list[float], list[complex]]:
"""Run the loop over n symbols. Return the estimates tau_k and the strobes y(k + tau_k)."""
tau, s = tau0, 0.0 # @line L1
prev = sample(-1.0 + tau) # @line L2
taus: list[float] = []
strobes: list[complex] = []
for k in range(n): # @line L3
taus.append(tau)
mid = sample(k - 0.5 + tau) # @line L4
cur = sample(k + tau) # @line L5
strobes.append(cur)
e = detector(prev, mid, cur) # @line L6
s += ki * e # @line L7
tau += kp * e + s # @line L8
prev = cur # @line L9
return taus, strobes # @line L10
test_gardner_timing_error_detector.py 139 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gardner-timing-error-detector/. The authors are listed in prov/9K1C0E.jsonl.
import cmath
import math
import random
from gardner_timing_error_detector import detector, gain_for_bandwidth, gardner_loop, s_curve_amplitude
BETA = 0.5
TAU = 0.3
QPSK = [cmath.exp(1j * (math.pi / 4 + m * math.pi / 2)) for m in range(4)]
def rc(t, b):
"""The raised cosine pulse with roll-off b and T = 1."""
if abs(t) < 1e-12:
return 1.0
if abs(abs(t) - 1 / (2 * b)) < 1e-9:
return math.pi / 4 * math.sin(math.pi / (2 * b)) / (math.pi / (2 * b))
return math.sin(math.pi * t) / (math.pi * t) * math.cos(math.pi * b * t) / (1 - (2 * b * t) ** 2)
def rrc(t, b):
"""The root raised cosine pulse with roll-off b and T = 1."""
if abs(t) < 1e-12:
return 1 - b + 4 * b / math.pi
if abs(abs(t) - 1 / (4 * b)) < 1e-9:
return b / math.sqrt(2) * ((1 + 2 / math.pi) * math.sin(math.pi / (4 * b)) + (1 - 2 / math.pi) * math.cos(math.pi / (4 * b)))
return (math.sin(math.pi * (1 - b) * t) + 4 * b * t * math.cos(math.pi * (1 + b) * t)) / (math.pi * t * (1 - (4 * b * t) ** 2))
def make_sampler(a, tau, n0=0.0, seed=0, theta=0.0, span=4, reach=8):
"""Matched filter output y(t) = e^(j theta) sum a_k g(t - k - tau) + v(t), g raised cosine.
The noise is v(t) = sum_n w_n rrc(t - n h) with h = 1/2 and w_n i.i.d.
CN(0, h n0). Since rrc has bandwidth (1 + beta)/2 < 1/(2h), v is stationary
with autocorrelation n0 g(t - s): the matched filter output of white noise
of density n0 (up to the cut of rrc at span symbols).
"""
rot = cmath.exp(1j * theta)
h = 0.5
n_lo = int(-6 / h)
w = None
if n0 > 0:
rng = random.Random(seed)
sd = math.sqrt(h * n0 / 2)
w = [complex(rng.gauss(0, sd), rng.gauss(0, sd)) for _ in range(int((len(a) + 12) / h))]
reach_w = int(span / h)
def sample(t):
k0 = int(round(t - tau))
acc = 0j
for k in range(max(0, k0 - reach), min(len(a), k0 + reach + 1)):
acc += a[k] * rc(t - k - tau, BETA)
acc *= rot
if w is not None:
c = int(round(t / h))
for n in range(c - reach_w, c + reach_w + 1):
acc += w[n - n_lo] * rrc(t - n * h, BETA)
return acc
return sample
def qpsk(n, seed):
rng = random.Random(seed)
return [rng.choice(QPSK) for _ in range(n)]
def test_amplitude_closed_form():
assert abs(s_curve_amplitude(0.5) - 0.2400843) < 1e-6
# For small roll-off the amplitude is about beta / 2.
assert abs(s_curve_amplitude(0.01) / 0.005 - 1) < 1e-3
def test_noise_model_has_unit_variance_at_any_offset():
sample = make_sampler([0j] * 600, TAU, n0=1.0, seed=11)
for off in (0.0, 0.25, 0.5):
vals = [sample(k + off) for k in range(5, 595)]
var = sum(abs(v) ** 2 for v in vals) / len(vals)
# 590 samples that are nearly independent: the standard error is about 0.04.
assert abs(var - 1.0) < 0.2
def test_exact_lock_on_alternating_data():
# With a_k = (-1)^k the signal is cos(pi (t - tau)) and the error is
# sin(2 pi (tau - tau_k)) exactly, so the loop has no self-noise.
a = [(-1) ** k + 0j for k in range(400)]
taus, _ = gardner_loop(make_sampler(a, TAU, reach=24), 360, kp=0.1)
# What is left comes from cutting the pulse at 24 symbols.
for t in taus[300:]:
assert abs(t - TAU) < 1e-5
def test_detector_mean_matches_s_curve():
a = qpsk(1300, 2)
sample = make_sampler(a, TAU)
amp = s_curve_amplitude(BETA)
for delta in (-0.3, 0.1, 0.2):
es = []
for k in range(10, 1290):
t = k + TAU - delta
es.append(detector(sample(t - 1), sample(t - 0.5), sample(t)))
mean = sum(es) / len(es)
# The standard error of the mean is about 0.02 here.
assert abs(mean - amp * math.sin(2 * math.pi * delta)) < 0.06
def test_carrier_phase_does_not_change_the_loop():
a = qpsk(300, 4)
t1, _ = gardner_loop(make_sampler(a, TAU), 250, kp=0.05)
t2, _ = gardner_loop(make_sampler(a, TAU, theta=2.3), 250, kp=0.05)
assert max(abs(x - y) for x, y in zip(t1, t2)) < 1e-9
def test_random_data_noiseless_settles_near_true_delay():
a = qpsk(1700, 5)
kd = 2 * math.pi * s_curve_amplitude(BETA)
taus, _ = gardner_loop(make_sampler(a, TAU), 1650, kp=gain_for_bandwidth(0.0025, kd))
tail = taus[800:]
mean = sum(tail) / len(tail)
assert abs(mean - TAU) < 0.003
assert max(abs(t - TAU) for t in tail) < 0.006
def test_noise_variance_against_mcrb():
snr = 10.0
bl_t = 0.01
xi = 1.0 / 12.0 + BETA ** 2 * (0.25 - 2.0 / math.pi ** 2)
mcrb = bl_t / (4 * math.pi ** 2 * xi * snr)
a = qpsk(2400, 6)
sample = make_sampler(a, TAU, n0=1.0 / snr, seed=7)
kd = 2 * math.pi * s_curve_amplitude(BETA)
taus, _ = gardner_loop(sample, 2350, kp=gain_for_bandwidth(bl_t, kd))
tail = taus[400:]
mean = sum(tail) / len(tail)
var = sum((t - mean) ** 2 for t in tail) / len(tail)
assert 1.0 <= var / mcrb <= 4.0
History
Floyd M. Gardner published the detector in the IEEE Transactions on Communications in 1986, for receivers that sample at two samples per symbol with a clock that is not tied to the symbol rate. Its independence of the carrier phase allowed timing recovery to come first in a digital receiver. In 1993 Gardner, with Lars Erup and Robert A. Harris, described how such a loop drives an interpolator from a free-running sample clock, and the pair of the Gardner detector and a Farrow interpolator became a standard structure in digital modems.
References
- F. M. Gardner, A BPSK/QPSK timing-error detector for sampled receivers, IEEE Transactions on Communications 34(5), 1986, pages 423 to 429, the detector from the midpoint sample and the two strobes, its S-curve, and its independence of the carrier phase
- F. M. Gardner, Interpolation in digital modems, Part I: Fundamentals, IEEE Transactions on Communications 41(3), 1993, pages 501 to 507, timing loops with a free-running sampler, an interpolator and a numerically controlled oscillator
- Umberto Mengali and Aldo N. D'Andrea, Synchronization Techniques for Digital Receivers, Plenum Press, 1997, Chapter 7 (timing recovery in baseband transmission) and Chapter 8 (timing recovery with linear modulations: the non-data-aided detectors)
- Heinrich Meyr, Marc Moeneclaey and Stefan A. Fechtel, Digital Communication Receivers, Wiley, 1998, Chapter 9 (interpolation and the digital timing loop)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 9K1C0E Edit this page History Report an error Markdown