Algorithm Search⌘K

Algorithmadvanced

Optimum multiuser detector

Also called Verdu detector, jointly optimum multiuser detector.

The maximum likelihood detector of the bits of all CDMA users: a matched filter bank and a Viterbi search over 2^(K-1) states, exponential in the number of users K.

Time
O(M K^2 (2^K + N)) worst
Space
O(2^K K M) extra
Where
K = the number of users; M = the number of symbols per user; N = the number of chips per symbol
Properties
deterministicexponential in usershandles asynchronous usersmaximum likelihoodneeds amplitudesnot needs noise level
Origin
Sergio Verdú, 1986

The optimum multiuser detector decides the bits of all users of a CDMA channel jointly, by maximum likelihood. It is the best possible answer to the multiuser detection problem: no other detector has a smaller probability of deciding a wrong frame, and it is fully resistant to the near-far problem. Verdú found its structure in 1983 to 1986. A bank of matched filters, one per user, gives sufficient statistics, and a Viterbi algorithm with 2K−12^{K-1} states searches the bit sequences of the KK users. The cost per bit is exponential in KK. This is not a weakness of the method: the problem itself is NP-hard in KK. The detector is the reference against which the cheaper detectors are measured: the decorrelator, the MMSE detector, successive and parallel interference cancellation.

In plain words

Several users send at the same time on the same band, each with its own spreading code. Their signals add up at the receiver, with noise. The optimum detector asks: of all the bit patterns the users could have sent, which one makes a received signal closest to what arrived? Checking every pattern is far too slow for long frames, but each bit overlaps only a few bits of the other users. So the detector works through the bits in time order and keeps, for each pattern of the last few bits, only the best history that ends in it. This is the Viterbi algorithm. The number of patterns it keeps doubles with each extra user, so the method is practical only for a small number of users.

The problem

User k=1,…,Kk = 1, \ldots, K sends bits bk[0],…,bk[M−1]∈{−1,+1}b_k[0], \ldots, b_k[M-1] \in \{-1, +1\} with amplitude Ak>0A_k > 0 and a signature sks_k of NN chips with ∥sk∥=1\|s_k\| = 1. The user starts τk\tau_k chips late, 0≤τk<N0 \le \tau_k < N. The receiver sees the chip samples

y[n]=∑kAk∑ibk[i] sk[n−iN−τk]+w[n],y[n] = \sum_{k} A_k \sum_{i} b_k[i]\, s_k[n - iN - \tau_k] + w[n],

with w[n]w[n] independent N(0,σ2)\mathcal{N}(0, \sigma^2). This is the in-phase part of the complex baseband model for coherent BPSK, with σ2=N0/2\sigma^2 = N_0/2, so Ak2/σ2=2Eb/N0A_k^2 / \sigma^2 = 2 E_b / N_0 for user kk. The receiver knows the signatures, the delays and the amplitudes. The output is the frame bb that maximizes the likelihood, which is the frame that minimizes ∥y−∑kAk∑ibk[i] sk[⋅−iN−τk]∥2\|y - \sum_k A_k \sum_i b_k[i]\, s_k[\cdot - iN - \tau_k]\|^2. With all delays 0, one interval is the synchronous model y=SAb+wy = S A b + w: the frame maximizes 2b⊤Az−b⊤ARAb2 b^\top A z - b^\top A R A b, where z=S⊤yz = S^\top y and R=S⊤SR = S^\top S.

The algorithm

