Algorithm Search⌘K

Techniqueresearch

Interference alignment

Also called Cadambe-Jafar alignment.

Precode so interference at each receiver fills half its space. K users get K/2 degrees of freedom asymptotically, over time-varying or frequency-selective channels with ever longer symbol extensions.

Interference alignment is a way to choose the transmit beams of several users who share a band, so that at each receiver all the interference falls into one subspace, and the rest of the receive space is free for the wanted signal. In a KK-user interference channel, each receiver has K−1K - 1 interferers. Without alignment, each interferer takes its own dimensions, and the users must share the band, so the sum rate grows like log⁡SNR\log \mathrm{SNR} times a constant that does not grow with KK. Cadambe and Jafar (2008) showed that, when the channel coefficients vary in time or frequency, the interference at every receiver can be packed into half of its signal space at once. Each user then gets half of its interference-free rate at high SNR, and the sum has K/2K/2 degrees of freedom: the sum rate grows like (K/2)log⁡2SNR(K/2) \log_2 \mathrm{SNR}. The K/2K/2 is reached only in the limit: the scheme codes over symbol extensions, blocks of many channel uses, whose length grows without bound as the fraction approaches 1/21/2. With multiple antennas and constant channels, a closed form works for three users, and iterative methods find aligned beams for small systems.

In plain words

Many pairs of radios talk at the same time on the same frequency, and each receiver hears all the other senders as noise. A receiver can listen in several independent directions, like several separate ears. Normally each unwanted sender takes up some of these directions, and soon none are left for the wanted sender. Interference alignment chooses how each sender transmits so that, at every receiver, all the unwanted senders arrive from the same few directions. The receiver ignores those directions and listens in the others, where only its own sender is heard. With careful choices, every receiver can keep half of its directions clean. This only works fully when the channels change over time or frequency and the senders plan over very long blocks.

When it applies

  • An interference network. Several transmitter-receiver pairs share a band, each receiver wants only its own transmitter, and no pair can cancel the others' data (the transmitters do not share messages, unlike in dirty paper coding).
  • Channel knowledge at the transmitters. Each transmitter must know the channels of all links, or at least those it affects, to compute its beam. This is global channel state information.
  • Enough dimensions. Alignment needs spare signal dimensions: antennas, subcarriers or time slots. With constant channels and one antenna per node, the dimensions must come from symbol extensions over channels that vary, or from more abstract constructions.
  • High SNR. The gain is in degrees of freedom, the slope of the sum rate against log⁡2SNR\log_2 \mathrm{SNR}. It shows at high SNR, where interference, not noise, limits the rates.
  • Generic channels. The constructions need the channel matrices to be in general position, which holds with probability 11 for continuous fading laws.

The template

Signal model. Transmitter jj sends djd_j streams xjx_j through a precoder VjV_j (a matrix with djd_j columns). Receiver kk gets

yk=HkkVkxk+∑j≠kHkjVjxj+zk,y_k = H_{kk} V_k x_k + \sum_{j \ne k} H_{kj} V_j x_j + z_k,

where HkjH_{kj} is the channel from transmitter jj to receiver kk over all antennas and channel uses. Receiver kk applies a filter UkU_k with dkd_k columns.

Alignment conditions. The interference is removed when

UkHHkjVj=0for all j≠k,rank⁡(UkHHkkVk)=dk.U_k^H H_{kj} V_j = 0 \quad \text{for all } j \ne k, \qquad \operatorname{rank}\big(U_k^H H_{kk} V_k\big) = d_k.

The first condition says that all interference lies in the orthogonal complement of the columns of UkU_k; the second, that the wanted streams remain separable there. In terms of subspaces: at receiver kk, the span of all HkjVjH_{kj} V_j with j≠kj \ne k must have dimension at most Mk−dkM_k - d_k, where MkM_k is the receive dimension.

The 3-user 2x2 MIMO closed form. Three pairs, two antennas each, one stream per user: dk=1d_k = 1 in Mk=2M_k = 2 dimensions, so each receiver needs its two interferers on the same line. The three conditions are H12v2∥H13v3H_{12} v_2 \parallel H_{13} v_3, H21v1∥H23v3H_{21} v_1 \parallel H_{23} v_3 and H31v1∥H32v2H_{31} v_1 \parallel H_{32} v_2. The last two give v2v_2 and v3v_3 from v1v_1, and the first makes v1v_1 an eigenvector of a fixed matrix:

  1. ALIGN-THREE-USERS(H)
  2. 1E ← (H_13 H_23^{-1} H_21)^{-1} H_12 H_32^{-1} H_31
  3. 2v_1 ← an eigenvector of E
  4. 3v_2 ← H_32^{-1} H_31 v_1
  5. 4v_3 ← H_23^{-1} H_21 v_1
  6. 5for k ← 1 to 3: u_k ← a unit vector orthogonal to H_kj v_j for one j ≠ k
  7. 6return v_1, v_2, v_3 and u_1, u_2, u_3

