Algorithm Search⌘K

Algorithmadvanced

Oerder and Meyr timing estimation

Also called square-law timing recovery, Oerder-Meyr estimator.

A feedforward timing estimator. It squares the magnitude of a block of samples at four per symbol, takes the DFT bin at the symbol rate and reads the delay from the phase of that bin.

Time
O(N S) worst
Space
O(S) extra
Where
N = the number of symbols in the block; S = the samples per symbol
Properties
carrier phase invariantdeterministicfeedforwardnon data aided
Origin
Martin Oerder, Heinrich Meyr, 1988

Oerder and Meyr timing estimation is a feedforward, non-data-aided method for symbol timing recovery. The power ∣y(t)∣2|y(t)|^2 of the matched filter output of a linearly modulated signal is, on average, a constant plus a sinusoid at the symbol rate, whose phase is the delay τ\tau. The estimator samples the output at Ls=4L_s = 4 samples per symbol, squares the magnitudes, computes the one bin of the discrete Fourier transform at the symbol rate, X=∑n∣x[n]∣2e−j2πn/LsX = \sum_n |x[n]|^2 e^{-j2\pi n/L_s}, and returns τ^=−arg⁡(X)/(2π)\hat\tau = -\arg(X)/(2\pi). There is no loop, so the estimate of a block is ready after the block, without acquisition time, which suits burst receivers. The squaring removes the data and the carrier phase. The estimate is then applied with an interpolator such as the Farrow interpolator. The sinusoid comes from the excess bandwidth: for a raised cosine pulse with roll-off β\beta its amplitude is β/4\beta/4, so the method needs β>0\beta > 0. The feedback detectors with the same idea are the early-late gate and the Gardner detector.

In plain words

The strength of the received signal rises and falls once per symbol on average: it is strongest near the moments when the symbols should be read. The pattern of the data blurs this rhythm, but over many symbols the rhythm remains. The estimator measures the strength of the signal four times per symbol over a block. It then asks how well the measured strengths match a wave that repeats once per symbol, and at which shift of that wave the match is best. That shift is the timing. The method does not need the data or the phase of the carrier, and it gives an answer for the whole block at once instead of slowly moving toward it.

The problem

Times are in symbol periods, T=1T = 1. The input is a block of N=L0LsN = L_0 L_s samples x[n]=y(n/Ls)x[n] = y(n/L_s) of the matched filter output

y(t)=ejθ∑mam g(t−m−τ)+v(t),y(t) = e^{j\theta}\sum_m a_m\,g(t - m - \tau) + v(t),

taken by a free-running clock at Ls≥3L_s \ge 3 samples per symbol. The pulse gg is a raised cosine with roll-off β>0\beta > 0, the symbols ama_m are unknown, independent and zero-mean with E∣am∣2=1E|a_m|^2 = 1, θ\theta is an unknown carrier phase, vv is filtered noise with SNR=Es/N0\mathrm{SNR} = E_s/N_0, and τ\tau is constant over the block. The output is an estimate τ^∈[−12,12)\hat\tau \in [-\frac12, \frac12) of τ\tau modulo one symbol, so that the receiver can interpolate the strobes y(k+τ^)y(k + \hat\tau).

The algorithm

  1. OERDER-MEYR(x[0..N-1], Ls)
  2. 1rot[i] <- exp(-j 2 pi i / Ls) for i <- 0 to Ls - 1
  3. 2X <- 0
  4. 3for n <- 0 to N - 1 do
  5. 4X <- X + |x[n]|^2 * rot[n mod Ls] ▷ symbol-rate DFT bin of |x|^2
  6. 5tau <- -arg(X) / (2 pi) ▷ wrapped to [-1/2, 1/2)
  7. 6return tau

Line L1 builds a table of the LsL_s rotations. For Ls=4L_s = 4 they are 1,−j,−1,j1, -j, -1, j, so with Pr=∑n≡r∣x[n]∣2P_r = \sum_{n \equiv r} |x[n]|^2 for r=0,1,2,3r = 0, 1, 2, 3, line L4 reduces to X=(P0−P2)+j(P3−P1)X = (P_0 - P_2) + j(P_3 - P_1) and needs no multiplications. Line L4 is one bin of the DFT, which is what the Goertzel algorithm computes in general. Line L5 takes the argument with a two-argument arctangent. For a long stream, the receiver runs the estimator on consecutive blocks and unwraps the estimates, because each is known only modulo one symbol.

