Algorithm Search⌘K

Definitioncore

Zadoff-Chu sequence

Also called ZC sequence, CAZAC sequence.

A complex sequence of constant amplitude whose periodic autocorrelation is zero at every nonzero shift. Used for preambles, random access and synchronization.

A Zadoff-Chu sequence is a complex sequence of length NN whose elements all have magnitude 11 and whose phases grow as a quadratic in the index. Its periodic autocorrelation is NN at shift 00 and exactly 00 at every other shift, for every length NN and every root uu coprime to NN. Its discrete Fourier transform also has constant magnitude, so the sequence is flat in both time and frequency. For prime NN, two sequences with different roots have a periodic cross-correlation of constant magnitude N\sqrt N at every shift. The family is named after Zadoff, who with Frank described the square-length case in 1962 (now the Frank code), and Chu, who gave the construction for every length in 1972.

Definition

Let N≥1N \ge 1 and let uu be an integer with gcd⁡(u,N)=1\gcd(u, N) = 1, the root. Let c=N mod 2c = N \bmod 2. The Zadoff-Chu sequence of root uu and length NN is

xu[n]=exp⁡ ⁣(−jπu n(n+c)N),n=0,1,…,N−1.x_u[n] = \exp\!\left(-\frac{j \pi u \, n (n + c)}{N}\right), \qquad n = 0, 1, \ldots, N - 1.

So xu[n]=e−jπun(n+1)/Nx_u[n] = e^{-j\pi u n(n+1)/N} for odd NN and xu[n]=e−jπun2/Nx_u[n] = e^{-j\pi u n^2/N} for even NN. The term cc makes the formula periodic with period NN: xu[n+N]=xu[n]x_u[n + N] = x_u[n] for every integer nn, so cyclic shifts are well defined. For odd NN, the number n(n+1)/2n(n+1)/2 is an integer, and xu[n]=e−j2πmn/Nx_u[n] = e^{-j 2\pi m_n / N} with mn=u n(n+1)/2 mod Nm_n = u \, n(n+1)/2 \bmod N; every element is an NN-th root of unity.

The periodic correlation of two sequences xx and yy of length NN at shift tt is

Cx,y(t)=∑n=0N−1x[n] y[(n+t) mod N]‾.C_{x,y}(t) = \sum_{n=0}^{N-1} x[n] \, \overline{y[(n + t) \bmod N]}.

Zero autocorrelation. Take odd NN. The exponents give n(n+1)−(n+t)(n+t+1)=−2nt−t(t+1)n(n+1) - (n+t)(n+t+1) = -2nt - t(t+1), so

Cxu,xu(t)=ejπut(t+1)/N∑n=0N−1ej2πutn/N.C_{x_u,x_u}(t) = e^{j\pi u t(t+1)/N} \sum_{n=0}^{N-1} e^{j 2\pi u t n / N}.

The sum is over all NN-th roots of unity of the form ej2π(ut)n/Ne^{j2\pi (ut) n/N}. It is NN if ut≡0(modN)ut \equiv 0 \pmod N and 00 otherwise. Since gcd⁡(u,N)=1\gcd(u, N) = 1, this is 00 for every t≢0t \not\equiv 0. The even case is the same with n2−(n+t)2=−2nt−t2n^2 - (n+t)^2 = -2nt - t^2.

Cross-correlation for prime NN. For two roots u1≠u2u_1 \ne u_2, the phase of the term nn in Cxu1,xu2(t)C_{x_{u_1}, x_{u_2}}(t) is a quadratic in nn with leading coefficient proportional to u1−u2u_1 - u_2. It is a quadratic Gauss sum, and its magnitude is N\sqrt N whenever gcd⁡(u1−u2,N)=1\gcd(u_1 - u_2, N) = 1. For prime NN this holds for all distinct roots, so the N−1N - 1 sequences of one prime length form a family with largest cross-correlation N\sqrt N. The magnitude follows from the classical evaluation of quadratic Gauss sums.

Flat spectrum. The DFT Xu[k]=∑nxu[n]e−j2πkn/NX_u[k] = \sum_n x_u[n] e^{-j2\pi kn/N} satisfies ∣Xu[k]∣=N|X_u[k]| = \sqrt N for every kk. This follows from the zero autocorrelation: ∣Xu[k]∣2|X_u[k]|^2 is the DFT of Cxu,xuC_{x_u,x_u}, which is NN at t=0t = 0 and 00 elsewhere, so ∣Xu[k]∣2=N|X_u[k]|^2 = N.

  1. ZADOFF-CHU(u, N) ▷ gcd(u, N) = 1
  2. 1c ← N mod 2
  3. 2return [exp(-jπ u n (n + c) / N) for n ← 0 to N - 1]
  4. CORR(x, y, t)
  5. 3return Σ_{n=0}^{N-1} x[n] · conj(y[(n + t) mod N])