Line L5 uses one interferer, since the other one is parallel to it. Each user then sends one stream free of interference, for 33 streams in total, while any one pair alone could send 22. With MM antennas at every node, the same idea gives three users 3M/23M/2 degrees of freedom; for odd MM it needs an extension over two channel uses.

Symbol extensions. With one antenna and coefficients that change in every channel use, take nn uses together: each HkjH_{kj} becomes an n×nn \times n diagonal matrix, and the alignment conditions are solved in this larger space. For three users, Cadambe and Jafar give user 1 n+1n + 1 streams and users 2 and 3 nn streams each over 2n+12n + 1 uses, for (3n+1)/(2n+1)(3n + 1)/(2n + 1) degrees of freedom per use, which tends to 3/23/2. For KK users, the construction aligns exactly in some dimensions and approximately in the count, and the fraction per user tends to 1/21/2 as the extension grows.

Classic examples

A real 3-user example. Take the integer channels

H11=I, H12=(1201), H13=(1011), H21=(2111), H22=(1101), H23=(1002),H_{11} = I, \ H_{12} = \begin{pmatrix} 1 & 2 \\ 0 & 1 \end{pmatrix}, \ H_{13} = \begin{pmatrix} 1 & 0 \\ 1 & 1 \end{pmatrix}, \ H_{21} = \begin{pmatrix} 2 & 1 \\ 1 & 1 \end{pmatrix}, \ H_{22} = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}, \ H_{23} = \begin{pmatrix} 1 & 0 \\ 0 & 2 \end{pmatrix},
H31=(0110), H32=(1112), H33=(2011).H_{31} = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \ H_{32} = \begin{pmatrix} 1 & 1 \\ 1 & 2 \end{pmatrix}, \ H_{33} = \begin{pmatrix} 2 & 0 \\ 1 & 1 \end{pmatrix}.

Line L1 gives E=(12−1−4)E = \begin{pmatrix} 1 & 2 \\ -1 & -4 \end{pmatrix}, with eigenvalues (−3±17)/2(-3 \pm \sqrt{17})/2. For λ=(17−3)/2=0.5616\lambda = (\sqrt{17} - 3)/2 = 0.5616, v1=(2,λ−1)=(2,−0.4384)v_1 = (2, \lambda - 1) = (2, -0.4384), then v2=(−2.8769,2.4384)v_2 = (-2.8769, 2.4384) and v3=(3.5616,0.7808)v_3 = (3.5616, 0.7808). At receiver 1, both interferers arrive along (1,1.2192)(1, 1.2192); at receiver 2 along (1,0.4384)(1, 0.4384); at receiver 3 along (1,−4.5616)(1, -4.5616). Each receiver projects onto the orthogonal line, where the wanted signal has a nonzero gain, so all three streams are free of interference. The other eigenvalue gives a second solution.

The K-user interference channel. With time-varying or frequency-selective channels and one antenna per node, the sum has K/2K/2 degrees of freedom, reached in the limit of long symbol extensions; with two users, it is 11, which time sharing already gets. For K=10K = 10 users, each user gets about half its own interference-free rate at high SNR, while time sharing gives each one tenth.

The X channel. Two transmitters each have a message for each of two receivers. Maddah-Ali, Motahari and Khandani (2008) aligned the unwanted messages at each receiver; with MM antennas per node, the X channel has 4M/34M/3 degrees of freedom (Jafar and Shamai), more than the MM of the interference channel with two users.

Variations

  • Iterative alignment. For constant MIMO channels with more users, Gomadam, Cadambe and Jafar (2011) proposed alternating minimization of the leakage ∑k∑j≠k∥UkHHkjVj∥F2\sum_k \sum_{j \ne k} \|U_k^H H_{kj} V_j\|_F^2: fix the precoders and take UkU_k as the eigenvectors of the smallest eigenvalues of the interference covariance at receiver kk, then do the same for the reverse network. The leakage decreases at each step. A max-SINR version replaces leakage by the SINR and works better at moderate SNR.
  • Feasibility for constant channels. With KK users, MM transmit and NN receive antennas and dd streams each, a necessary condition for alignment in general position is M+N≥(K+1)dM + N \ge (K + 1) d; for some sizes it is also sufficient. Without extensions, constant channels allow only a fixed number of users to align.
  • Ergodic alignment. With fading, pair each channel state with a complementary state and send the same symbols in both; the interference cancels in the sum. Each user gets half of its interference-free rate at every SNR, not only at high SNR.
  • Real interference alignment. For constant scalar channels, alignment on rationally independent dimensions of the real line (lattice and number-theoretic arguments) also reaches K/2K/2 for almost all channels, but only in the high-SNR limit.
  • Blind and partial alignment. Schemes that exploit known patterns of channel change (for example reconfigurable antennas) need no channel knowledge at the transmitters, at a smaller gain.