Example

Take QPSK data (seed 7), β=0.5\beta = 0.5, τ=0.3\tau = 0.3, no noise, Ls=4L_s = 4 and a block of L0=100L_0 = 100 symbols in the middle of a longer stream, so N=400N = 400. The four partial sums of line L4 are:

rr PrP_r rotation
0 85.99185.991 11
1 99.48599.485 −j-j
2 92.52892.528 −1-1
3 78.91678.916 jj

So X=(85.991−92.528)+j(78.916−99.485)=−6.537−20.569jX = (85.991 - 92.528) + j(78.916 - 99.485) = -6.537 - 20.569j. Its argument is −1.8786-1.8786 rad, and line L5 gives τ^=0.29897\hat\tau = 0.29897, an error of 0.0010.001 symbol. The mean of XX is β8Ne−j2πτ=25e−j0.6π=−7.725−23.776j\frac{\beta}{8}N e^{-j2\pi\tau} = 25e^{-j0.6\pi} = -7.725 - 23.776j: the data pattern moved XX from its mean, which is self-noise. With alternating data am=(−1)ma_m = (-1)^m the power is exactly 12+12cos⁡(2π(t−τ))\frac12 + \frac12\cos(2\pi(t - \tau)), the sums are 34.548,97.553,65.450,2.44734.548, 97.553, 65.450, 2.447, and X=−30.902−95.106j=100e−j0.6πX = -30.902 - 95.106j = 100e^{-j0.6\pi}, which gives τ^=0.3000003\hat\tau = 0.3000003.

Over 20 random QPSK blocks without noise, the rms error was 0.00560.0056 symbol and the largest 0.0100.010 (measurement). At Es/N0=10E_s/N_0 = 10 dB, 30 blocks gave a mean square error of 1.921.92 times the MCRB 1/(8π2ξL0 SNR)=1.33×10−41/(8\pi^2\xi L_0\,\mathrm{SNR}) = 1.33 \times 10^{-4} (measurement). With alternating data and a delay that grows by 0.0040.004 symbol per symbol, from 0.30.3 to 1.51.5 over 300 symbols, blocks of 20 symbols with unwrapping followed the delay at each block centre within 0.010.01 (measurement).

Correctness

Claim. If Ls≥3L_s \ge 3 and NN is a multiple of LsL_s, then E[X]=β8Ne−j2πτE[X] = \frac{\beta}{8}N e^{-j2\pi\tau} for every carrier phase and every stationary noise, so the phase of the mean gives τ\tau exactly. For Ls=2L_s = 2, XX is real and the method fails. As L0→∞L_0 \to \infty the estimate converges to τ\tau modulo one.

Key steps. By Poisson summation, the mean power of a raised cosine signal is 1−β4+β4cos⁡(2π(t−τ))1 - \frac{\beta}{4} + \frac{\beta}{4}\cos(2\pi(t - \tau)) plus the noise power. Over whole periods, the DFT bin removes the constant and the term at twice the symbol rate, and keeps β8e−j2πτ\frac{\beta}{8}e^{-j2\pi\tau} per sample. At Ls=2L_s = 2 the term at −1-1 cycle per symbol aliases onto the one at +1+1. Also, Re⁡{Xej2πτc}=∑n∣x[n]∣2cos⁡(2π(n/Ls−τc))\operatorname{Re}\{Xe^{j2\pi\tau_c}\} = \sum_n |x[n]|^2\cos(2\pi(n/L_s - \tau_c)), so τ^\hat\tau is the τc\tau_c that maximizes the match between the measured power and a sinusoid at the symbol rate, and the tests check this against a grid search. The full proof is in the proofs file.

The mean is a closed form under assumptions: raised cosine pulses, independent data that extend beyond the block, stationary noise and a constant delay. The variance is not given in closed form here; the numbers above are measurements.

