Definitioncore
Gold sequences
Also called Gold codes.
The 2^n + 1 binary sequences made from a preferred pair of m-sequences u and v: u, v and u plus every shift of v. All their periodic correlations take only the values -1, -t(n) and t(n) - 2.
Gold sequences are a family of binary sequences of period whose periodic autocorrelations (off the peak) and cross-correlations all lie in the set , with . Robert Gold built them in 1967 by adding, bit by bit, one m-sequence to every cyclic shift of a second m-sequence of the same degree. The pair must be a preferred pair, one whose own cross-correlation is three-valued. A single m-sequence has a perfect two-level autocorrelation, but there are few m-sequences of each degree and two of them can correlate badly. Gold sequences give up the perfect autocorrelation and get about sequences whose largest correlation is near for odd . That is why they are the spreading codes of many CDMA systems and the C/A codes of GPS.
Definition
Write a binary sequence of period as , its cyclic shift by as , with indices mod , and its decimation by as . The periodic correlation of two bit sequences at shift is
the correlation of their forms (bit to , bit to ). For a family , the figure of merit is
which covers the off-peak autocorrelations and all cross-correlations.
Preferred pair. Let and , so for odd and for even . Two m-sequences and of degree are a preferred pair if takes exactly the three values , and . A standard way to get one: take with or , where for odd and for (Sarwate and Pursley 1980, the section on m-sequence cross-correlation). For divisible by no preferred pair exists.
Gold family. For a preferred pair the Gold family is
with sequences of period . Gold's theorem (Gold 1967): every off-peak autocorrelation and every cross-correlation in takes a value in , so . The reason is the shift-and-add property of m-sequences: the correlation of two members reduces to the cross-correlation of and at some shift, or to an autocorrelation value . Each member is a sum of two sequences with linear recurrences of degree , so it satisfies the recurrence of the product polynomial of degree .
The construction and the computation of are below. Building the family costs bit operations in the word RAM model; checking by direct sums over all pairs and shifts costs , which is fine for .
GOLD-FAMILY(u, v) ▷ u, v a preferred pair of period N- 1
F ← [u, v] - 2
for τ ← 0 to N - 1 do - 3
append u ⊕ T^τ v to F ▷ bitwise XOR with the shifted v return FTHETA-MAX(F)for each pair a, b in F and each shift τ, except a = b with τ = 0 do- 4
θ ← N - 2 · #{k : a[k] ≠ b[(k + τ) mod N]} - 5
best ← max(best, |θ|) return best
Against the Welch bound. The Welch bound for sequences of length and energy gives , which is close to for . For odd , is about times the bound; for it is about times. The small set of Kasami sequences has a smaller , about , but only sequences.
Examples and non-examples
Degree 5 (the check value). The m-sequences of : and : , both started from , are a preferred pair. In fact , the decimation by . Over the shifts, takes the value six times, fifteen times and ten times. Here , so the values are , and as stated. The Gold family has distinct sequences of period and . The Welch bound for and is , so the family is within a factor of of it. In dB, the largest correlation is dB below the peak.
Degree 6. from and , which is the sequence of , are a preferred pair with values , and , and . Here and . The decimation by does not work for : , so is not an m-sequence of degree 6.
GPS C/A codes. The C/A code of each GPS satellite is a Gold code of period from the two 10-cell registers with polynomials and . Their cross-correlation over the shifts takes the value at shifts, at shifts and at shifts, which matches . Each satellite uses a different shift of the second register. The largest correlation is dB below the peak, which is the margin that lets a receiver separate satellites with parallel code phase search.
Non-example: degree 4. Degree 4 has two primitive polynomials, and . The cross-correlation of their m-sequences takes four values, , , and , so they are not a preferred pair, and no other pair of degree 4 is.
Non-example: a wrong decimation. For , is an m-sequence, but is not of the form above, and takes six values from to . Adding to the shifts of this sequence does not give a Gold family.
Non-example: m-sequences alone. A set of distinct m-sequences of one degree is not a good CDMA family in general: the degree 5 pair and above already reaches a correlation of , worse than the Gold bound , and degree 5 has only six m-sequences.
Related definitions
- Maximal-length sequences are the parts of a Gold family. Two of the members, and , are m-sequences; the others are not.
- Kasami sequences: the small set has fewer sequences () and a smaller (), and the large set contains a Gold family.
- The Welch bound is the limit that is compared with.
- Cross-correlation is the general signal processing notion; here it is periodic and on sequences.
- In code-division multiple access, sets the interference that one user leaks into the correlator of another, and multiuser detection removes what is left.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gold-sequences/. The authors are listed in prov/BGG18W.jsonl.
"""Gold sequences from a preferred pair of m-sequences, with integer correlations.
A polynomial over GF(2) is the list of its exponents, for example [5, 2, 0]
for x^5 + x^2 + 1. The m-sequence of f satisfies
s[k + n] = XOR over the exponents i < n of s[k + i].
The Gold family of a preferred pair (u, v) of period N = 2^n - 1 is
u, v and u XOR (v shifted by t) for t = 0, ..., N - 1: N + 2 sequences.
"""
def mseq(exps: list[int], state: list[int] | None = None) -> list[int]:
"""One period of the recurrence of f, from the state 1, 0, ..., 0 by default."""
n = max(exps)
s = list(state) if state is not None else [1] + [0] * (n - 1)
taps = [i for i in exps if i < n]
while len(s) < (1 << n) - 1:
k = len(s) - n
bit = 0
for i in taps:
bit ^= s[k + i]
s.append(bit)
return s
def decimate(s: list[int], q: int) -> list[int]:
"""The sequence s[q k mod N], k = 0, ..., N - 1."""
n = len(s)
return [s[(q * k) % n] for k in range(n)]
def shift(s: list[int], t: int) -> list[int]:
"""The cyclic shift s[(k + t) mod N]."""
n = len(s)
return [s[(k + t) % n] for k in range(n)]
def gold_family(u: list[int], v: list[int]) -> list[list[int]]:
"""The N + 2 sequences u, v and u XOR shift(v, t) for t = 0, ..., N - 1 (as bits)."""
n = len(u)
if len(v) != n:
raise ValueError("lengths differ")
fam = [list(u), list(v)] # @line L1
for t in range(n): # @line L2
fam.append([u[k] ^ v[(k + t) % n] for k in range(n)]) # @line L3
return fam
def xcorr(a: list[int], b: list[int], t: int) -> int:
"""Periodic correlation sum over k of (-1)^(a[k] XOR b[k + t]) for two bit sequences."""
n = len(a)
return n - 2 * sum(a[k] ^ b[(k + t) % n] for k in range(n)) # @line L4
def correlation_values(a: list[int], b: list[int]) -> set[int]:
"""The set of values of the periodic cross-correlation of a and b over all shifts."""
return {xcorr(a, b, t) for t in range(len(a))}
def max_correlation(fam: list[list[int]]) -> int:
"""theta_max: the largest |correlation| over all pairs and shifts, except the peaks at shift 0 of a with a."""
best = 0
for i, a in enumerate(fam):
for j in range(i, len(fam)):
b = fam[j]
for t in range(len(a)):
if i == j and t == 0:
continue
best = max(best, abs(xcorr(a, b, t))) # @line L5
return best
def gold_t(n: int) -> int:
"""t(n) = 1 + 2^floor((n + 2) / 2)."""
return 1 + (1 << ((n + 2) // 2))
def is_preferred_pair(u: list[int], v: list[int], n: int) -> bool:
"""True if the cross-correlation of u and v takes exactly the values -1, -t(n) and t(n) - 2."""
t = gold_t(n)
return correlation_values(u, v) == {-1, -t, t - 2}
test_gold_sequences.py 93 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gold-sequences/. The authors are listed in prov/BGG18W.jsonl.
from collections import Counter
from gold_sequences import (
correlation_values,
decimate,
gold_family,
gold_t,
is_preferred_pair,
max_correlation,
mseq,
shift,
xcorr,
)
def brute_xcorr(a: list[int], b: list[int], t: int) -> int:
pa = [1 - 2 * x for x in a]
pb = [1 - 2 * x for x in b]
n = len(a)
return sum(pa[k] * pb[(k + t) % n] for k in range(n))
def test_check_value_degree_five() -> None:
u = mseq([5, 2, 0])
v = mseq([5, 4, 3, 2, 0])
counts = Counter(xcorr(u, v, t) for t in range(31))
assert counts == {-9: 6, -1: 15, 7: 10}
assert gold_t(5) == 9
assert is_preferred_pair(u, v, 5)
def test_xcorr_matches_plus_minus_one_sum() -> None:
u = mseq([5, 2, 0])
v = mseq([5, 4, 3, 2, 0])
for t in range(31):
assert xcorr(u, v, t) == brute_xcorr(u, v, t)
def test_second_sequence_is_a_decimation() -> None:
u = mseq([5, 2, 0])
assert decimate(u, 3) == mseq([5, 4, 3, 2, 0])
def test_family_size_and_bound_degree_five() -> None:
fam = gold_family(mseq([5, 2, 0]), mseq([5, 4, 3, 2, 0]))
assert len(fam) == 33
assert len({tuple(s) for s in fam}) == 33
assert max_correlation(fam) == gold_t(5)
# every value of every correlation is -1, -t or t - 2 (except the peaks)
allowed = {-1, -9, 7}
for i in (0, 1, 2, 17, 32):
for j in (0, 1, 5, 20, 31):
for t in range(31):
if i == j and t == 0:
continue
assert xcorr(fam[i], fam[j], t) in allowed
def test_family_degree_six() -> None:
u = mseq([6, 1, 0])
v = mseq([6, 5, 2, 1, 0])
assert decimate(u, 5) == v
assert correlation_values(u, v) == {-17, -1, 15}
fam = gold_family(u, v)
assert len(fam) == 65 and max_correlation(fam) == 17 == gold_t(6)
def test_no_preferred_pair_for_degree_four() -> None:
# the two primitive polynomials of degree 4 give a four-valued cross-correlation
u = mseq([4, 1, 0])
v = mseq([4, 3, 0])
vals = correlation_values(u, v)
assert vals == {-5, -1, 3, 7}
assert not is_preferred_pair(u, v, 4)
for q in (7,):
assert not is_preferred_pair(u, decimate(u, q), 4)
def test_members_have_full_period_and_three_valued_autocorrelation() -> None:
u = mseq([5, 2, 0])
v = mseq([5, 4, 3, 2, 0])
fam = gold_family(u, v)
for s in fam[2:]:
assert all(s != shift(s, t) for t in range(1, 31))
auto = {xcorr(s, s, t) for t in range(1, 31)}
assert auto <= {-1, -9, 7}
def test_t_values() -> None:
assert [gold_t(n) for n in range(3, 11)] == [5, 9, 9, 17, 17, 33, 33, 65]
References
- Robert Gold, Optimal binary sequences for spread spectrum multiplexing, IEEE Transactions on Information Theory 13(4), 1967, pp. 619 to 621 (the sum of a preferred pair of maximal-length sequences and the three-valued cross-correlation bound t(n))
- Dilip V. Sarwate and Michael B. Pursley, Crosscorrelation properties of pseudorandom and related sequences, Proceedings of the IEEE 68(5), 1980, pp. 593 to 619 (the sections on the cross-correlation of m-sequences, preferred pairs and Gold sequences)
- Kai Borre, Dennis M. Akos, Nicolaj Bertelsen, Peter Rinder and Søren Holdt Jensen, A Software-Defined GPS and Galileo Receiver, a Single-Frequency Approach, Birkhäuser, 2007, The chapter on the GPS signal (the C/A codes as Gold codes from two 10-cell shift registers)
Where this leads
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 | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag BGG18W Edit this page History Report an error Markdown