Pitfalls

  • K/2 is asymptotic. The fraction 1/21/2 per user is a limit over symbol extensions of growing length; any finite scheme gets less, for example (3n+1)/(2n+1)(3n + 1)/(2n + 1) for three users. With constant scalar channels and no extensions, alignment gives no gain.
  • Degrees of freedom are a high-SNR measure. At low and moderate SNR, the noise boost of the receive projection can make alignment worse than treating interference as noise or than weighted sum rate methods such as WMMSE.
  • Channel knowledge. Every transmitter needs accurate channels of the whole network. Errors leave residual interference whose power grows with the transmit power, so the rate stops growing at high SNR unless the feedback precision grows like log⁡SNR\log \mathrm{SNR} bits per coefficient.
  • Long extensions. The extension length needed for a fraction near 1/21/2 grows very fast with KK, and the channels must stay different across the uses of the extension.
  • Ill-conditioned channels. When the channel matrices are close to singular, the closed form uses near-singular inverses, the wanted gain ∣ukHHkkvk∣|u_k^H H_{kk} v_k| can be tiny, and the scheme loses at any practical SNR.

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.

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

"""Complex baseband tools for the communications pages.

Vectors are lists of complex numbers. Matrices are lists of rows. The
functions here are plain building blocks: small linear algebra, convolution,
the DFT as a direct sum, the Gaussian Q function, dB conversion, complex
Gaussian noise and the Wilson score interval. No page algorithm (equalizer,
estimator, synchronizer, detector, precoder, demapper or power allocation)
lives in this file.

Conventions (prompts of the communications area):
- dft is X[k] = sum_n x[n] e^(-j 2 pi k n / N) with no factor; idft has 1/N.
- udft and uidft are the unitary pair, with 1/sqrt(N) on both sides.
- qfunc(x) = 0.5 erfc(x / sqrt(2)); it never computes 1 - Phi(x).
- cn(rng, var) draws CN(0, var): real and imaginary parts are independent
  with variance var / 2 each, so E|w|^2 = var.
"""

import cmath
import math
import random


# ---------------------------------------------------------------- vectors and matrices


def zeros(rows: int, cols: int | None = None) -> list:
    """A zero vector of length rows, or a rows by cols zero matrix."""
    if cols is None:
        return [0j] * rows
    return [[0j] * cols for _ in range(rows)]


def eye(n: int) -> list[list[complex]]:
    """The n by n identity matrix."""
    return [[1 + 0j if i == k else 0j for k in range(n)] for i in range(n)]


def add(a: list, b: list) -> list:
    """Elementwise a + b for two vectors or two matrices of the same shape."""
    if len(a) != len(b):
        raise ValueError("shapes differ")
    if a and isinstance(a[0], list):
        return [add(r, s) for r, s in zip(a, b)]
    return [x + y for x, y in zip(a, b)]


def sub(a: list, b: list) -> list:
    """Elementwise a - b for two vectors or two matrices of the same shape."""
    if len(a) != len(b):
        raise ValueError("shapes differ")
    if a and isinstance(a[0], list):
        return [sub(r, s) for r, s in zip(a, b)]
    return [x - y for x, y in zip(a, b)]


def scale(c: complex, a: list) -> list:
    """The scalar c times a vector or a matrix."""
    if a and isinstance(a[0], list):
        return [scale(c, r) for r in a]
    return [c * x for x in a]


def matmul(a: list[list[complex]], b: list[list[complex]]) -> list[list[complex]]:
    """The matrix product a b."""
    if not a or not b or len(a[0]) != len(b):
        raise ValueError("inner dimensions differ")
    cols = list(zip(*b))
    return [[sum(x * y for x, y in zip(row, col)) for col in cols] for row in a]


def matvec(a: list[list[complex]], x: list[complex]) -> list[complex]:
    """The matrix times vector product a x."""
    if a and len(a[0]) != len(x):
        raise ValueError("inner dimensions differ")
    return [sum(p * q for p, q in zip(row, x)) for row in a]


def herm(a: list) -> list:
    """The conjugate transpose of a matrix. A vector gives its conjugate."""
    if a and isinstance(a[0], list):
        return [[complex(a[i][k]).conjugate() for i in range(len(a))] for k in range(len(a[0]))]
    return [complex(x).conjugate() for x in a]


def dot(x: list[complex], y: list[complex]) -> complex:
    """The inner product x^H y = sum of conj(x_i) y_i."""
    if len(x) != len(y):
        raise ValueError("lengths differ")
    return sum(complex(p).conjugate() * q for p, q in zip(x, y))


def norm2(x: list) -> float:
    """The squared Euclidean norm sum |x_i|^2 (squared Frobenius norm for a matrix)."""
    if x and isinstance(x[0], list):
        return sum(norm2(r) for r in x)
    return sum(abs(v) ** 2 for v in x)


# ---------------------------------------------------------------- linear systems