Proof: The spectral line of the squared signal has the mean (beta/8) N e^(-j 2 pi tau), so the Oerder and Meyr estimate is unbiased in phase and needs at least three samples per symbolfull

Times are in symbol periods, T=1T = 1. The input is x[n]=y(n/Ls)x[n] = y(n/L_s) for n=0,…,N−1n = 0, \ldots, N - 1 with N=L0LsN = L_0 L_s, where y(t)=ejθ∑mamg(t−m−τ)+v(t)y(t) = e^{j\theta}\sum_m a_m g(t - m - \tau) + v(t). The pulse gg is a raised cosine with roll-off 0<β<10 < \beta < 1, the data are independent with Eam=0E a_m = 0 and E∣am∣2=1E|a_m|^2 = 1 and extend beyond the window on both sides, and vv is stationary noise independent of the data with E∣v(t)∣2=σv2E|v(t)|^2 = \sigma_v^2. Lines L1 to L4 compute

X=∑n=0N−1∣x[n]∣2e−j2πn/Ls,X = \sum_{n=0}^{N-1}|x[n]|^2 e^{-j2\pi n/L_s},

and line L5 returns τ^=−arg⁡(X)/(2π)\hat\tau = -\arg(X)/(2\pi).

Lemma 1 (mean power). E∣y(t)∣2=1−β4+σv2+β4cos⁡(2π(t−τ))E|y(t)|^2 = 1 - \frac{\beta}{4} + \sigma_v^2 + \frac{\beta}{4}\cos(2\pi(t - \tau)), for every θ\theta.

Proof. The factor ejθe^{j\theta} drops out of ∣y∣2|y|^2. The cross terms between different symbols, and between data and noise, have mean zero. What remains is ∑mg(t−m−τ)2+σv2\sum_m g(t - m - \tau)^2 + \sigma_v^2, and the folded energy formula ∑mg(x+m)2=1−β4+β4cos⁡(2πx)\sum_m g(x + m)^2 = 1 - \frac{\beta}{4} + \frac{\beta}{4}\cos(2\pi x), proved on the early-late gate proof page by Poisson summation, gives the result. □\square

Theorem 1 (mean of the spectral line). If Ls≥3L_s \ge 3 and NN is a multiple of LsL_s, then

E[X]=β8Ne−j2πτ.E[X] = \frac{\beta}{8}N e^{-j2\pi\tau}.

So −arg⁡E[X]/(2π)=τ-\arg E[X]/(2\pi) = \tau modulo one symbol.

Proof. Write ϕn=2πn/Ls\phi_n = 2\pi n/L_s. By Lemma 1, E[X]=∑n(c+β4cos⁡(ϕn−2πτ))e−jϕnE[X] = \sum_n \bigl(c + \frac{\beta}{4}\cos(\phi_n - 2\pi\tau)\bigr)e^{-j\phi_n} with the constant c=1−β4+σv2c = 1 - \frac{\beta}{4} + \sigma_v^2. Over a whole number of periods, ∑ne−jϕn=0\sum_n e^{-j\phi_n} = 0, so the constant drops out. Expand the cosine:

cos⁡(ϕn−2πτ)e−jϕn=12e−j2πτ+12ej2πτe−j2ϕn.\cos(\phi_n - 2\pi\tau)e^{-j\phi_n} = \frac12 e^{-j2\pi\tau} + \frac12 e^{j2\pi\tau}e^{-j2\phi_n}.

The first term sums to N2e−j2πτ\frac{N}{2}e^{-j2\pi\tau}. The second sums to zero because e−j2ϕn=e−j4πn/Lse^{-j2\phi_n} = e^{-j4\pi n/L_s} runs over whole periods of a nontrivial root of unity when Ls≥3L_s \ge 3. Multiply by β4\frac{\beta}{4}. □\square

Theorem 2 (why Ls=2L_s = 2 fails). For Ls=2L_s = 2, the rotations are e−jπn=±1e^{-j\pi n} = \pm1, so XX is real and arg⁡X∈{0,π}\arg X \in \{0, \pi\} for every input. The estimate cannot show τ\tau.

