Algorithm Search⌘K

Definitionadvanced

Kasami sequences

Also called Kasami codes.

Binary sequence families from an m-sequence and its decimations. The small set has 2^(n/2) sequences of period 2^n - 1 and largest correlation 1 + 2^(n/2), the least possible for binary sequences.

Kasami sequences are binary sequence families of period N=2n−1N = 2^n - 1, for even nn, made by adding an m-sequence uu to the shifts of one or two decimations of uu. The small set has 2n/22^{n/2} sequences, and every off-peak autocorrelation and every cross-correlation in it takes one of the three values −1-1, −1−2n/2-1 - 2^{n/2} and −1+2n/2-1 + 2^{n/2}, so the largest magnitude is 1+2n/21 + 2^{n/2}, about N\sqrt N. The large set, for n≡2(mod4)n \equiv 2 \pmod 4, contains a Gold family and many more sequences, with the Gold bound t(n)t(n) as its largest correlation. The small set is optimal for binary sequences in the sense of Sarwate and Pursley 1980: the Welch bound and the fact that binary correlations of odd length are odd integers force θmax⁡≥1+2n/2\theta_{\max} \ge 1 + 2^{n/2} for any 2n/22^{n/2} binary sequences of period NN, and the small set reaches that value. It does not meet the real-valued Welch bound with equality. The construction comes from Kasami's 1966 report on the weight distributions of some cyclic codes.

Definition

Use the notation of the Gold sequences page: bit sequences of period NN, the shift TτsT^\tau s, the decimation s[q]=(sqk mod N)ks[q] = (s_{qk \bmod N})_k, the periodic correlation θa,b(τ)=∑k(−1)ak⊕bk+τ\theta_{a,b}(\tau) = \sum_k (-1)^{a_k \oplus b_{k+\tau}} and the figure of merit θmax⁡\theta_{\max} over all pairs and shifts except the peaks.

Small set. Let nn be even, uu an m-sequence of degree nn and period N=2n−1N = 2^n - 1, and s(n)=2n/2+1s(n) = 2^{n/2} + 1. The decimation w=u[s(n)]w = u[s(n)] is not an m-sequence of degree nn: since s(n)s(n) divides N=(2n/2−1)(2n/2+1)N = (2^{n/2} - 1)(2^{n/2} + 1), ww has period 2n/2−12^{n/2} - 1, and it is an m-sequence of degree n/2n/2 repeated 2n/2+12^{n/2} + 1 times. The small Kasami set is

KS(u)={u}∪{u⊕Tτw:τ=0,1,…,2n/2−2},\mathcal{K}_S(u) = \{u\} \cup \{u \oplus T^\tau w : \tau = 0, 1, \ldots, 2^{n/2} - 2\},

with 2n/22^{n/2} sequences of period NN. Every off-peak autocorrelation and every cross-correlation of KS\mathcal{K}_S takes a value in {−1, −1−2n/2, −1+2n/2}\{-1, \ -1 - 2^{n/2}, \ -1 + 2^{n/2}\}, so θmax⁡=1+2n/2\theta_{\max} = 1 + 2^{n/2} (Sarwate and Pursley 1980, the section on Kasami sequences). Each member satisfies a linear recurrence of degree 3n/23n/2, the product of the polynomials of uu and ww.

Large set. For n≡2(mod4)n \equiv 2 \pmod 4, let v=u[t(n)]v = u[t(n)] with t(n)=1+2(n+2)/2t(n) = 1 + 2^{(n+2)/2}, so that (u,v)(u, v) is a preferred pair, and w=u[s(n)]w = u[s(n)] as above. The large set is the Gold family G(u,v)\mathcal{G}(u, v) together with the sums u⊕Tiv⊕Tjwu \oplus T^i v \oplus T^j w, u⊕Tjwu \oplus T^j w and v⊕Tjwv \oplus T^j w for 0≤i<N0 \le i < N and 0≤j<2n/2−10 \le j < 2^{n/2} - 1. It has 2n/2(2n+1)2^{n/2}(2^n + 1) sequences, and its correlations take values in {−1, −1±2n/2, −1±2(n+2)/2}\{-1, \ -1 \pm 2^{n/2}, \ -1 \pm 2^{(n+2)/2}\}, so θmax⁡=t(n)\theta_{\max} = t(n), the same as the Gold family it contains (Sarwate and Pursley 1980).