def _lu(a: list[list[complex]]) -> tuple[list[list[complex]], list[int], int]:
    """LU factorization with partial pivoting. Returns (lu, perm, sign)."""
    n = len(a)
    if any(len(r) != n for r in a):
        raise ValueError("matrix is not square")
    m = [[complex(v) for v in r] for r in a]
    perm = list(range(n))
    sign = 1
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(m[i][k]))
        if abs(m[p][k]) == 0.0:
            raise ValueError("matrix is singular")
        if p != k:
            m[k], m[p] = m[p], m[k]
            perm[k], perm[p] = perm[p], perm[k]
            sign = -sign
        for i in range(k + 1, n):
            f = m[i][k] / m[k][k]
            m[i][k] = f
            if f != 0:
                rk, ri = m[k], m[i]
                for c in range(k + 1, n):
                    ri[c] -= f * rk[c]
    return m, perm, sign


def _lu_solve(lu: list[list[complex]], perm: list[int], b: list[complex]) -> list[complex]:
    n = len(lu)
    y = [complex(b[perm[i]]) for i in range(n)]
    for i in range(n):
        for c in range(i):
            y[i] -= lu[i][c] * y[c]
    for i in range(n - 1, -1, -1):
        for c in range(i + 1, n):
            y[i] -= lu[i][c] * y[c]
        y[i] /= lu[i][i]
    return y


def solve(a: list[list[complex]], b: list) -> list:
    """Solve a x = b by Gaussian elimination with partial pivoting.

    b is a vector, or a matrix whose columns are right-hand sides.
    Raises ValueError if a is singular.
    """
    lu, perm, _ = _lu(a)
    if b and isinstance(b[0], list):
        cols = [list(c) for c in zip(*b)]
        xs = [_lu_solve(lu, perm, c) for c in cols]
        return [list(r) for r in zip(*xs)]
    if len(b) != len(a):
        raise ValueError("lengths differ")
    return _lu_solve(lu, perm, b)


def inv(a: list[list[complex]]) -> list[list[complex]]:
    """The inverse of a square matrix."""
    return solve(a, eye(len(a)))


def det(a: list[list[complex]]) -> complex:
    """The determinant of a square matrix (0 for a singular matrix)."""
    try:
        lu, _, sign = _lu(a)
    except ValueError as e:
        if "singular" in str(e):
            return 0j
        raise
    d = complex(sign)
    for i in range(len(lu)):
        d *= lu[i][i]
    return d


def cholesky(a: list[list[complex]]) -> list[list[complex]]:
    """The lower triangular L with a = L L^H, for a Hermitian positive definite a.

    Raises ValueError if a is not positive definite (to rounding).
    """
    n = len(a)
    low = zeros(n, n)
    for i in range(n):
        for k in range(i + 1):
            s = complex(a[i][k]) - sum(low[i][c] * low[k][c].conjugate() for c in range(k))
            if i == k:
                if s.real <= 0.0:
                    raise ValueError("matrix is not positive definite")
                low[i][i] = complex(math.sqrt(s.real))
            else:
                low[i][k] = s / low[k][k].real
    return low


# ---------------------------------------------------------------- convolution and the DFT


def conv(a: list[complex], b: list[complex]) -> list[complex]:
    """Linear convolution, of length len(a) + len(b) - 1."""
    if not a or not b:
        return []
    out = [0j] * (len(a) + len(b) - 1)
    for i, x in enumerate(a):
        for k, y in enumerate(b):
            out[i + k] += x * y
    return out


def cconv(a: list[complex], b: list[complex], n: int | None = None) -> list[complex]:
    """Circular convolution of length n (default: the longer length).

    Both inputs are padded with zeros to length n, or must not be longer than n.
    """
    if n is None:
        n = max(len(a), len(b))
    if len(a) > n or len(b) > n:
        raise ValueError("input longer than n")
    out = [0j] * n
    for i, x in enumerate(a):
        for k, y in enumerate(b):
            out[(i + k) % n] += x * y
    return out


def _twiddles(n: int, sign: int) -> list[complex]:
    return [cmath.exp(sign * 2j * math.pi * t / n) for t in range(n)]


def dft(x: list[complex]) -> list[complex]:
    """X[k] = sum over n of x[n] e^(-j 2 pi k n / N), as a direct O(N^2) sum."""
    n = len(x)
    w = _twiddles(n, -1)
    return [sum(x[t] * w[(k * t) % n] for t in range(n)) for k in range(n)]


def idft(xf: list[complex]) -> list[complex]:
    """x[n] = (1/N) sum over k of X[k] e^(j 2 pi k n / N), the inverse of dft."""
    n = len(xf)
    w = _twiddles(n, 1)
    return [sum(xf[k] * w[(k * t) % n] for k in range(n)) / n for t in range(n)]


def udft(x: list[complex]) -> list[complex]:
    """The unitary DFT: dft(x) / sqrt(N)."""
    s = 1.0 / math.sqrt(len(x)) if x else 1.0
    return [v * s for v in dft(x)]