Proof. Immediate. In Theorem 1, the second term then does not cancel: e−j2πn=1e^{-j2\pi n} = 1, and E[X]=β8N(e−j2πτ+ej2πτ)=β4Ncos⁡(2πτ)E[X] = \frac{\beta}{8}N(e^{-j2\pi\tau} + e^{j2\pi\tau}) = \frac{\beta}{4}N\cos(2\pi\tau), which is real. This is aliasing: ∣y∣2|y|^2 has a band up to 1+β1 + \beta cycles per symbol, and sampling it at two per symbol folds the line at +1+1 onto the line at −1-1. □\square

Theorem 3 (exact for alternating data). If am=(−1)ma_m = (-1)^m and there is no noise, then X=N4e−j2πτX = \frac{N}{4}e^{-j2\pi\tau} exactly, for every window, so τ^=τ\hat\tau = \tau.

Proof. By Poisson summation, y(t)=±ejθcos⁡(π(t−τ))y(t) = \pm e^{j\theta}\cos(\pi(t - \tau)), as in the early-late gate proof. So ∣y(t)∣2=12+12cos⁡(2π(t−τ))|y(t)|^2 = \frac12 + \frac12\cos(2\pi(t - \tau)) with no random part, and the computation of Theorem 1 with 12\frac12 in place of β4\frac{\beta}{4} gives XX itself, not only its mean. □\square

Theorem 4 (consistency). As L0→∞L_0 \to \infty, X/N→β8e−j2πτX/N \to \frac{\beta}{8}e^{-j2\pi\tau} in mean square, so τ^→τ\hat\tau \to \tau modulo one.

Proof. The sequence ∣x[n]∣2|x[n]|^2 is periodic in distribution with period LsL_s and has a covariance that decays with the distance ∣n−n′∣|n - n'| in symbols, because g(t)g(t) decays as ∣t∣−3|t|^{-3} and the data are independent. So the covariances are summable and Var⁡(X/N)=O(1/N)\operatorname{Var}(X/N) = O(1/N). With Theorem 1 this gives convergence in mean square. The argument is a continuous function of XX away from X=0X = 0, and the limit is not zero for β>0\beta > 0. □\square

Theorem 1 is a closed form under assumptions: raised cosine pulses, independent zero-mean data that fill the window and extend past it, stationary noise, and a constant delay. The variance of τ^\hat\tau for a finite L0L_0 comes from two sources, the noise and the data pattern (self-noise). It is not given in closed form here; the page reports measurements against the MCRB. The tests check Theorem 3 to 10−510^{-5} for Ls∈{3,4,5,8}L_s \in \{3, 4, 5, 8\}, and check that τ^\hat\tau equals the maximum of the grid search over J(τc)=∑n∣x[n]∣2cos⁡(2π(n/Ls−τc))J(\tau_c) = \sum_n |x[n]|^2\cos(2\pi(n/L_s - \tau_c)) to 10−710^{-7}; this holds because J(τc)=Re⁡{Xej2πτc}=∣X∣cos⁡(arg⁡X+2πτc)J(\tau_c) = \operatorname{Re}\{X e^{j2\pi\tau_c}\} = |X|\cos(\arg X + 2\pi\tau_c) is largest at τc=−arg⁡X/(2π)\tau_c = -\arg X/(2\pi).

Complexity

Each sample costs two real multiplications and one addition for ∣x[n]∣2|x[n]|^2, and one multiply-add by a table entry, or only an addition when Ls=4L_s = 4. So a block costs O(L0Ls)O(L_0 L_s) operations and one arctangent, in the real RAM, with O(Ls)O(L_s) extra space for the table. The work per symbol is O(Ls)O(L_s), a little more than a feedback loop at two samples per symbol, but the estimate has no acquisition time. The sum can be split over parallel hardware, since it has no feedback.

Properties

  • Feedforward. The estimate of a block depends only on that block. There is no hang-up and no acquisition time, which makes the method suitable for bursts.
  • Non-data-aided and phase-free. The magnitude removes the carrier phase, and a frequency offset small enough not to distort the matched filter output does not matter.
  • Needs excess bandwidth. The line amplitude is β/4\beta/4 times the symbol power. For β→0\beta \to 0 the line vanishes and the estimate becomes noise.
  • Modulo one symbol. τ^\hat\tau is in [−12,12)[-\frac12, \frac12). Which symbol the strobe belongs to must come from frame synchronization or from unwrapping.
  • Low-SNR maximum likelihood link. At low SNR, the non-data-aided log-likelihood of the delay is about proportional to ∑k∣y(k+τc)∣2\sum_k |y(k + \tau_c)|^2, a periodic function of τc\tau_c. The estimator maximizes its first Fourier component (heuristic justification of the method).