Optimality of the small set. Let M=2n/2M = 2^{n/2}, so N=M2−1N = M^2 - 1. The sequence form of the Welch bound says that MM sequences of length NN and energy NN have θmax⁡≥B=N(M−1)/(MN−1)\theta_{\max} \ge B = N \sqrt{(M-1)/(MN-1)}. Then B>M−1B > M - 1: squaring and dividing by M−1M - 1, this is (M−1)(M+1)2>M3−M−1(M-1)(M+1)^2 > M^3 - M - 1, which reduces to M2>0M^2 > 0. A correlation of two ±1\pm 1 sequences of odd length NN is NN minus twice a count, so it is odd. The odd numbers above M−1M - 1 start at M+1M + 1, so every binary family of MM sequences of period NN has θmax⁡≥M+1=1+2n/2\theta_{\max} \ge M + 1 = 1 + 2^{n/2}, and the small Kasami set meets this. The real bound BB itself is strictly smaller than M+1M + 1.

  1. KASAMI-SMALL(u) ▷ u an m-sequence of even degree n, N = 2^n - 1
  2. 1w ← u[2^{n/2} + 1] ▷ decimation: w[k] = u[(2^{n/2} + 1) k mod N]
  3. 2F ← [u]
  4. 3for τ ← 0 to 2^{n/2} - 2 do
  5. 4append u ⊕ T^τ w to F
  6. return F
  7. THETA-MAX(F)
  8. 5return the largest |θ_{a,b}(τ)| over a, b in F and τ, except a = b with τ = 0

The construction costs O(N 2n/2)O(N \, 2^{n/2}) bit operations in the word RAM model, and the direct check of θmax⁡\theta_{\max} costs O(2nN2)O(2^n N^2).

Examples and non-examples

Degree 4. With uu from x4+x+1x^4 + x + 1 (100010011010111100010011010111) and s(4)=5s(4) = 5, the decimation w=u[5]w = u[5] has period 33. The small set has 44 sequences of period 1515. Over all ordered pairs and shifts except the peaks, the correlation is −5-5 in 6868 cases, −1-1 in 5656 cases and 33 in 112112 cases. So θmax⁡=5=1+22\theta_{\max} = 5 = 1 + 2^2. The Welch bound for M=4M = 4 and N=15N = 15 is 153/59=3.3815 \sqrt{3/59} = 3.38; the least odd integer at or above it is 55.

Degree 6. With uu from x6+x+1x^6 + x + 1, w=u[9]w = u[9] has period 77. The small set has 88 sequences of period 6363, with correlation values −9-9, −1-1 and 77 and θmax⁡=9\theta_{\max} = 9. The Welch bound is 637/503=7.4363 \sqrt{7/503} = 7.43, so 99 is the least possible odd value. A Gold family of degree 6 has 6565 sequences and θmax⁡=17\theta_{\max} = 17. The small Kasami set trades 5757 sequences for half the largest correlation.

Degree 8. With uu from x8+x4+x3+x2+1x^8 + x^4 + x^3 + x^2 + 1, the small set has 1616 sequences of period 255255 and θmax⁡=17\theta_{\max} = 17, against a Welch bound of 15.4615.46. The ratio of θmax⁡\theta_{\max} to the bound is 1.481.48, 1.211.21 and 1.101.10 for n=4n = 4, 66 and 88; it goes to 11 as nn grows.

Large set, degree 6. With v=u[17]v = u[17] and w=u[9]w = u[9], the large set has 8⋅65=5208 \cdot 65 = 520 sequences of period 6363, and its correlations lie in {−17,−9,−1,7,15}\{-17, -9, -1, 7, 15\}, so θmax⁡=17=t(6)\theta_{\max} = 17 = t(6).

Non-example: odd nn. For odd nn, 2n/22^{n/2} is not an integer and 2n−12^n - 1 has no factor 2n/2+12^{n/2} + 1. The small set does not exist; use a Gold family.

Non-example: decimating by a number coprime to NN. If gcd⁡(q,N)=1\gcd(q, N) = 1, then u[q]u[q] is again an m-sequence of period NN, not a short sequence, and adding it to uu gives a Gold-like family only for the preferred values of qq. The Kasami step needs the short period that comes from gcd⁡(s(n),N)=s(n)\gcd(s(n), N) = s(n).

  • Gold sequences have about 2n2^n sequences and θmax⁡\theta_{\max} near 2N\sqrt{2N} or 2N2\sqrt N. The small Kasami set has about N\sqrt N sequences and θmax⁡\theta_{\max} near N\sqrt N. The large Kasami set has about N3/2N^{3/2} sequences with the Gold value of θmax⁡\theta_{\max}.
  • The Welch bound is the reference for optimality. Complex sequence families, such as sets of Zadoff-Chu sequences of prime length, can do better than any binary family.
  • The sums a⊕Tτba \oplus T^\tau b of members of the small set lie in the cyclic code of length NN and dimension 3n/23n/2 spanned by the shifts of uu and ww. A correlation value θ\theta belongs to a codeword of weight (N−θ)/2(N - \theta)/2, so the three values correspond to the three nonzero weights 2n−12^{n-1} and 2n−1±2n/2−12^{n-1} \pm 2^{n/2 - 1}. Kasami's 1966 report found the weight distributions of this class of cyclic codes.
  • Code-division multiple access uses such families as user signatures. IS-95, for example, uses long m-sequences and Walsh codes instead.

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.

kasami_sequences.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/kasami-sequences/. The authors are listed in prov/H5NT6J.jsonl.

"""The small set of Kasami sequences, with integer correlations.

A polynomial over GF(2) is the list of its exponents, for example [6, 1, 0]
for x^6 + x + 1. For even n, let u be an m-sequence of period N = 2^n - 1 and
w = u decimated by s = 2^(n/2) + 1, which has period 2^(n/2) - 1. The small
Kasami set is u together with u XOR (w shifted by t) for
t = 0, ..., 2^(n/2) - 2: 2^(n/2) sequences of period N.
"""