Making the sequence costs O(N)O(N) operations in the real RAM model, and one correlation costs O(N)O(N). For odd NN all of the arithmetic can be done in integers modulo NN on the exponents mnm_n.

Examples and non-examples

Length 7, root 1. The exponents mn=n(n+1)/2 mod 7m_n = n(n+1)/2 \bmod 7 are 0,1,3,6,3,1,00, 1, 3, 6, 3, 1, 0, so the sequence is e−j2πmn/7e^{-j 2\pi m_n/7}: about 11, 0.6235−0.7818j0.6235 - 0.7818j, −0.9010−0.4339j-0.9010 - 0.4339j, 0.6235+0.7818j0.6235 + 0.7818j, −0.9010−0.4339j-0.9010 - 0.4339j, 0.6235−0.7818j0.6235 - 0.7818j, 11. At shift t=1t = 1, the differences mn−mn+1 mod 7m_n - m_{n+1} \bmod 7 take each value 0,1,…,60, 1, \ldots, 6 exactly once, so the correlation is the sum of all seventh roots of unity, which is 00. The same holds at every shift from 11 to 66.

Length 7, roots 1 and 3. For u=3u = 3 the exponents are 0,3,2,4,2,3,00, 3, 2, 4, 2, 3, 0. The cross-correlation with the root-1 sequence has the values 2.5794−0.5887j2.5794 - 0.5887j, 2.0685+1.6496j2.0685 + 1.6496j, −2.5794−0.5887j-2.5794 - 0.5887j, 2.6458j2.6458j, 2.6458j2.6458j, −2.5794−0.5887j-2.5794 - 0.5887j and 2.0685+1.6496j2.0685 + 1.6496j at shifts 00 to 66. Each has magnitude 7=2.6458\sqrt 7 = 2.6458, which is 8.458.45 dB below the peak of 77.

Even length. For N=8N = 8 and u=1u = 1, x[n]=e−jπn2/8x[n] = e^{-j\pi n^2/8}. The autocorrelation is 88 at shift 00 and 00 at the other seven shifts.

Comparison with the Welch bound. For prime NN and the M=N−1M = N - 1 roots, the largest cross-correlation is N\sqrt N. The Welch bound for MM sequences of length NN and energy NN is N(M−1)/(MN−1)N\sqrt{(M-1)/(MN-1)}. For N=7N = 7, 3131 and 839839 the bound is 2.44452.4445, 5.47715.4771 and 28.948228.9482, against N=2.6458\sqrt N = 2.6458, 5.56785.5678 and 28.965528.9655. The ratio is 1.08231.0823, 1.01651.0165 and 1.00061.0006. A binary family of the same size cannot come this close, since its correlations are integers of fixed parity.

Non-example: composite length. For N=63N = 63, the roots 11 and 22 differ by 11, which is coprime to 6363, and their cross-correlation has magnitude 63=7.9373\sqrt{63} = 7.9373 at every shift. The roots 11 and 44 differ by 33, which divides 6363. Their cross-correlation is 00 at some shifts and 3⋅63=13.7477\sqrt{3 \cdot 63} = 13.7477 at the others, so the constant magnitude is lost. This is one reason why standards use prime lengths when they need many roots.

Non-example: root not coprime to NN. If g=gcd⁡(u,N)>1g = \gcd(u, N) > 1, then ut≡0(modN)ut \equiv 0 \pmod N at t=N/gt = N/g, and the autocorrelation at that shift has magnitude NN, as large as the peak. The definition excludes such roots.