Variants and improvements

  • Other nonlinearities. ∣x∣|x|, ∣x∣4|x|^4 or ln⁡(1+∣x∣2/σ2)\ln(1 + |x|^2/\sigma^2) also produce a line at the symbol rate. They change the noise and the self-noise, but not the structure.
  • Other sample rates. Any Ls≥3L_s \ge 3 works by the same proof; Ls=4L_s = 4 is the cheapest. Variants at two samples per symbol interpolate a third sample or use a different nonlinearity to avoid the aliasing.
  • Block-wise tracking. Running the estimator on consecutive blocks, with unwrapping, follows a slowly drifting delay, as in the example. A smoothing filter on the estimates reduces their variance.
  • Feedback form. Using Im⁡{Xej2πτk}\operatorname{Im}\{X e^{j2\pi\tau_k}\} as an error signal turns the estimator into a timing error detector for a loop.
  • Data-aided estimation. With known symbols, the delay can be found by correlating with the known waveform, which reaches the MCRB at lower SNR; see data-aided synchronization.

When to use it

Use the Oerder and Meyr estimator when the receiver samples at a fixed rate of four samples per symbol, the data arrive in bursts or the timing must be found fast, the roll-off is not small, and the carrier is not yet recovered. It is a standard first stage in digital burst modems: estimate the timing, interpolate, then recover the carrier. For continuous links with tight jitter requirements, a narrow feedback loop averages over more symbols. For small roll-off, use a data-aided or decision-directed method.

Pitfalls

  • Two samples per symbol. At Ls=2L_s = 2 the rotations are ±1\pm1, XX is real, and the phase carries no timing information. The implementation raises an error for Ls<3L_s < 3.
  • Block not a multiple of LsL_s. Then the constant part of ∣x∣2|x|^2 does not cancel in XX and biases the estimate. Use a whole number of symbols.
  • Edges of a burst. If the block covers the ramp-up or the ramp-down of a burst, the power there does not follow the stationary model. Keep the block inside the data, or accept a larger error.
  • Wrap-around. An estimate near ±12\pm\frac12 can jump by one symbol from block to block. Unwrap before interpolating, and track which symbol each strobe belongs to.
  • Small roll-off. With β=0.1\beta = 0.1 the line is five times weaker than with β=0.5\beta = 0.5, and self-noise dominates unless the block is long.

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.

oerder_meyr_timing_estimation.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/oerder-meyr-timing-estimation/. The authors are listed in prov/WF9W5Z.jsonl.

"""Oerder and Meyr timing estimation (1988): square the matched filter output and take
the phase of its spectral line at the symbol rate.

The input is a block of matched filter output samples x[n] = y(n / L_s), at L_s
samples per symbol (L_s >= 3; Oerder and Meyr use 4), with times in symbol
periods. The symbols sit at t = k + tau. The estimator is

    X = sum_n |x[n]|^2 e^(-j 2 pi n / L_s),    tau_hat = -arg(X) / (2 pi),

which lies in [-1/2, 1/2). For raised cosine pulses with roll-off beta > 0 and
i.i.d. zero-mean data, E|y(t)|^2 = c0 + (beta/4) E|a|^2 cos(2 pi (t - tau)), so
E[X] = (beta/8) E|a|^2 N e^(-j 2 pi tau) for N samples: the phase of the mean
is exactly -2 pi tau. The estimate does not depend on the carrier phase.
"""

import cmath
import math
from typing import Sequence


def spectral_line(x: Sequence[complex], ls: int) -> complex:
    """X = sum_n |x[n]|^2 e^(-j 2 pi n / L_s), the symbol-rate DFT bin of |x|^2."""
    if ls < 3:
        raise ValueError("L_s must be at least 3")
    rot = [cmath.exp(-2j * math.pi * i / ls) for i in range(ls)]  # @line L1
    acc = 0j  # @line L2
    for n, v in enumerate(x):  # @line L3
        acc += (v.real * v.real + v.imag * v.imag) * rot[n % ls]  # @line L4
    return acc