import math


def mseq(exps: list[int], state: list[int] | None = None) -> list[int]:
    """One period of the recurrence s[k + n] = XOR over the exponents i < n of s[k + i]."""
    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 least_period(s: list[int]) -> int:
    """The least p > 0 with s[k] = s[(k + p) mod N] for all k."""
    n = len(s)
    for p in range(1, n + 1):
        if n % p == 0 and all(s[k] == s[(k + p) % n] for k in range(n)):
            return p
    return n


def kasami_small(u: list[int]) -> list[list[int]]:
    """The small Kasami set of an m-sequence u of even degree n (as bit lists)."""
    big = len(u)
    n = (big + 1).bit_length() - 1
    if (1 << n) - 1 != big or n % 2:
        raise ValueError("u must have period 2^n - 1 with n even")
    s = (1 << (n // 2)) + 1
    w = decimate(u, s)  # @line L1
    fam = [list(u)]  # @line L2
    for t in range((1 << (n // 2)) - 1):  # @line L3
        fam.append([u[k] ^ w[(k + t) % big] for k in range(big)])  # @line L4
    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])."""
    n = len(a)
    return n - 2 * sum(a[k] ^ b[(k + t) % n] for k in range(n))


def max_correlation(fam: list[list[int]]) -> int:
    """theta_max over all pairs and shifts, except the peaks of a sequence with itself at shift 0."""
    best = 0
    for i, a in enumerate(fam):
        for j in range(i, len(fam)):
            for t in range(len(a)):
                if i == j and t == 0:
                    continue
                best = max(best, abs(xcorr(a, fam[j], t)))  # @line L5
    return best


def welch_sequence_bound(m: int, n: int) -> float:
    """The Welch bound N sqrt((M - 1) / (M N - 1)) on theta_max for M sequences of length N and energy N."""
    return n * math.sqrt((m - 1) / (m * n - 1))
test_kasami_sequences.py 70 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/kasami-sequences/. The authors are listed in prov/H5NT6J.jsonl.

import math

from kasami_sequences import decimate, kasami_small, least_period, max_correlation, mseq, welch_sequence_bound, xcorr

PRIMITIVE = {4: [4, 1, 0], 6: [6, 1, 0], 8: [8, 4, 3, 2, 0]}


def brute_xcorr(a: list[int], b: list[int], t: int) -> int:
    n = len(a)
    return sum((1 - 2 * a[k]) * (1 - 2 * b[(k + t) % n]) for k in range(n))


def all_values(fam: list[list[int]]) -> set[int]:
    out = set()
    for i, a in enumerate(fam):
        for j, b in enumerate(fam):
            for t in range(len(a)):
                if i != j or t != 0:
                    out.add(xcorr(a, b, t))
    return out


def test_xcorr_against_plus_minus_one_sum() -> None:
    fam = kasami_small(mseq(PRIMITIVE[4]))
    for a in fam:
        for b in fam:
            for t in range(15):
                assert xcorr(a, b, t) == brute_xcorr(a, b, t)


def test_decimated_sequence_has_short_period() -> None:
    for n, f in PRIMITIVE.items():
        w = decimate(mseq(f), (1 << (n // 2)) + 1)
        assert least_period(w) == (1 << (n // 2)) - 1


def test_three_values_and_bound() -> None:
    for n in (4, 6):
        fam = kasami_small(mseq(PRIMITIVE[n]))
        half = 1 << (n // 2)
        assert len(fam) == half
        assert len({tuple(s) for s in fam}) == half
        assert all_values(fam) == {-1, -1 - half, -1 + half}
        assert max_correlation(fam) == 1 + half


def test_degree_eight_bound() -> None:
    fam = kasami_small(mseq(PRIMITIVE[8]))
    assert len(fam) == 16 and max_correlation(fam) == 17


def test_optimal_against_welch_for_binary_sequences() -> None:
    # Correlations of binary sequences of odd length are odd integers, so
    # theta_max >= the least odd integer at or above the Welch bound.
    for n in (4, 6, 8, 10, 12):
        big = (1 << n) - 1
        m = 1 << (n // 2)
        w = welch_sequence_bound(m, big)
        least_odd = math.ceil(w)
        if least_odd % 2 == 0:
            least_odd += 1
        assert least_odd == 1 + m
        assert w < 1 + m  # the bound itself is not met with equality


def test_check_values_degree_six() -> None:
    assert abs(welch_sequence_bound(8, 63) - 7.431998) < 1e-6

References

  1. Tadao Kasami, Weight Distribution Formula for Some Class of Cyclic Codes, Coordinated Science Laboratory, University of Illinois, Report R-285, April 1966 (doi:10.21236/ad0632574), The whole report (the weight distribution of the cyclic codes whose codewords give the Kasami sequences)
  2. 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 small and the large sets of Kasami sequences and their comparison with the Welch bound)
  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 the small Kasami set is compared with)

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/H5NT6J/text.yaml