Use in LTE. LTE builds its random-access preambles from Zadoff-Chu sequences of prime length 839839 and makes several preambles from one root by cyclic shifts, since the shifts are orthogonal. The primary synchronization signal uses a length-63 sequence with the middle element removed and one of the roots 2525, 2929 and 3434.

  • The Frank code of length L2L^2 has phases 2π pq/L2\pi \, pq / L on an L×LL \times L grid. It has the same zero periodic autocorrelation and belongs to the same family of chirp-like polyphase codes.
  • A frequency offset couples with the shift. If the received sequence is multiplied by ej2πn/Ne^{j2\pi n/N}, one bin of the DFT, the correlation peak moves from shift 00 to the shift −u−1 mod N-u^{-1} \bmod N, where u−1u^{-1} is the inverse of uu modulo NN. With the definition of CC above, the peak for N=7N = 7 moves to shift 66 for u=1u = 1 and to shift 22 for u=3u = 3; for N=839N = 839 and u=1u = 1 it moves to shift 838838. A frequency offset of a whole bin can therefore look like a delay, and preamble detectors must allow for it.
  • Maximal-length sequences are the binary counterpart: their periodic autocorrelation is −1-1 off the peak, not 00.
  • In SC-FDMA and OFDM systems the flat DFT of a Zadoff-Chu sequence makes it a good reference signal: every subcarrier gets the same power, and the time signal has a low peak-to-average ratio.
  • Preamble correlation detection uses the zero autocorrelation to find the start of a frame without false peaks at other shifts.

Code

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.

zadoff_chu_sequence.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/zadoff-chu-sequence/. The authors are listed in prov/MHXFB8.jsonl.

"""Zadoff-Chu sequences and their periodic correlations.

For a root u with gcd(u, N) = 1:
    x_u[n] = exp(-j pi u n (n + 1) / N)   for odd N,
    x_u[n] = exp(-j pi u n^2 / N)         for even N,
for n = 0, ..., N - 1. The periodic correlation at shift t is
    C(t) = sum over n of x[n] conj(y[(n + t) mod N]).
"""

import cmath
import math


def zadoff_chu(u: int, n: int) -> list[complex]:
    """The Zadoff-Chu sequence of root u and length n (gcd(u, n) = 1)."""
    if n < 1 or math.gcd(u, n) != 1:
        raise ValueError("need n >= 1 and gcd(u, n) = 1")
    c = n % 2  # @line L1
    return [cmath.exp(-1j * math.pi * u * k * (k + c) / n) for k in range(n)]  # @line L2