Sort the KMKM bits by their first chip and call them t=0,1,…,KM−1t = 0, 1, \ldots, KM - 1. Write ata_t for the amplitude of bit tt, utu_t for its shifted signature, zt=⟨ut,y⟩z_t = \langle u_t, y \rangle for its matched filter output, and ρt,v=⟨ut,uv⟩\rho_{t,v} = \langle u_t, u_v \rangle. A bit overlaps only the K−1K - 1 bits before it and the K−1K - 1 bits after it, so the log-likelihood is a sum of terms that each depend on one bit and the K−1K - 1 bits before it.

  1. OPTIMUM-MUD(y, s, τ, A, M)
  2. 1sort the K M bits by their first chip i N + τ_k
  3. 2for each bit t: z_t ← ⟨u_t, y⟩ and ρ_{t,t-d} ← ⟨u_t, u_{t-d}⟩ for 1 ≤ d ≤ min(t, K - 1)
  4. 3metric[empty state] ← 0
  5. 4for t ← 0 to K M - 1
  6. 5for each state σ = (b_{t-1}, .., b_{t-min(t,K-1)}) and each b_t ∈ {+1, -1}
  7. 6λ ← 2 a_t b_t (z_t - Σ_d a_{t-d} b_{t-d} ρ_{t,t-d}) ▷ the branch metric
  8. 7candidate for the state σ' = (b_t, .., b_{t-K+2}) is metric[σ] + λ
  9. 8metric[σ'] ← the best candidate of σ', and its survivor ← the survivor of that σ, then b_t
  10. 9return the survivor of the state with the largest metric

Line L1 puts the bits in time order; for synchronous users with M=1M = 1 this is just the user order. Line L2 is the matched filter bank and the correlations of overlapping bits. Line L6 is the gain in likelihood from deciding btb_t, given the bits that overlap it from the left. Lines L7 and L8 are the add-compare-select step of the Viterbi algorithm on a trellis whose state is the last K−1K - 1 bits, so there are 2K−12^{K-1} states after the first K−1K - 1 bits. Line L9 picks the best final state and returns its history, which is put back as bk[i]b_k[i] by user and symbol.

Example

Three synchronous users with N=8N = 8 chips use the signatures s1=(1,1,1,1,1,1,1,1)/8s_1 = (1,1,1,1,1,1,1,1)/\sqrt 8, s2=(1,1,1,1,1,1,−1,−1)/8s_2 = (1,1,1,1,1,1,-1,-1)/\sqrt 8 and s3=(1,−1,1,−1,1,−1,1,1)/8s_3 = (1,-1,1,-1,1,-1,1,1)/\sqrt 8, so R12=0.5R_{12} = 0.5, R13=0.25R_{13} = 0.25 and R23=−0.25R_{23} = -0.25. The amplitudes are A=(1,4,2)A = (1, 4, 2) and the bits sent are b=(+1,−1,+1)b = (+1, -1, +1). Without noise the matched filters give z=RAb=(−0.5,−4,3.25)z = R A b = (-0.5, -4, 3.25); user 1 has the wrong sign, because user 2 is four times stronger. With noise of σ=0.5\sigma = 0.5, one draw gave z=(−0.47,−4.21,2.18)z = (-0.47, -4.21, 2.18). The table lists the metric Ω(b)=2b⊤Az−b⊤ARAb\Omega(b) = 2 b^\top A z - b^\top A R A b of every candidate.

b1b_1 b2b_2 b3b_3 Ω(b)\Omega(b)
+1 +1 +1 -47.90
+1 +1 -1 -71.34
+1 -1 +1 19.46
+1 -1 -1 12.02
-1 +1 +1 -36.02
-1 +1 -1 -63.46
-1 -1 +1 15.34
-1 -1 -1 3.90

The largest metric, 19.46, belongs to the sent bits (+1,−1,+1)(+1, -1, +1). The signs of zz give (−1,−1,+1)(-1, -1, +1), with the metric 15.34, so the conventional receiver gets user 1 wrong. The trellis of lines L4 to L8 has three steps here. After the last step it keeps 4 states, one for each value of (b2,b3)(b_2, b_3), and each holds the better of the two rows that differ only in b1b_1. The best of the four is the row in bold.

Correctness

Claim. The detector returns a frame that maximizes the likelihood of yy over all 2KM2^{KM} frames.

Key step. If two bits are KK or more places apart in time order, they start at least NN chips apart, because each user has at most one bit starting in any window of NN chips. So their waveforms do not overlap, and −∥y−signal∥2-\|y - \text{signal}\|^2 is a constant plus ∑tλt\sum_t \lambda_t, where λt\lambda_t depends only on btb_t and the K−1K - 1 bits before it. The Viterbi invariant then holds: after step tt, each state stores the best partial sum over all histories that end in it. The full proof is in the proofs folder.

Proof: The Viterbi search over 2^(K-1) states returns the bit sequences of maximum likelihoodfull

The receiver sees y[n]=∑tatbt ut[n]+w[n]y[n] = \sum_{t} a_t b_t\, u_t[n] + w[n], with w[n]w[n] independent N(0,σ2)\mathcal{N}(0, \sigma^2). Here t=0,…,T−1t = 0, \ldots, T - 1 runs over the T=KMT = KM bits in the order of line L1, at>0a_t > 0 is the amplitude of the user of bit tt, bt∈{−1,+1}b_t \in \{-1, +1\}, and ut[n]=sk[n−stt]u_t[n] = s_k[n - \mathrm{st}_t] is the signature of that user shifted to the start chip stt=iN+τk\mathrm{st}_t = iN + \tau_k of the bit. Each signature has ∥sk∥=1\|s_k\| = 1 and each delay satisfies 0≤τk<N0 \le \tau_k < N. Line L1 sorts the bits by start chip, so st0≤st1≤⋯≤stT−1\mathrm{st}_0 \le \mathrm{st}_1 \le \cdots \le \mathrm{st}_{T-1}. Line L2 computes zt=⟨ut,y⟩z_t = \langle u_t, y \rangle and ρt,t−d=⟨ut,ut−d⟩\rho_{t,t-d} = \langle u_t, u_{t-d} \rangle for 1≤d≤min⁡(t,K−1)1 \le d \le \min(t, K - 1).

Lemma 1 (each bit overlaps at most K−1K - 1 bits on each side). If v−t≥Kv - t \ge K, then stv−stt≥N\mathrm{st}_v - \mathrm{st}_t \ge N, and so ⟨ut,uv⟩=0\langle u_t, u_v \rangle = 0.

Proof. Suppose stv−stt<N\mathrm{st}_v - \mathrm{st}_t < N. The v−t+1≥K+1v - t + 1 \ge K + 1 bits t,t+1,…,vt, t+1, \ldots, v all start in the half-open interval [stt,stt+N)[\mathrm{st}_t, \mathrm{st}_t + N). The start chips of one user are τk,τk+N,τk+2N,…\tau_k, \tau_k + N, \tau_k + 2N, \ldots, so at most one of them lies in a half-open interval of length NN. There are only KK users, so at most KK bits start in the interval, a contradiction. The support of utu_t is [stt,stt+N)[\mathrm{st}_t, \mathrm{st}_t + N), so two waveforms whose start chips differ by NN or more do not overlap. □\square

Lemma 2 (the log-likelihood is a sum of branch metrics). Let Λ(b)=−∥y−∑tatbtut∥2\Lambda(b) = -\|y - \sum_t a_t b_t u_t\|^2. Then

Λ(b)=−∥y∥2−∑tat2+∑t=0T−1λt,λt=2atbt(zt−∑d=1min⁡(t,K−1)at−d bt−d ρt,t−d).(1)\Lambda(b) = -\|y\|^2 - \sum_t a_t^2 + \sum_{t=0}^{T-1} \lambda_t, \qquad \lambda_t = 2 a_t b_t \Big( z_t - \sum_{d=1}^{\min(t, K-1)} a_{t-d}\, b_{t-d}\, \rho_{t,t-d} \Big). \tag{1}

Proof. Expand the square: ∥∑tatbtut∥2=∑tat2bt2∥ut∥2+2∑t>vatavbtbv⟨ut,uv⟩\|\sum_t a_t b_t u_t\|^2 = \sum_t a_t^2 b_t^2 \|u_t\|^2 + 2 \sum_{t > v} a_t a_v b_t b_v \langle u_t, u_v \rangle. Here bt2=1b_t^2 = 1 and ∥ut∥=1\|u_t\| = 1, because the shift keeps all NN chips inside the frame. By Lemma 1 the cross terms vanish unless t−v≤K−1t - v \le K - 1, so we write v=t−dv = t - d with 1≤d≤min⁡(t,K−1)1 \le d \le \min(t, K - 1). The linear term is 2∑tatbt⟨ut,y⟩=2∑tatbtzt2 \sum_t a_t b_t \langle u_t, y \rangle = 2 \sum_t a_t b_t z_t. Collecting the terms of each tt gives (1). □\square

The first two terms of (1) do not depend on bb. The noise is white and Gaussian, so the likelihood of yy given bb is proportional to exp⁡(Λ(b)/(2σ2))\exp(\Lambda(b) / (2\sigma^2)). A sequence that maximizes ∑tλt\sum_t \lambda_t therefore maximizes the likelihood. With independent, equally likely bits, it is also the sequence with the largest posterior probability, so it minimizes the probability that the decided frame differs from the sent frame. Line L6 computes λt\lambda_t exactly as in (1).

Lemma 3 (the Viterbi invariant). A state is a tuple of the last min⁡(t,K−1)\min(t, K - 1) bits, the most recent last. At the start of iteration tt of line L4, for every state σ\sigma in metric, metric[σ]=max⁡∑v<tλv\mathrm{metric}[\sigma] = \max \sum_{v < t} \lambda_v over all bit sequences b0,…,bt−1b_0, \ldots, b_{t-1} whose last bits are σ\sigma, and survivor[σ] is one such sequence that attains the maximum. Every possible tuple of length min⁡(t,K−1)\min(t, K-1) is a key of metric.

Proof. By induction on tt. For t=0t = 0, line L3 sets the empty state to 0, and the empty sum is 0. Assume the claim at the start of iteration tt. By (1), λt\lambda_t depends only on btb_t and on bt−1,…,bt−min⁡(t,K−1)b_{t-1}, \ldots, b_{t - \min(t, K-1)}, which are exactly the bits in the state σ\sigma. So line L6 evaluates λt(σ,bt)\lambda_t(\sigma, b_t) correctly from σ\sigma alone. A sequence b0,…,btb_0, \ldots, b_t ends in the new state σ′\sigma', the last min⁡(t+1,K−1)\min(t + 1, K - 1) bits, if and only if it is a sequence b0,…,bt−1b_0, \ldots, b_{t-1} ending in some state σ\sigma followed by a bit btb_t, with σ′\sigma' the tail of σ\sigma followed by btb_t. Its value is ∑v<tλv+λt(σ,bt)\sum_{v < t} \lambda_v + \lambda_t(\sigma, b_t). For a fixed σ\sigma and btb_t, the first sum is largest for the survivor of σ\sigma, by the induction hypothesis. Lines L5 to L7 try every pair (σ,bt)(\sigma, b_t) and keep, for each σ′\sigma', the largest value and the sequence that reaches it, so line L8 stores the maximum over all sequences that end in σ′\sigma'. Every tuple σ′\sigma' is reached, because every σ\sigma is present and both values of btb_t are tried. □\square

Theorem 1. The output of the detector maximizes Λ(b)\Lambda(b) over all 2KM2^{KM} frames. It is a jointly maximum likelihood decision.

Proof. After the last iteration, Lemma 3 with t=Tt = T says that each metric[σ] is the best total over the sequences ending in σ\sigma, and every sequence ends in some state. Line L9 takes the best state, so its survivor maximizes ∑tλt\sum_t \lambda_t over all sequences, and by (1) it maximizes Λ\Lambda. The final loop only moves each bit tt back to its user and symbol index. □\square

Corollary (the synchronous case). With all delays 0 and M=1M = 1, the bits are the KK users of one interval and every pair overlaps. The detector maximizes 2b⊤Az−b⊤ARAb2 b^\top A z - b^\top A R A b, with z=S⊤yz = S^\top y and R=S⊤SR = S^\top S, over b∈{−1,+1}Kb \in \{-1, +1\}^K. This is (1) with T=KT = K and all (K2)\binom{K}{2} cross terms present.

Remark (no noise). If w=0w = 0, the sent frame has Λ=0\Lambda = 0, the largest possible value. Any other frame with Λ=0\Lambda = 0 would give the same noiseless signal. If the shifted signatures utu_t are linearly independent, no such frame exists and the detector returns the sent frame. If they are dependent, two frames can give the same signal, and no detector can tell them apart.

Remark (the cost). Iteration tt visits 2min⁡(t,K−1)2^{\min(t, K-1)} states. For each it computes a sum of at most K−1K - 1 terms and two branches, so the search costs O(TK2K)=O(MK22K)O(T K 2^{K}) = O(M K^2 2^K) operations. Line L2 costs O(TKN)O(T K N). The interference sums of all 2K−12^{K-1} states can instead be built one bit at a time: the sum over the last jj bits is the sum over the last j−1j - 1 bits plus one term, so all of them cost 2+4+⋯+2K−1<2K2 + 4 + \cdots + 2^{K-1} < 2^K additions. With this table the cost per bit is O(2K)O(2^K), the figure in Verdú's 1986 paper. The number of states, 2K−12^{K-1}, is the same in both forms.

Complexity

Line L2 costs O(KN)O(K N) per bit, O(MK2N)O(M K^2 N) in all. The search visits at most 2K−12^{K-1} states per bit with two branches each, and the interference sum of line L6 has at most K−1K - 1 terms, so it costs O(K2K)O(K 2^K) per bit and O(MK22K)O(M K^2 2^K) in all in the real RAM. Building the interference sums of all states one bit at a time removes the factor KK and gives the O(2K)O(2^K) per bit of Verdú's paper. The survivors need O(2KKM)O(2^K K M) space, or O(2KD)O(2^K D) with a fixed decision depth DD. For one synchronous interval the search is a brute force over 2K2^K vectors in disguise, and no polynomial algorithm is expected, because the problem is NP-hard.

Properties

  • Optimal for the frame. It minimizes the probability that the decided frame differs from the sent frame, for equally likely bits. The individually optimum detector, which minimizes the error probability of each bit, uses posterior probabilities instead of a maximum; at high SNR the two behave the same.
  • Near-far resistant. Its asymptotic efficiency stays positive however strong the other users are, as long as the signatures are linearly independent. Lupas and Verdú showed that the decorrelator has the same near-far resistance.
  • Needs the amplitudes. The branch metric uses AkA_k; the noise level σ\sigma is not needed for the maximum likelihood frame.
  • Exponential in KK, linear in MM. The trellis has 2K−12^{K-1} states whatever the frame length.
  • Error rate. At high SNR, each user's error rate is close to Q(dmin⁡,k/(2σ))Q(d_{\min,k} / (2 \sigma)) up to a constant factor, where dmin⁡,kd_{\min,k} is the smallest distance between two noiseless signals whose bits of user kk differ.

Variants and improvements

  • Individually optimum detection. Replace max by sum in the trellis (the BCJR algorithm) to get the posterior probability of each bit; this gives the minimum bit error rate and soft outputs for a decoder.
  • Sphere decoding. For the synchronous case, write ∥y−SAb∥2\|y - S A b\|^2 with a Cholesky factor of RR and search the binary vectors with Fincke-Pohst or Schnorr-Euchner enumeration. The answer is still exact, and the average cost is much lower at high SNR.
  • Relaxations. Semidefinite relaxation solves a convex problem and rounds; it is polynomial and often close to optimal.
  • Polynomial special cases. When all crosscorrelations are nonpositive, the synchronous problem reduces to a minimum cut and is solvable in polynomial time (Sankaran and Ephremides 1998).
  • Reduced-state trellis. Keep only the best few states per step, or cancel the far bits with decisions, as in reduced-state sequence estimation.

When to use it

Use it when KK is small, about ten users or fewer, and the signatures and amplitudes are known: as a benchmark in simulations, in a receiver for a few strong users, or as the inner step of an iterative receiver for a small group. For large KK use the MMSE detector, interference cancellation or a sphere decoder.

Pitfalls

  • Wrong amplitudes or delays. The metric uses AkA_k, τk\tau_k and the signatures. Errors in these parameters break the optimality, and the result can be worse than a linear detector.
  • Forgetting the edges of the frame. In the asynchronous case the first and last bits overlap fewer bits. The trellis must start with an empty state and grow, as here, not with 2K−12^{K-1} equal states.
  • Delays not in 0,…,N−10, \ldots, N-1. A delay of NN or more shifts the symbol index. Reduce delays modulo NN and renumber the symbols, or the overlap argument fails.
  • Expecting it to scale. The cost doubles with each user. For K=30K = 30 there are about 5×1085 \times 10^8 states per bit.

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.

constel.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the communications pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Constellations, Gray labels and brute-force maximum likelihood detection.

Each constellation function returns a list of M complex points with unit
average energy, ordered by label: points[i] is the point whose bit label is
the integer i, and bits(i, log2 M) gives that label, most significant bit
first. The labels follow the communications area rules:

- M-PAM: the point with amplitude index m = 0, ..., M-1 (raw amplitude
  M - 1 - 2m, from the most positive) gets the Gray label gray(m).
  So 2-PAM maps bit 0 to +1 and bit 1 to -1.
- Square M-QAM, M = 4^k: the label is the in-phase PAM label followed by the
  quadrature PAM label, each of log2(sqrt(M)) bits.
- M-PSK: the point e^(j(2 pi m / M + phase0)) gets the label gray(m).

PAM points are returned as complex numbers with zero imaginary part.
This file imports nothing from cbb.py. It holds no demapper: soft and
max-log demapping are algorithm pages of their own.
"""

import cmath
import itertools
import math


def gray(n: int) -> int:
    """The binary reflected Gray code of n: n XOR (n >> 1)."""
    return n ^ (n >> 1)


def _gray_inv(g: int) -> int:
    n = 0
    while g:
        n ^= g
        g >>= 1
    return n


def bits(i: int, m: int) -> list[int]:
    """The m bits of the integer i, most significant bit first."""
    if i < 0 or i >= 1 << m:
        raise ValueError("i does not fit in m bits")
    return [(i >> (m - 1 - t)) & 1 for t in range(m)]


def _log2(m: int) -> int:
    if m < 2 or m & (m - 1):
        raise ValueError("M must be a power of two, at least 2")
    return m.bit_length() - 1


def pam(m: int) -> list[complex]:
    """Unit-energy M-PAM, ordered by Gray label."""
    _log2(m)
    s = math.sqrt((m * m - 1) / 3.0)
    return [complex((m - 1 - 2 * _gray_inv(lab)) / s, 0.0) for lab in range(m)]


def qam(m: int) -> list[complex]:
    """Unit-energy square M-QAM (M = 4, 16, 64, ...), ordered by label (in-phase bits first)."""
    k = _log2(m)
    if k % 2:
        raise ValueError("square QAM needs M = 4^k")
    side = 1 << (k // 2)
    s = math.sqrt(2.0 * (m - 1) / 3.0)
    raw = [side - 1 - 2 * _gray_inv(lab) for lab in range(side)]
    return [complex(raw[lab // side], raw[lab % side]) / s for lab in range(m)]


def psk(m: int, phase0: float = 0.0) -> list[complex]:
    """Unit-energy M-PSK with first point at angle phase0, ordered by Gray label."""
    _log2(m)
    return [cmath.exp(1j * (2.0 * math.pi * _gray_inv(lab) / m + phase0)) for lab in range(m)]


def energy(points: list[complex]) -> float:
    """The average energy (1/M) sum |p|^2 of equally likely points."""
    return sum(abs(p) ** 2 for p in points) / len(points)


def ml_detect(y: complex, points: list[complex], h: complex = 1) -> int:
    """The index of the point p that minimizes |y - h p|^2, by brute force (lowest index on a tie)."""
    best, arg = math.inf, -1
    for i, p in enumerate(points):
        d = abs(y - h * p) ** 2
        if d < best:
            best, arg = d, i
    return arg


def ml_vector(y: list[complex], h: list[list[complex]], points: list[complex]) -> list[int]:
    """The index vector that minimizes ||y - H x||^2 over all M^n vectors x, by brute force.

    h is the m by n channel matrix as a list of rows; the result has n indices.
    The first minimizer in lexicographic order of the indices wins a tie.
    """
    n = len(h[0])
    best, arg = math.inf, None
    for idx in itertools.product(range(len(points)), repeat=n):
        x = [points[i] for i in idx]
        d = 0.0
        for yi, row in zip(y, h):
            d += abs(yi - sum(a * b for a, b in zip(row, x))) ** 2
        if d < best:
            best, arg = d, idx
    return list(arg)


def bit_errors(a, b) -> int:
    """The number of differing bits between two integer labels, or summed over two equal-length lists."""
    if isinstance(a, int) and isinstance(b, int):
        return bin(a ^ b).count("1")
    if len(a) != len(b):
        raise ValueError("lengths differ")
    return sum(bit_errors(x, y) for x, y in zip(a, b))
optimum_multiuser_detector.py 116 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/optimum-multiuser-detector/. The authors are listed in prov/H2AQFV.jsonl.

"""Verdu's optimum (jointly maximum likelihood) multiuser detector for CDMA.

Model (real, chip level, coherent BPSK). User k = 0, ..., K-1 sends the bits
b_k[0], ..., b_k[M-1] in {-1, +1} with the amplitude A_k > 0 and the
signature s_k of N chips with unit energy. User k starts tau_k chips late,
with 0 <= tau_k < N. The receiver sees

    y[n] = sum_k A_k sum_i b_k[i] s_k[n - i N - tau_k] + w[n],

with w[n] independent N(0, sigma^2). In the complex baseband model this is
the in-phase part, with sigma^2 = N0 / 2. With all delays 0 the model is
synchronous: y = S A b + w for one symbol interval.

The detector orders the K M bits by start time, so that each bit overlaps only
the K - 1 bits before it and the K - 1 bits after it. The log-likelihood is
then a sum of branch metrics that depend on the current bit and the K - 1
bits before it, and a Viterbi search over 2^(K-1) states finds the bit
sequence that maximizes it.
"""

import math


def bit_waveforms(sigs: list[list[float]], delays: list[int], m: int) -> tuple[list[tuple[int, int]], list[int], int]:
    """The bits in order of start time.

    Returns (order, starts, length): order[t] = (user k, symbol i) of the t-th
    bit, starts[t] = i N + tau_k its first chip, and the frame length in chips.
    """
    k_users = len(sigs)
    if k_users < 1 or m < 1:
        raise ValueError("need K >= 1 and M >= 1")
    n = len(sigs[0])
    if any(len(s) != n for s in sigs) or len(delays) != k_users:
        raise ValueError("signatures must have N chips each and one delay per user")
    if any(not 0 <= d < n for d in delays):
        raise ValueError("delays must lie in 0 .. N - 1")
    bits = sorted(((i * n + delays[k], k, i) for i in range(m) for k in range(k_users)))
    order = [(k, i) for _, k, i in bits]
    starts = [st for st, _, _ in bits]
    return order, starts, m * n + max(delays)


def received(sigs, delays, amps, b, sigma=0.0, rng=None) -> list[float]:
    """The chip samples y for the bits b[k][i], plus N(0, sigma^2) noise if rng is given."""
    m = len(b[0])
    order, starts, length = bit_waveforms(sigs, delays, m)
    n = len(sigs[0])
    y = [0.0] * length
    for (k, i), st in zip(order, starts):
        a = amps[k] * b[k][i]
        for c in range(n):
            y[st + c] += a * sigs[k][c]
    if rng is not None and sigma > 0.0:
        y = [v + rng.gauss(0.0, sigma) for v in y]
    return y


def _corr(sa: list[float], st_a: int, sb: list[float], st_b: int) -> float:
    """The inner product of two shifted signatures."""
    n = len(sa)
    lo, hi = max(st_a, st_b), min(st_a, st_b) + n
    return sum(sa[c - st_a] * sb[c - st_b] for c in range(lo, hi))


def optimum_detector(y: list[float], sigs: list[list[float]], delays: list[int], amps: list[float], m: int) -> list[list[int]]:
    """The bit sequences b[k][i] that maximize the likelihood of y (ties are measure zero)."""
    k_users = len(sigs)
    order, starts, length = bit_waveforms(sigs, delays, m)  # @line L1
    if len(y) != length:
        raise ValueError("y has the wrong length")
    total = len(order)
    amp = [amps[k] for k, _ in order]
    z = []
    rho = []
    for t, (k, _) in enumerate(order):  # @line L2
        st = starts[t]
        z.append(sum(sigs[k][c] * y[st + c] for c in range(len(sigs[k]))))
        rho.append([_corr(sigs[k], st, sigs[order[t - d][0]], starts[t - d]) for d in range(1, min(t, k_users - 1) + 1)])
    # A state holds the last min(t, K - 1) bits, most recent last.
    metric = {(): 0.0}  # @line L3
    survivor: dict[tuple[int, ...], list[int]] = {(): []}
    for t in range(total):  # @line L4
        new_metric: dict[tuple[int, ...], float] = {}
        new_surv: dict[tuple[int, ...], list[int]] = {}
        for state, lam in metric.items():  # @line L5
            interf = sum(amp[t - d] * state[-d] * rho[t][d - 1] for d in range(1, len(state) + 1))
            for bt in (1, -1):
                branch = 2.0 * amp[t] * bt * (z[t] - interf)  # @line L6
                nxt = (state + (bt,))[-(k_users - 1):] if k_users > 1 else ()
                val = lam + branch  # @line L7
                if nxt not in new_metric or val > new_metric[nxt]:
                    new_metric[nxt] = val
                    new_surv[nxt] = survivor[state] + [bt]
        metric, survivor = new_metric, new_surv  # @line L8
    best = max(metric, key=lambda s: metric[s])  # @line L9
    seq = survivor[best]
    out = [[0] * m for _ in range(k_users)]
    for (k, i), bt in zip(order, seq):
        out[k][i] = bt
    return out


def optimum_synchronous(y: list[float], sigs: list[list[float]], amps: list[float]) -> list[int]:
    """The synchronous case, one symbol interval: argmin over b of ||y - S A b||^2."""
    res = optimum_detector(y, sigs, [0] * len(sigs), amps, 1)
    return [r[0] for r in res]


def log_likelihood(y, sigs, delays, amps, b) -> float:
    """-||y - signal(b)||^2, the log-likelihood up to a constant and the factor 1 / (2 sigma^2)."""
    s = received(sigs, delays, amps, b)
    return -math.fsum((u - v) ** 2 for u, v in zip(y, s))
test_optimum_multiuser_detector.py 114 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/optimum-multiuser-detector/. The authors are listed in prov/H2AQFV.jsonl.

import itertools
import math
import random

import pytest

import constel
from optimum_multiuser_detector import (
    bit_waveforms,
    log_likelihood,
    optimum_detector,
    optimum_synchronous,
    received,
)

R8 = 1.0 / math.sqrt(8.0)
# The signatures of the page: s1 s2 = 0.5, s1 s3 = 0.25, s2 s3 = -0.25.
S_PAGE = [
    [R8 * c for c in (1, 1, 1, 1, 1, 1, 1, 1)],
    [R8 * c for c in (1, 1, 1, 1, 1, 1, -1, -1)],
    [R8 * c for c in (1, -1, 1, -1, 1, -1, 1, 1)],
]


def random_sigs(rng: random.Random, k: int, n: int) -> list[list[float]]:
    s = 1.0 / math.sqrt(n)
    return [[s * rng.choice((1, -1)) for _ in range(n)] for _ in range(k)]


def brute_force(y, sigs, delays, amps, m):
    best, arg = -math.inf, None
    k = len(sigs)
    for flat in itertools.product((1, -1), repeat=k * m):
        b = [list(flat[u * m:(u + 1) * m]) for u in range(k)]
        v = log_likelihood(y, sigs, delays, amps, b)
        if v > best:
            best, arg = v, b
    return arg


def test_page_example_synchronous() -> None:
    # The matched filter outputs of the page come from these chip samples.
    amps = [1.0, 4.0, 2.0]
    b = [1, -1, 1]
    y = received(S_PAGE, [0, 0, 0], amps, [[v] for v in b])
    z = [sum(a * c for a, c in zip(s, y)) for s in S_PAGE]
    assert [round(v, 12) for v in z] == [-0.5, -4.0, 3.25]
    assert optimum_synchronous(y, S_PAGE, amps) == b


def test_synchronous_matches_brute_force_ml() -> None:
    rng = random.Random(4101)
    pts = constel.pam(2)  # [+1, -1]
    for k in range(1, 7):
        for _ in range(25):
            sigs = random_sigs(rng, k, 8)
            amps = [rng.uniform(0.3, 3.0) for _ in range(k)]
            b = [rng.choice((1, -1)) for _ in range(k)]
            y = received(sigs, [0] * k, amps, [[v] for v in b], sigma=0.6, rng=rng)
            h = [[amps[u] * sigs[u][c] for u in range(k)] for c in range(8)]
            idx = constel.ml_vector([complex(v) for v in y], h, pts)
            ref = [1 if i == 0 else -1 for i in idx]
            assert optimum_synchronous(y, sigs, amps) == ref


@pytest.mark.parametrize("k,m,seed", [(2, 4, 11), (3, 2, 12), (3, 3, 13), (4, 2, 14)])
def test_asynchronous_matches_brute_force(k: int, m: int, seed: int) -> None:
    rng = random.Random(seed)
    n = 7
    for _ in range(12):
        sigs = random_sigs(rng, k, n)
        delays = [0] + [rng.randrange(n) for _ in range(k - 1)]
        amps = [rng.uniform(0.3, 3.0) for _ in range(k)]
        b = [[rng.choice((1, -1)) for _ in range(m)] for _ in range(k)]
        y = received(sigs, delays, amps, b, sigma=0.8, rng=rng)
        assert optimum_detector(y, sigs, delays, amps, m) == brute_force(y, sigs, delays, amps, m)


def test_noiseless_frames_are_recovered() -> None:
    rng = random.Random(4102)
    for k in range(1, 6):
        sigs = random_sigs(rng, k, 16)
        if k > 1:
            sigs[1] = list(sigs[0])  # two users with the same signature but other delays
        delays = [rng.randrange(16) for _ in range(k)]
        if k > 1:
            delays[1] = (delays[0] + 5) % 16
        amps = [rng.uniform(0.5, 2.0) for _ in range(k)]
        b = [[rng.choice((1, -1)) for _ in range(5)] for _ in range(k)]
        y = received(sigs, delays, amps, b)
        assert optimum_detector(y, sigs, delays, amps, 5) == b


def test_each_bit_overlaps_only_k_minus_one_neighbors() -> None:
    rng = random.Random(4103)
    for k in range(1, 6):
        n = 9
        delays = [rng.randrange(n) for _ in range(k)]
        _, starts, _ = bit_waveforms([[1.0] * n] * k, delays, 4)
        for t in range(len(starts)):
            for u in range(t + k, len(starts)):
                assert starts[u] - starts[t] >= n


def test_errors() -> None:
    with pytest.raises(ValueError):
        bit_waveforms([[1.0, 0.0]], [2], 1)
    with pytest.raises(ValueError):
        bit_waveforms([[1.0, 0.0], [1.0]], [0, 0], 1)
    with pytest.raises(ValueError):
        optimum_detector([0.0], [[1.0, 0.0]], [0], [1.0], 1)

History

Verdú presented the optimum detector for asynchronous Gaussian multiple access channels at MILCOM 1983 and published it in the IEEE Transactions on Information Theory in 1986. He showed that a bank of matched filters gives sufficient statistics and that a Viterbi algorithm with 2K−12^{K-1} states finds the maximum likelihood bits, and he computed the asymptotic efficiency of the optimum detector, which showed that the conventional receiver loses much more than necessary in a near-far situation. In 1989 he proved that the synchronous problem is NP-hard in KK, which explained why the search over states could not be avoided in general. These results started the work on suboptimal multiuser detectors with polynomial cost, collected in his 1998 book.

References

  1. Sergio Verdú, Minimum probability of error for asynchronous Gaussian multiple-access channels, IEEE Transactions on Information Theory 32(1), 1986, pp. 85 to 96 (the matched filter bank, the Viterbi algorithm with 2^(K-1) states and complexity O(2^K) per bit, and the asymptotic efficiency of the optimum detector)
  2. Sergio Verdú, Minimum probability of error for asynchronous multiple access communication systems, IEEE Military Communications Conference (MILCOM), 1983, pp. 213 to 219 (the first presentation of the optimum detector)
  3. Sergio Verdú, Multiuser Detection, Cambridge University Press, 1998, Chapter 4, Optimum multiuser detection
  4. Sergio Verdú, Computational complexity of optimum multiuser detection, Algorithmica 4, 1989, pp. 303 to 312 (the synchronous problem is NP-hard in the number of users)
  5. C. Sankaran and A. Ephremides, Solving a class of optimum multiuser detection problems with polynomial complexity, IEEE Transactions on Information Theory 44(5), 1998, pp. 1958 to 1961 (nonpositive crosscorrelations give a minimum cut problem)

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.

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