def uidft(xf: list[complex]) -> list[complex]:
    """The unitary inverse DFT: sqrt(N) idft(X), the inverse of udft."""
    s = math.sqrt(len(xf)) if xf else 1.0
    return [v * s for v in idft(xf)]


# ---------------------------------------------------------------- Q function and dB


def qfunc(x: float) -> float:
    """Q(x) = P(Z > x) for a standard normal Z, computed as 0.5 erfc(x / sqrt(2))."""
    return 0.5 * math.erfc(x / math.sqrt(2.0))


def qinv(p: float) -> float:
    """The x with Q(x) = p, for 0 < p < 1, by bisection on Q (which decreases)."""
    if not 0.0 < p < 1.0:
        raise ValueError("p must be in (0, 1)")
    lo, hi = -40.0, 40.0
    for _ in range(200):
        mid = 0.5 * (lo + hi)
        if qfunc(mid) > p:
            lo = mid
        else:
            hi = mid
        if hi - lo <= 1e-15 * max(1.0, abs(mid)):
            break
    return 0.5 * (lo + hi)


def db(x: float) -> float:
    """10 log10(x), for a ratio of powers or energies."""
    return 10.0 * math.log10(x)


def undb(d: float) -> float:
    """10^(d / 10), the inverse of db."""
    return 10.0 ** (d / 10.0)


# ---------------------------------------------------------------- noise and statistics


def cn(rng: random.Random, var: float) -> complex:
    """One sample of CN(0, var): independent real and imaginary parts of variance var / 2."""
    s = math.sqrt(var / 2.0)
    return complex(rng.gauss(0.0, s), rng.gauss(0.0, s))


def awgn(rng: random.Random, x: list[complex], n0: float) -> list[complex]:
    """x plus independent CN(0, n0) noise on each sample."""
    return [v + cn(rng, n0) for v in x]


def wilson(k: int, n: int, z: float = 3.29) -> tuple[float, float]:
    """The Wilson score interval for k successes in n trials (z = 3.29 is about 0.999 two-sided)."""
    if n <= 0 or not 0 <= k <= n:
        raise ValueError("need 0 <= k <= n and n > 0")
    p = k / n
    z2 = z * z
    den = 1.0 + z2 / n
    mid = (p + z2 / (2 * n)) / den
    half = z * math.sqrt(p * (1 - p) / n + z2 / (4 * n * n)) / den
    return max(0.0, mid - half), min(1.0, mid + half)
interference_alignment.py 98 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/interference-alignment/. The authors are listed in prov/BAD5BM.jsonl.

"""Interference alignment for the 3-user 2x2 MIMO interference channel.

Three transmitters and three receivers each have 2 antennas. h[k][j] is the
2x2 channel matrix from transmitter j to receiver k (users 0, 1, 2). Each
user sends one stream with the beam v[j]. Receiver k sees the two interfering
directions h[k][j] v[j], j != k, in its 2-dimensional space. If the two are
parallel, they fill only one dimension, and the receiver projects onto the
other dimension with u[k] to see its own stream free of interference. Then
all three users get one stream each, 3 streams in total in a space where
any one user alone could send 2.

The closed form of Cadambe and Jafar: with all channel matrices invertible,
    v[0] = an eigenvector of E = (h02 h12^-1 h10)^-1 (h01 h21^-1 h20),
    v[1] = h21^-1 h20 v[0],  v[2] = h12^-1 h10 v[0].
"""

import cmath
import math

from cbb import dot, inv, matmul, matvec


def _unit(x: list[complex]) -> list[complex]:
    n = math.sqrt(sum(abs(c) ** 2 for c in x))
    if n == 0.0:
        raise ValueError("zero vector")
    return [c / n for c in x]


def eigvec2(a: list[list[complex]], which: int = 0) -> tuple[complex, list[complex]]:
    """An eigenvalue and a unit eigenvector of a 2x2 matrix (which = 0 or 1 picks the root)."""
    tr = a[0][0] + a[1][1]
    dt = a[0][0] * a[1][1] - a[0][1] * a[1][0]
    root = cmath.sqrt(tr * tr - 4 * dt)
    lam = (tr + root) / 2 if which == 0 else (tr - root) / 2
    # (a - lam I) x = 0: use the row with the larger entries for a stable null vector
    r0 = [a[0][0] - lam, a[0][1]]
    r1 = [a[1][0], a[1][1] - lam]
    row = r0 if abs(r0[0]) + abs(r0[1]) >= abs(r1[0]) + abs(r1[1]) else r1
    if abs(row[0]) + abs(row[1]) == 0.0:
        return lam, [1 + 0j, 0j]
    return lam, _unit([-row[1], row[0]])


def orthogonal_unit(a: list[complex]) -> list[complex]:
    """A unit vector u in C^2 with u^H a = 0."""
    return _unit([-complex(a[1]).conjugate(), complex(a[0]).conjugate()])