def oerder_meyr(x: Sequence[complex], ls: int = 4) -> float:
    """The timing estimate tau_hat in [-1/2, 1/2) symbol periods from one block of samples."""
    xs = spectral_line(x, ls)
    tau = -cmath.phase(xs) / (2.0 * math.pi)  # @line L5
    if tau >= 0.5:
        tau -= 1.0
    return tau  # @line L6


def oerder_meyr_blocks(x: Sequence[complex], ls: int, block: int) -> list[float]:
    """One estimate per block of `block` symbols, unwrapped so that it is continuous."""
    out: list[float] = []
    step = block * ls
    for start in range(0, len(x) - step + 1, step):
        # Sample n of the block is sample start + n of the stream; start is a whole
        # number of symbols, so the delay relative to the block start is the same.
        tau = oerder_meyr(x[start:start + step], ls)
        if out:
            tau += round(out[-1] - tau)
        out.append(tau)
    return out
test_oerder_meyr_timing_estimation.py 167 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/oerder-meyr-timing-estimation/. The authors are listed in prov/WF9W5Z.jsonl.

import cmath
import math
import random

import pytest

from oerder_meyr_timing_estimation import oerder_meyr, oerder_meyr_blocks, spectral_line

BETA = 0.5
TAU = 0.3
LS = 4
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 samples(a, tau, n_sym, ls=LS, n0=0.0, seed=0, theta=0.0, drift=0.0, start=0, span=4, reach=8):
    """x[n] = y(start + n / ls) for n < n_sym ls, where
    y(t) = e^(j theta) sum a_k g(t - k - tau - drift k) + v(t), g raised cosine.

    The noise is v(t) = sum_m w_m rrc(t - m h) with h = 1/2 and w_m i.i.d.
    CN(0, h n0): a stationary process with autocorrelation n0 g(t - s).
    """
    rot = cmath.exp(1j * theta)
    h = 0.5
    m_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)
    out = []
    for n in range(n_sym * ls):
        t = start + n / ls
        k0 = int(round((t - tau) / (1 + drift)))
        acc = 0j
        for k in range(max(0, k0 - reach), min(len(a), k0 + reach + 1)):
            acc += a[k] * rc(t - k - tau - drift * k, BETA)
        acc *= rot
        if w is not None:
            c = int(round(t / h))
            for m in range(c - reach_w, c + reach_w + 1):
                acc += w[m - m_lo] * rrc(t - m * h, BETA)
        out.append(acc)
    return out


def qpsk(n, seed):
    rng = random.Random(seed)
    return [rng.choice(QPSK) for _ in range(n)]


def brute_force(x, ls):
    """argmax over tau_c of J(tau_c) = sum_n |x[n]|^2 cos(2 pi (n / ls - tau_c)), by a grid then ternary search."""
    p = [abs(v) ** 2 for v in x]

    def j(tc):
        return sum(pn * math.cos(2 * math.pi * (n / ls - tc)) for n, pn in enumerate(p))

    grid = [-0.5 + i / 400 for i in range(400)]
    best = max(grid, key=j)
    lo, hi = best - 1 / 400, best + 1 / 400
    for _ in range(80):
        m1, m2 = lo + (hi - lo) / 3, hi - (hi - lo) / 3
        if j(m1) < j(m2):
            lo = m1
        else:
            hi = m2
    tc = 0.5 * (lo + hi)
    return (tc + 0.5) % 1.0 - 0.5


def wrap(d):
    return (d + 0.5) % 1.0 - 0.5


def test_alternating_data_gives_exact_delay():
    # a_k = (-1)^k gives |y|^2 = (1 + cos(2 pi (t - tau))) / 2: a pure symbol-rate line.
    a = [(-1) ** k + 0j for k in range(140)]
    for tau in (0.3, -0.45, 0.0, 0.12):
        for ls in (3, 4, 5, 8):
            x = samples(a, tau, 100, ls=ls, start=20, reach=24)
            assert abs(wrap(oerder_meyr(x, ls) - tau)) < 1e-5