def zc_exponents(u: int, n: int) -> list[int]:
    """For odd n: the integers m[k] = u k (k + 1) / 2 mod n, so that x_u[k] = exp(-j 2 pi m[k] / n)."""
    if n % 2 == 0:
        raise ValueError("n must be odd")
    return [(u * k * (k + 1) // 2) % n for k in range(n)]


def periodic_corr(x: list[complex], y: list[complex], t: int) -> complex:
    """C(t) = sum over k of x[k] conj(y[(k + t) mod N])."""
    n = len(x)
    if len(y) != n:
        raise ValueError("lengths differ")
    return sum(x[k] * y[(k + t) % n].conjugate() for k in range(n))  # @line L3


def corr_all(x: list[complex], y: list[complex]) -> list[complex]:
    """C(t) for t = 0, ..., N - 1."""
    return [periodic_corr(x, y, t) for t in range(len(x))]


def corr_exact_odd(u1: int, u2: int, n: int, t: int) -> tuple[int, list[int]]:
    """C(t) for two Zadoff-Chu sequences of odd length n, exactly, as a sum of n-th roots of unity.

    Returns (n, counts) where counts[r] is how many k give the root exp(-j 2 pi r / n),
    so that C(t) = sum over r of counts[r] exp(-j 2 pi r / n). Integer arithmetic only.
    """
    a = zc_exponents(u1, n)
    b = zc_exponents(u2, n)
    counts = [0] * n
    for k in range(n):
        counts[(a[k] - b[(k + t) % n]) % n] += 1
    return n, counts
test_zadoff_chu_sequence.py 102 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/zadoff-chu-sequence/. The authors are listed in prov/MHXFB8.jsonl.

import cmath
import math

from zadoff_chu_sequence import corr_all, corr_exact_odd, periodic_corr, zadoff_chu, zc_exponents

TOL = 1e-9


def test_check_values_length_seven() -> None:
    x = zadoff_chu(1, 7)
    y = zadoff_chu(3, 7)
    auto = corr_all(x, x)
    assert abs(auto[0] - 7) < TOL
    assert all(abs(c) < TOL for c in auto[1:])
    assert all(abs(abs(c) - math.sqrt(7)) < TOL for c in corr_all(x, y))
    assert abs(math.sqrt(7) - 2.6458) < 5e-5


def test_exponent_form() -> None:
    assert zc_exponents(1, 7) == [0, 1, 3, 6, 3, 1, 0]
    x = zadoff_chu(1, 7)
    for k, m in enumerate(zc_exponents(1, 7)):
        assert abs(x[k] - cmath.exp(-2j * math.pi * m / 7)) < TOL


def test_constant_amplitude_and_periodic_extension() -> None:
    for n, u in ((7, 1), (13, 5), (63, 2), (8, 3), (64, 5)):
        x = zadoff_chu(u, n)
        assert all(abs(abs(v) - 1) < TOL for v in x)
        c = n % 2
        for k in range(n):
            nxt = cmath.exp(-1j * math.pi * u * (k + n) * (k + n + c) / n)
            assert abs(nxt - x[k]) < TOL


def test_zero_autocorrelation_for_coprime_roots() -> None:
    for n in (7, 13, 31, 63, 8, 16, 30):
        for u in range(1, n):
            if math.gcd(u, n) != 1:
                continue
            x = zadoff_chu(u, n)
            auto = corr_all(x, x)
            assert abs(auto[0] - n) < 1e-8
            assert all(abs(c) < 1e-8 for c in auto[1:])


def test_exact_zero_autocorrelation_in_integers() -> None:
    # For odd prime n, every shift t != 0 hits each n-th root of unity once,
    # and the sum of all n-th roots of unity is 0.
    for n in (7, 11, 13):
        for u in range(1, n):
            for t in range(1, n):
                _, counts = corr_exact_odd(u, u, n, t)
                assert counts == [1] * n


def test_cross_correlation_prime_length() -> None:
    for n in (7, 13, 31):
        for u1 in range(1, n):
            for u2 in (1, 2, n - 1):
                if u2 == u1:
                    continue
                vals = corr_all(zadoff_chu(u1, n), zadoff_chu(u2, n))
                assert all(abs(abs(c) - math.sqrt(n)) < 1e-8 for c in vals)


def test_cross_correlation_composite_length() -> None:
    a = zadoff_chu(1, 63)
    # u2 - u1 = 1 is coprime to 63: constant magnitude sqrt(63)
    assert all(abs(abs(c) - math.sqrt(63)) < 1e-8 for c in corr_all(a, zadoff_chu(2, 63)))
    # u2 - u1 = 3 shares the factor 3: magnitudes 0 and sqrt(3 * 63)
    mags = {round(abs(c), 6) for c in corr_all(a, zadoff_chu(4, 63))}
    assert mags == {0.0, round(math.sqrt(189), 6)}


def test_dft_has_constant_magnitude() -> None:
    for n, u in ((7, 1), (13, 4), (16, 3)):
        x = zadoff_chu(u, n)
        for k in range(n):
            xk = sum(x[m] * cmath.exp(-2j * math.pi * k * m / n) for m in range(n))
            assert abs(abs(xk) - math.sqrt(n)) < 1e-8


def test_frequency_offset_moves_the_peak() -> None:
    for n, u in ((7, 1), (7, 3), (13, 5), (31, 7)):
        x = zadoff_chu(u, n)
        y = [x[k] * cmath.exp(2j * math.pi * k / n) for k in range(n)]
        c = corr_all(y, x)
        peak = max(range(n), key=lambda t: abs(c[t]))
        assert peak == (-pow(u, -1, n)) % n
        assert abs(abs(c[peak]) - n) < 1e-8


def test_periodic_corr_definition() -> None:
    x = zadoff_chu(2, 11)
    y = zadoff_chu(3, 11)
    for t in range(11):
        direct = sum(x[k] * y[(k + t) % 11].conjugate() for k in range(11))
        assert abs(periodic_corr(x, y, t) - direct) < TOL

References

  1. David C. Chu, Polyphase codes with good periodic correlation properties, IEEE Transactions on Information Theory 18(4), 1972, pp. 531 to 532 (the construction for every length N and the proof of zero periodic autocorrelation)
  2. R. L. Frank and S. A. Zadoff, Phase shift pulse codes with good periodic correlation properties, IRE Transactions on Information Theory 8(6), 1962, pp. 381 to 382 (the related codes of length N squared, now called Frank codes)
  3. Lloyd R. Welch, Lower bounds on the maximum cross correlation of signals, IEEE Transactions on Information Theory 20(3), 1974, pp. 397 to 399 (the bound that a set of Zadoff-Chu sequences of prime length nearly meets)

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 proofH0 no proof
  • add a proof in proofs/ (06.5)
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)
WritingW4 complete
  • a review of the text: no review record reviews/MHXFB8/text.yaml