def align_three_users(h: list[list[list[list[complex]]]], which: int = 0) -> tuple[list[list[complex]], list[list[complex]]]:
    """Beams v[k] and receive filters u[k] that align the interference of the 3-user 2x2 channel."""
    a = matmul(h[0][1], matmul(inv(h[2][1]), h[2][0]))  # @line L1
    b = matmul(h[0][2], matmul(inv(h[1][2]), h[1][0]))
    e = matmul(inv(b), a)
    _, v0 = eigvec2(e, which)  # @line L2
    v1 = _unit(matvec(inv(h[2][1]), matvec(h[2][0], v0)))  # @line L3
    v2 = _unit(matvec(inv(h[1][2]), matvec(h[1][0], v0)))  # @line L4
    v = [v0, v1, v2]
    u = []
    for k in range(3):  # @line L5
        j = (k + 1) % 3
        u.append(orthogonal_unit(matvec(h[k][j], v[j])))
    return v, u  # @line L6


def leakage(h, v, u) -> float:
    """Total interference power after the filters, sum over k and j != k of |u_k^H h_kj v_j|^2."""
    total = 0.0
    for k in range(3):
        for j in range(3):
            if j != k:
                total += abs(dot(u[k], matvec(h[k][j], v[j]))) ** 2
    return total


def desired_gains(h, v, u) -> list[float]:
    """The gains |u_k^H h_kk v_k|^2 of the wanted streams."""
    return [abs(dot(u[k], matvec(h[k][k], v[k]))) ** 2 for k in range(3)]


def parallel_defect(x: list[complex], y: list[complex]) -> float:
    """|det [x y]| / (|x| |y|): 0 exactly when the two vectors of C^2 are parallel."""
    nx = math.sqrt(sum(abs(c) ** 2 for c in x))
    ny = math.sqrt(sum(abs(c) ** 2 for c in y))
    return abs(x[0] * y[1] - x[1] * y[0]) / (nx * ny)


def sum_rate(h, v, u, snr: float) -> float:
    """Sum rate in bit/s/Hz with power snr per user, unit noise and the filters u (interference included)."""
    total = 0.0
    for k in range(3):
        s = snr * abs(dot(u[k], matvec(h[k][k], v[k]))) ** 2
        i = sum(snr * abs(dot(u[k], matvec(h[k][j], v[j]))) ** 2 for j in range(3) if j != k)
        total += math.log2(1.0 + s / (1.0 + i))
    return total
test_interference_alignment.py 100 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/interference-alignment/. The authors are listed in prov/BAD5BM.jsonl.

import math
import random

import pytest

from cbb import cn, dot, matvec
from interference_alignment import (
    align_three_users,
    desired_gains,
    eigvec2,
    leakage,
    orthogonal_unit,
    parallel_defect,
    sum_rate,
)


def page_channels():
    m = {
        (1, 1): [[1, 0], [0, 1]], (2, 2): [[1, 1], [0, 1]], (3, 3): [[2, 0], [1, 1]],
        (1, 2): [[1, 2], [0, 1]], (1, 3): [[1, 0], [1, 1]],
        (2, 1): [[2, 1], [1, 1]], (2, 3): [[1, 0], [0, 2]],
        (3, 1): [[0, 1], [1, 0]], (3, 2): [[1, 1], [1, 2]],
    }
    return [[[[complex(x) for x in row] for row in m[k + 1, j + 1]] for j in range(3)] for k in range(3)]


def random_channels(rng: random.Random):
    return [[[[cn(rng, 1.0) for _ in range(2)] for _ in range(2)] for _ in range(3)] for _ in range(3)]


def direction(x):
    """x scaled so that its first entry is 1."""
    return [c / x[0] for c in x]


def test_page_example() -> None:
    h = page_channels()
    v, u = align_three_users(h)
    assert leakage(h, v, u) < 1e-18
    lam = (math.sqrt(17) - 3) / 2
    assert direction(v[0]) == pytest.approx([1, (lam - 1) / 2], abs=1e-12)
    assert direction(v[1]) == pytest.approx([1, -2.4384471871911697 / 2.8768943743823394], abs=1e-12)
    assert direction(v[2]) == pytest.approx([1, 0.7807764064044151 / 3.5615528128088303], abs=1e-12)
    # the interference directions at the three receivers
    assert direction(matvec(h[0][1], v[1])) == pytest.approx([1, 2.4384471871911697 / 2], abs=1e-12)
    assert direction(matvec(h[1][0], v[0])) == pytest.approx([1, 1.5615528128088303 / 3.5615528128088303], abs=1e-12)
    assert direction(matvec(h[2][0], v[0])) == pytest.approx([1, 2 / -0.4384471871911697], abs=1e-12)
    assert min(desired_gains(h, v, u)) > 0.1


def test_eigvec2() -> None:
    lam, x = eigvec2([[2, 1], [1, 2]], 0)
    assert lam == pytest.approx(3)
    assert abs(x[0] - x[1]) < 1e-12
    lam, x = eigvec2([[1, 0], [0, 1]], 1)
    assert lam == pytest.approx(1)
    assert sum(abs(c) ** 2 for c in x) == pytest.approx(1)