def test_matches_brute_force_search():
    for seed in range(4):
        a = qpsk(100, seed)
        x = samples(a, TAU, 100, n0=0.1, seed=seed + 50)
        assert abs(wrap(oerder_meyr(x, LS) - brute_force(x, LS))) < 1e-7


def test_carrier_phase_does_not_change_the_estimate():
    a = qpsk(100, 9)
    x0 = samples(a, TAU, 100)
    x1 = samples(a, TAU, 100, theta=2.0)
    assert abs(oerder_meyr(x0) - oerder_meyr(x1)) < 1e-12


def test_needs_three_samples_per_symbol():
    # At L_s = 2 the rotations are +1 and -1, so X would be real and its phase could not show tau.
    with pytest.raises(ValueError):
        spectral_line([1 + 0j] * 8, 2)


def test_range_of_estimate():
    rng = random.Random(3)
    for _ in range(100):
        x = [complex(rng.gauss(0, 1), rng.gauss(0, 1)) for _ in range(40)]
        t = oerder_meyr(x)
        assert -0.5 <= t < 0.5


def test_noiseless_random_data_is_close():
    # The data run on for 10 symbols on each side of the 100-symbol window, as in a
    # stream. What is left is self-noise: the data pattern moves the line a little.
    errs = []
    for seed in range(20):
        x = samples(qpsk(120, seed), TAU, 100, start=10)
        errs.append(wrap(oerder_meyr(x) - TAU))
    rms = math.sqrt(sum(e * e for e in errs) / len(errs))
    assert rms < 0.01


def test_noise_variance_against_mcrb():
    snr = 10.0
    l0 = 100
    xi = 1.0 / 12.0 + BETA ** 2 * (0.25 - 2.0 / math.pi ** 2)
    mcrb = 1.0 / (8 * math.pi ** 2 * xi * l0 * snr)
    errs = []
    for seed in range(30):
        x = samples(qpsk(l0 + 20, 100 + seed), TAU, l0, start=10, n0=1.0 / snr, seed=200 + seed)
        errs.append(wrap(oerder_meyr(x) - TAU))
    mse = sum(e * e for e in errs) / len(errs)
    assert 1.0 <= mse / mcrb <= 4.0


def test_blocks_follow_a_drifting_delay():
    # The delay grows by 0.004 T per symbol, from 0.3 to 1.5 over 300 symbols.
    a = [(-1) ** k + 0j for k in range(330)]
    x = samples(a, TAU, 300, start=0, drift=0.004, reach=24)
    est = oerder_meyr_blocks(x, LS, 20)
    assert len(est) == 15
    for i, e in enumerate(est):
        mid = 20 * i + 10
        assert abs(e - (TAU + 0.004 * mid)) < 0.01
    assert est[-1] > 1.0

History

Clock recovery by squaring the signal and filtering out the tone at the symbol rate is an old analog technique. Martin Oerder and Heinrich Meyr, at the RWTH Aachen, published a digital form in the IEEE Transactions on Communications in 1988: sample at a fixed rate of four samples per symbol, square, and take one DFT coefficient, so the phase of the tone is computed directly instead of filtered by a loop. Their paper gave the variance of the estimate and showed its use in all-digital receivers with interpolation. Meyr, Moeneclaey and Fechtel later placed it among the feedforward synchronizers derived from the likelihood function.

References

  1. M. Oerder and H. Meyr, Digital filter and square timing recovery, IEEE Transactions on Communications 36(5), 1988, pages 605 to 612, the estimator from the spectral line at the symbol rate of the squared samples at four samples per symbol, and its variance
  2. Heinrich Meyr, Marc Moeneclaey and Stefan A. Fechtel, Digital Communication Receivers, Wiley, 1998, Section 5.4 (feedforward timing estimation from the spectral line)
  3. Umberto Mengali and Aldo N. D'Andrea, Synchronization Techniques for Digital Receivers, Plenum Press, 1997, Chapter 7 and Chapter 8 (feedforward non-data-aided timing estimation and its comparison with the modified Cramer-Rao bound)

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example