def test_orthogonal_unit() -> None:
    rng = random.Random(5)
    for _ in range(50):
        a = [cn(rng, 1.0), cn(rng, 1.0)]
        u = orthogonal_unit(a)
        assert abs(dot(u, a)) < 1e-12
        assert sum(abs(c) ** 2 for c in u) == pytest.approx(1.0, abs=1e-12)


def test_zero_leakage_on_random_channels() -> None:
    rng = random.Random(2008)
    for _ in range(200):
        h = random_channels(rng)
        for which in (0, 1):
            v, u = align_three_users(h, which)
            assert leakage(h, v, u) < 1e-9
            for k in range(3):
                i, j = [x for x in range(3) if x != k]
                assert parallel_defect(matvec(h[k][i], v[i]), matvec(h[k][j], v[j])) < 1e-9
            assert min(desired_gains(h, v, u)) > 0.0


def test_random_beams_leak() -> None:
    rng = random.Random(77)
    h = random_channels(rng)
    v = [[cn(rng, 1.0), cn(rng, 1.0)] for _ in range(3)]
    u = [orthogonal_unit(matvec(h[k][(k + 1) % 3], v[(k + 1) % 3])) for k in range(3)]
    assert leakage(h, v, u) > 1e-3


def test_three_degrees_of_freedom() -> None:
    rng = random.Random(11)
    h = random_channels(rng)
    v, u = align_three_users(h)
    lo, hi = sum_rate(h, v, u, 1e6), sum_rate(h, v, u, 1e10)
    # each factor 10^4 in power adds 3 log2(10^4) bits when 3 streams are free of interference
    assert (hi - lo) == pytest.approx(3 * math.log2(1e4), abs=1e-3)

Exercises

  1. In the 3-user 2x2 closed form, show that the two eigenvectors of EE give two different aligned solutions, and that if EE has a repeated eigenvalue with a single eigenvector, only one remains.
  2. Verify the example: compute H12v2H_{12} v_2 and H13v3H_{13} v_3 and show that they are parallel.
  3. Show that for K=2K = 2 users with one antenna each, time sharing already gets 11 degree of freedom, the same as K/2K/2, so alignment gives nothing.
  4. For three single-antenna users over 2n+12n + 1 channel uses, count the dimensions of the interference at receiver 1 when user 1 sends n+1n + 1 streams and the others nn each, and explain why the interference must fill at most nn dimensions.
  5. Write the leakage minimization for three 2x2 users as alternating steps, and show that the leakage does not increase from one step to the next.
Proof: The 3-user 2x2 closed form aligns the interference at every receiverfull

Three transmitter-receiver pairs have two antennas each. Hkj∈C2×2H_{kj} \in \mathbb C^{2 \times 2} is the channel from transmitter jj to receiver kk, and every cross channel HkjH_{kj}, j≠kj \ne k, is invertible. Each transmitter sends one stream along a nonzero beam vj∈C2v_j \in \mathbb C^2, and receiver kk applies a unit vector uku_k. Two nonzero vectors a,b∈C2a, b \in \mathbb C^2 are parallel, a∥ba \parallel b, when b=c ab = c\, a for some c∈Cc \in \mathbb C, which holds exactly when det⁡[a b]=a1b2−a2b1=0\det[a\ b] = a_1 b_2 - a_2 b_1 = 0.

Lemma 1 (orthogonal vector). For nonzero a∈C2a \in \mathbb C^2, u=(−aˉ2,aˉ1)/∥a∥u = (-\bar a_2, \bar a_1)/\|a\| is a unit vector with uHa=0u^H a = 0, and every b∥ab \parallel a also has uHb=0u^H b = 0.

Proof. ∥u∥2=(∣a2∣2+∣a1∣2)/∥a∥2=1\|u\|^2 = (|a_2|^2 + |a_1|^2)/\|a\|^2 = 1. uHa=(−a2a1+a1a2)/∥a∥=0u^H a = (-a_2 a_1 + a_1 a_2)/\|a\| = 0. If b=c ab = c\, a, then uHb=c uHa=0u^H b = c\, u^H a = 0. □\square

Lemma 2 (2x2 eigenvector). For E∈C2×2E \in \mathbb C^{2 \times 2} and a root λ\lambda of λ2−tr⁡(E)λ+det⁡E=0\lambda^2 - \operatorname{tr}(E) \lambda + \det E = 0, let (r1,r2)(r_1, r_2) be a nonzero row of E−λIE - \lambda I. Then x=(−r2,r1)x = (-r_2, r_1) is a nonzero vector with Ex=λxE x = \lambda x. If both rows are zero, E=λIE = \lambda I and every nonzero vector is an eigenvector.

Proof. λ\lambda is an eigenvalue, so det⁡(E−λI)=0\det(E - \lambda I) = 0, and E−λIE - \lambda I has rank at most 11. If its rank is 11, both rows are multiples of the nonzero row rr, and its null space is the line of vectors orthogonal (in the bilinear sense) to rr: r1x1+r2x2=−r1r2+r2r1=0r_1 x_1 + r_2 x_2 = -r_1 r_2 + r_2 r_1 = 0, so xx is in the null space of every row. If the rank is 00, E=λIE = \lambda I. □\square

The code picks the row with the larger entries, which is a nonzero row whenever E≠λIE \ne \lambda I, and returns the vector scaled to unit length.

Theorem (alignment). Let A=H12H32−1H31A = H_{12} H_{32}^{-1} H_{31} and B=H13H23−1H21B = H_{13} H_{23}^{-1} H_{21}, both invertible, and E=B−1AE = B^{-1} A. Let v1v_1 be an eigenvector of EE with eigenvalue λ\lambda, and put v2=H32−1H31v1v_2 = H_{32}^{-1} H_{31} v_1, v3=H23−1H21v1v_3 = H_{23}^{-1} H_{21} v_1. Then v2,v3≠0v_2, v_3 \ne 0, and

H31v1∥H32v2,H21v1∥H23v3,H12v2∥H13v3.H_{31} v_1 \parallel H_{32} v_2, \qquad H_{21} v_1 \parallel H_{23} v_3, \qquad H_{12} v_2 \parallel H_{13} v_3.

With uku_k orthogonal to one interference vector at receiver kk as in Lemma 1, ukHHkjvj=0u_k^H H_{kj} v_j = 0 for both j≠kj \ne k.

Proof. v2v_2 and v3v_3 are images of v1≠0v_1 \ne 0 under invertible matrices, so they are nonzero. H32v2=H31v1H_{32} v_2 = H_{31} v_1 and H23v3=H21v1H_{23} v_3 = H_{21} v_1 by construction, which gives the first two relations with c=1c = 1. For the third, H12v2=H12H32−1H31v1=Av1H_{12} v_2 = H_{12} H_{32}^{-1} H_{31} v_1 = A v_1 and H13v3=H13H23−1H21v1=Bv1H_{13} v_3 = H_{13} H_{23}^{-1} H_{21} v_1 = B v_1. From B−1Av1=λv1B^{-1} A v_1 = \lambda v_1 we get Av1=λBv1A v_1 = \lambda B v_1, so H12v2=λH13v3H_{12} v_2 = \lambda H_{13} v_3. Since AA is invertible and v1≠0v_1 \ne 0, λ≠0\lambda \ne 0, so the two vectors are nonzero multiples of each other. At each receiver, the two interference vectors are parallel and nonzero, so by Lemma 1 the vector uku_k built from either one is orthogonal to both. □\square

Wanted signal. The wanted gain ukHHkkvku_k^H H_{kk} v_k is nonzero unless HkkvkH_{kk} v_k falls on the interference line at receiver kk. The beams and filters do not depend on HkkH_{kk}, so for direct channels drawn from any continuous law, independent of the cross channels, this happens with probability 00: for fixed uku_k and vkv_k, the set of HkkH_{kk} with ukHHkkvk=0u_k^H H_{kk} v_k = 0 is a proper linear subspace of C2×2\mathbb C^{2 \times 2}. Then each receiver sees its stream with gain gk=∣ukHHkkvk∣2>0g_k = |u_k^H H_{kk} v_k|^2 > 0 and no interference, and with power PP per user and unit noise the sum rate is ∑klog⁡2(1+Pgk)\sum_k \log_2(1 + P g_k), which grows like 3log⁡2P3 \log_2 P: three degrees of freedom. The tests check this slope.

The code. Lines L1 to L4 of the page compute EE, v1v_1, v2v_2 and v3v_3 as in the theorem; the code scales each beam to unit length, which keeps every parallel relation. Line L5 builds uku_k from the interferer j=k+1 mod 3j = k + 1 \bmod 3 by Lemma 1. In floating point the relations hold up to rounding, which the tests bound by 10−910^{-9} for random Gaussian channels.

References

  1. Viveck R. Cadambe and Syed A. Jafar, Interference alignment and degrees of freedom of the K-user interference channel, IEEE Transactions on Information Theory 54(8), 2008, pages 3425 to 3441, the K/2 degrees of freedom of the K-user interference channel with time-varying or frequency-selective coefficients, the alignment scheme over symbol extensions, the 3-user scheme over 2n + 1 symbols with 3n + 1 streams, and the closed form for the 3-user MIMO channel with constant coefficients
  2. Mohammad Ali Maddah-Ali, Abolfazl S. Motahari and Amir K. Khandani, Communication over MIMO X channels: interference alignment, decomposition, and performance analysis, IEEE Transactions on Information Theory 54(8), 2008, pages 3457 to 3470, the alignment of interference in the two-user MIMO X channel, and the resulting gain in multiplexing over the interference channel

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 proofH2 full proof
  • correctness: no review record reviews/BAD5BM/proof-correctness.yaml
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
  • three classic examples