Algorithm Search⌘K

Algorithmadvanced

Regularized zero-forcing precoding

Also called RZF precoding, MMSE precoding.

Adds a regularization term to the channel inversion, which trades residual interference for less noise enhancement.

Time
O(K^2 M + K^3) worst
Space
O(M K) extra
Where
K = the number of single-antenna users; M = the number of base station antennas
Properties
deterministiclinearminimizes sum mseneeds channel at transmitterneeds noise levelnot zero interference
Origin
Christian B. Peel, Bertrand M. Hochwald, A. Lee Swindlehurst, 2005

Regularized zero-forcing (RZF) precoding is the linear multiuser precoder W=βHH(HHH+αI)−1W = \beta H^H (H H^H + \alpha I)^{-1} with α=KN0/P\alpha = K N_0 / P and a scalar β\beta that sets the transmit power to PP. It sits between the two simple linear precoders. With α→0\alpha \to 0 it is zero-forcing precoding, which removes all interference but can need much power when the channel matrix is badly conditioned. With α→∞\alpha \to \infty it sends each user a beam along its own channel, as maximum ratio transmission does, and ignores interference. The choice α=KN0/P\alpha = K N_0 / P minimizes the sum mean squared error at the users, so RZF is the transmit form of the MMSE filter. The same regularized inverse (⋅+noise⋅I)−1(\cdot + \text{noise} \cdot I)^{-1} appears at the receiver in the MMSE linear equalizer, the MMSE MIMO detector and the MMSE multiuser detector; here it is applied before the channel, and the regularization is KN0/PK N_0 / P because the noise is at the receivers while the power limit is at the transmitter. Vector perturbation precoding adds an integer offset to the data before the same inverse, and weighted MMSE precoding tunes the beams to a weighted sum rate instead of the plain sum MSE.

In plain words

A base station sends to several users at once. One simple method aims a beam at each user and ignores the others. Another method cancels every leak between users completely, but it may spend a lot of power to do this when two users are in similar directions. Regularized zero forcing takes a middle path. It cancels most of the leaks but stops when the cost in power gets too high. How far it goes depends on the noise: with much noise it cares more about signal strength, and with little noise it cares more about canceling the leaks. The result is a smaller total error at the users than either simple method.

The problem

User kk receives yk=hkHx+wky_k = h_k^H x + w_k, with H=[h1,…,hK]H∈CK×MH = [h_1, \ldots, h_K]^H \in \mathbb{C}^{K \times M} known at the base station, wk∼CN(0,N0)w_k \sim \mathcal{CN}(0, N_0), x=Wsx = W s, E[ssH]=IKE[s s^H] = I_K and the power tr(WHW)=P\mathrm{tr}(W^H W) = P. Each user scales its sample by the same real factor 1/β1/\beta. The goal is the linear precoder that minimizes the sum MSE E∥s−β−1y∥2E\|s - \beta^{-1} y\|^2, as a cheap and robust stand-in for the sum rate. Unlike zero forcing, RZF also works when K=MK = M with a badly conditioned HH, and even when K>MK > M, because HHH+αIH H^H + \alpha I is always invertible.

The algorithm

  1. RZF-PRECODE(H, P, N0)
  2. 1α ← K N0 / P ▷ the regularization
  3. 2A ← H Hᴴ ▷ K × K
  4. 3A ← A + α I
  5. 4F ← Hᴴ A⁻¹ ▷ solve A X = H, F = Xᴴ
  6. 5β ← √(P / ‖F‖²_F) ▷ meet the power exactly
  7. 6return W = β F

Line L4 needs one factorization of a K×KK \times K Hermitian positive definite matrix, for example a Cholesky decomposition, and MM solves. By the push-through identity, HH(HHH+αI)−1=(HHH+αI)−1HHH^H (H H^H + \alpha I)^{-1} = (H^H H + \alpha I)^{-1} H^H, so a base station with M<KM < K can invert the smaller M×MM \times M matrix instead. Line L5 does not change the directions of the beams, only the common power.

Example

Take the same channel as on the zero-forcing page: M=K=2M = K = 2, P=10P = 10, N0=1N_0 = 1 and

H=(2111),HHH=(5332).H = \begin{pmatrix} 2 & 1 \\ 1 & 1 \end{pmatrix}, \qquad H H^H = \begin{pmatrix} 5 & 3 \\ 3 & 2 \end{pmatrix}.

Line L1 gives α=2⋅1/10=0.2\alpha = 2 \cdot 1 / 10 = 0.2. Then A=(5.2332.2)A = \begin{pmatrix} 5.2 & 3 \\ 3 & 2.2 \end{pmatrix} with det⁡A=2.44\det A = 2.44, and

F=HHA−1=12.44(1.4−0.8−0.82.2),HF=12.44(2.00.60.61.4).F = H^H A^{-1} = \frac{1}{2.44} \begin{pmatrix} 1.4 & -0.8 \\ -0.8 & 2.2 \end{pmatrix}, \qquad H F = \frac{1}{2.44} \begin{pmatrix} 2.0 & 0.6 \\ 0.6 & 1.4 \end{pmatrix}.

So each user still hears some interference (0.6/2.440.6 / 2.44 against the signals 2.0/2.442.0 / 2.44 and 1.4/2.441.4 / 2.44). Line L5 gives ∥F∥F2=8.08/2.442=1.357\|F\|_F^2 = 8.08 / 2.44^2 = 1.357 and β=2.714\beta = 2.714. The SINRs are 3.425 and 1.678, and the sum rate is 3.567 bits per channel use. The table compares RZF with the other linear precoders on this channel; the zero-forcing rows are from the zero-forcing page:

precoder P=1P = 1 P=10P = 10 P=100P = 100
RZF, α=KN0/P\alpha = K N_0 / P 1.737 3.567 8.066
zero forcing, channel inversion 0.385 2.560 7.868
zero forcing, water-filling 0.585 2.853
maximum ratio transmission, equal power 1.433 2.045

At P=10P = 10 the sum MSE of RZF is α tr(A−1)=0.2⋅7.4/2.44=0.607\alpha\, \mathrm{tr}(A^{-1}) = 0.2 \cdot 7.4 / 2.44 = 0.607, against 1.4 for the plain inverse. At high power RZF and zero forcing come close, because α\alpha goes to 0.

Correctness

The proof is in proofs/correctness.md. Theorem 1 shows that the scaling of line L5 meets the power constraint exactly. Lemma 2 writes the sum MSE of any scaled precoder as ∥I−HF∥F2+(KN0/P)∥F∥F2\|I - H F\|_F^2 + (K N_0 / P) \|F\|_F^2, which does not depend on the scale of FF. Theorem 2 shows that this is a Tikhonov regularization problem whose unique minimizer is the FF of line L4, with the minimum α tr((HHH+αI)−1)\alpha\, \mathrm{tr}((H H^H + \alpha I)^{-1}); this is the transmit Wiener filter of Joham, Utschick and Nossek. Theorem 3 shows that the limits α→0\alpha \to 0 and α→∞\alpha \to \infty give zero forcing with channel inversion and matched beams hkh_k.

Proof: RZF meets the power constraint, minimizes the sum MSE with a common receive scale, and tends to zero forcing and to matched beams at its two limitsfull

The model is yk=hkHx+wky_k = h_k^H x + w_k for k=1,…,Kk = 1, \ldots, K, with H=[h1,…,hK]H∈CK×MH = [h_1, \ldots, h_K]^H \in \mathbb{C}^{K \times M}, w∼CN(0,N0IK)w \sim \mathcal{CN}(0, N_0 I_K), x=Wsx = W s and E[ssH]=IKE[s s^H] = I_K. Lines L1 to L5 compute α=KN0/P\alpha = K N_0 / P, F=HH(HHH+αI)−1F = H^H (H H^H + \alpha I)^{-1}, β=P/∥F∥F2\beta = \sqrt{P / \|F\|_F^2} and W=βFW = \beta F. Each user scales its sample by 1/β1/\beta.

Lemma 1 (push-through identity). For α>0\alpha > 0, both HHH+αIKH H^H + \alpha I_K and HHH+αIMH^H H + \alpha I_M are positive definite, and HH(HHH+αIK)−1=(HHH+αIM)−1HHH^H (H H^H + \alpha I_K)^{-1} = (H^H H + \alpha I_M)^{-1} H^H.

Proof. For u≠0u \ne 0, uH(HHH+αI)u=∥HHu∥2+α∥u∥2>0u^H (H H^H + \alpha I) u = \|H^H u\|^2 + \alpha \|u\|^2 > 0, and the same holds for the other matrix. Then (HHH+αI)HH=HHHHH+αHH=HH(HHH+αI)(H^H H + \alpha I) H^H = H^H H H^H + \alpha H^H = H^H (H H^H + \alpha I). Multiply on the left by (HHH+αI)−1(H^H H + \alpha I)^{-1} and on the right by (HHH+αI)−1(H H^H + \alpha I)^{-1}. □\square

Theorem 1 (power). tr(WHW)=P\mathrm{tr}(W^H W) = P.

Proof. tr(WHW)=β2∥F∥F2=P\mathrm{tr}(W^H W) = \beta^2 \|F\|_F^2 = P. Here F≠0F \ne 0 if H≠0H \ne 0, because HF=HHH(HHH+αI)−1H F = H H^H (H H^H + \alpha I)^{-1} has the positive eigenvalues λi/(λi+α)\lambda_i / (\lambda_i + \alpha) for the positive eigenvalues λi\lambda_i of HHHH H^H. □\square

Lemma 2 (the MSE of a scaled precoder). For W=βFW = \beta F with β=P/∥F∥F2\beta = \sqrt{P / \|F\|_F^2}, the sum MSE with the common receive scale 1/β1/\beta is

E∥s−β−1y∥2=∥IK−HF∥F2+KN0P∥F∥F2.E\|s - \beta^{-1} y\|^2 = \|I_K - H F\|_F^2 + \frac{K N_0}{P} \|F\|_F^2.

Proof. β−1y=HFs+β−1w\beta^{-1} y = H F s + \beta^{-1} w, so s−β−1y=(I−HF)s−β−1ws - \beta^{-1} y = (I - H F) s - \beta^{-1} w. The two terms are independent with zero mean, so the MSE is tr((I−HF)(I−HF)H)+β−2KN0\mathrm{tr}((I - H F)(I - H F)^H) + \beta^{-2} K N_0, and β−2=∥F∥F2/P\beta^{-2} = \|F\|_F^2 / P. □\square

The right side does not change when FF is multiplied by a positive scalar together with the matching β\beta. So minimizing it over FF is the same as minimizing the MSE over all pairs (W,β)(W, \beta) with tr(WHW)=P\mathrm{tr}(W^H W) = P.

Theorem 2 (the transmit Wiener filter). The function J(F)=∥I−HF∥F2+α∥F∥F2J(F) = \|I - H F\|_F^2 + \alpha \|F\|_F^2 with α=KN0/P\alpha = K N_0 / P has the unique minimizer F⋆=HH(HHH+αI)−1F^\star = H^H (H H^H + \alpha I)^{-1}, and the minimum is J(F⋆)=α tr((HHH+αI)−1)J(F^\star) = \alpha\, \mathrm{tr}\bigl((H H^H + \alpha I)^{-1}\bigr).

Proof. JJ is a sum of KK independent problems, one for each column fkf_k of FF: J=∑k(∥ek−Hfk∥2+α∥fk∥2)J = \sum_k \bigl(\|e_k - H f_k\|^2 + \alpha \|f_k\|^2\bigr). Each is a Tikhonov regularization problem. Expand it as fkH(HHH+αI)fk−2Re(fkHHHek)+1f_k^H (H^H H + \alpha I) f_k - 2 \mathrm{Re}(f_k^H H^H e_k) + 1. The quadratic form is positive definite by Lemma 1, so the function is strictly convex, and its unique minimizer is the zero of the gradient, (HHH+αI)fk=HHek(H^H H + \alpha I) f_k = H^H e_k. So F⋆=(HHH+αI)−1HHF^\star = (H^H H + \alpha I)^{-1} H^H, which is HH(HHH+αI)−1H^H (H H^H + \alpha I)^{-1} by Lemma 1. For the value, let A=HHH+αIA = H H^H + \alpha I. Then I−HF⋆=I−HHHA−1=αA−1I - H F^\star = I - H H^H A^{-1} = \alpha A^{-1}, and

J(F⋆)=α2tr(A−2)+α tr(A−1HHHA−1)=α tr(A−1(αI+HHH)A−1)=α tr(A−1). □J(F^\star) = \alpha^2 \mathrm{tr}(A^{-2}) + \alpha\, \mathrm{tr}(A^{-1} H H^H A^{-1}) = \alpha\, \mathrm{tr}\bigl(A^{-1} (\alpha I + H H^H) A^{-1}\bigr) = \alpha\, \mathrm{tr}(A^{-1}). \ \square

So, by Lemma 2 and the remark after it, the RZF precoder of lines L1 to L6 minimizes the sum MSE over all linear precoders with power PP and a common receive scale. This is the transmit Wiener filter of Joham, Utschick and Nossek (2005).

Theorem 3 (the two limits). Let HH have full row rank. As α→0\alpha \to 0, WW tends to P/tr((HHH)−1) HH(HHH)−1\sqrt{P / \mathrm{tr}((H H^H)^{-1})}\, H^H (H H^H)^{-1}, the zero-forcing precoder with the channel inversion power rule, so HWH W tends to a multiple of II. As α→∞\alpha \to \infty, WW tends to P/∥H∥F2 HH\sqrt{P / \|H\|_F^2}\, H^H, a matched beam hkh_k for each user with the power share ∥hk∥2/∥H∥F2\|h_k\|^2 / \|H\|_F^2.

Proof. WW does not change when FF is multiplied by a positive scalar. As α→0\alpha \to 0, F→HH(HHH)−1F \to H^H (H H^H)^{-1} by continuity of the inverse at the invertible matrix HHHH H^H. As α→∞\alpha \to \infty, αF=HH(HHH/α+I)−1→HH\alpha F = H^H (H H^H / \alpha + I)^{-1} \to H^H. In both cases the normalization by β\beta gives the stated limits. □\square

The tests check Theorem 1 within 10−910^{-9}, Theorem 2 by the zero gradient (the KKT condition of the unconstrained problem), by random perturbations of FF, by a grid search over each column of FF for real 2×22 \times 2 channels and by the closed form of the minimum, Theorem 3 at α=10−10\alpha = 10^{-10} and α=1010\alpha = 10^{10}, and the example values of the page.

Complexity

Lines L2 and L3 cost K2MK^2 M multiplications. Line L4 costs O(K3)O(K^3) for the factorization and O(K2M)O(K^2 M) for the solves, or O(M3+M2K)O(M^3 + M^2 K) with the push-through form. Line L5 costs O(MK)O(M K). The total is O(K2M+K3)O(K^2 M + K^3) per channel realization, with O(MK)O(M K) extra space, the same as zero forcing.

Properties

  • Minimum sum MSE. Among linear precoders with power PP and a common receive scale, RZF has the smallest sum MSE (theorem).
  • Always defined. HHH+αIH H^H + \alpha I is invertible for every HH when α>0\alpha > 0, including K>MK > M.
  • Between two extremes. α→0\alpha \to 0 gives zero forcing, and α→∞\alpha \to \infty gives beams along each user's channel (theorem).
  • Needs the noise level. Unlike zero forcing, RZF uses N0/PN_0 / P. A wrong value moves it toward one of the two extremes.
  • Residual interference. HWH W is not diagonal. If α\alpha stays fixed while PP grows, the SINR of each user stops at a finite value. With α=KN0/P\alpha = K N_0 / P, α\alpha falls with PP, and for K≤MK \le M and a channel of full row rank the sum rate grows like Klog⁡2PK \log_2 P.
  • Large K=MK = M. Peel, Hochwald and Swindlehurst showed that the sum rate of RZF grows linearly with K=MK = M, while plain channel inversion does not.

Variants and improvements

  • Per-user regularization. With unequal path losses or noise levels, use HH(HHH+diag(αk))−1H^H (H H^H + \mathrm{diag}(\alpha_k))^{-1} or the general MMSE form with a weight per user.
  • Imperfect channel knowledge. Add the estimation error variance to α\alpha. The large-system analysis of RZF gives the best α\alpha for a given error level.
  • Regularized vector perturbation. Perturb the data by an integer vector before the regularized inverse; see vector perturbation precoding.
  • Weighted MMSE. Replace the sum MSE by a weighted sum of MSEs with weights updated from the rates; this gives a local optimum of the weighted sum rate; see weighted MMSE precoding.
  • Multi-antenna users. Regularized block diagonalization applies the same idea to block diagonalization.

When to use it

Use RZF as the default linear precoder in a multiuser downlink when the base station knows the channel and the noise level, especially when KK is close to MM or when the SNR is low or moderate. It costs the same as zero forcing and is never worse than it in sum MSE. At very high SNR with K≪MK \ll M, zero forcing and RZF are nearly the same. When the sum rate itself must be maximized with user weights, start from RZF and refine it with weighted MMSE precoding.

Pitfalls

  • The name "MMSE precoding". It is used for RZF, for the transmit Wiener filter with a common scale (the same thing), and for other designs with per-user receive gains or with power constraints per antenna. Check the cost function before comparing results.
  • Not the sum rate optimum. α=KN0/P\alpha = K N_0 / P minimizes the sum MSE, not the sum rate. On the example channel at P=1P = 1, α=3\alpha = 3 gives a sum rate of 1.741, a little more than the 1.737 of α=2\alpha = 2.
  • Wrong regularization. Using N0N_0 instead of KN0/PK N_0 / P, or the SNR in dB, gives a precoder that is close to one of the extremes.
  • Normalization. Normalizing each column of FF separately changes the precoder. Line L5 uses one common scale.
  • Stale channel. As for zero forcing, an old channel estimate leaves interference that grows with PP.

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.

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)
regularized_zero_forcing_precoding.py 57 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/regularized-zero-forcing-precoding/. The authors are listed in prov/E77HBP.jsonl.

"""Regularized zero-forcing (RZF) precoding for the multiuser MISO downlink.

User k receives y_k = h_k^H x + w_k with w_k ~ CN(0, N0). The K by M matrix H
has row k equal to h_k^H. The transmitter sends x = W s with E[s s^H] = I and
tr(W^H W) = P, where

    F = H^H (H H^H + alpha I)^(-1),   W = beta F,   beta = sqrt(P / ||F||_F^2),

and alpha = K N0 / P by default. Every user scales its signal by 1 / beta.
With this alpha, F minimizes the sum MSE ||I - H F||_F^2 + (K N0 / P) ||F||_F^2
(the transmit Wiener filter). alpha -> 0 gives the zero-forcing channel
inversion and alpha -> infinity gives a precoder along H^H.
"""

import math

import cbb


def rzf_precoder(h: list[list[complex]], p_total: float, n0: float, alpha: float | None = None):
    """The RZF precoder of the K by M channel h. Returns (w, beta, f)."""
    k_users = len(h)
    if alpha is None:
        alpha = k_users * n0 / p_total  # @line L1
    g = cbb.matmul(h, cbb.herm(h))  # @line L2
    for i in range(k_users):
        g[i][i] += alpha  # @line L3
    f = cbb.herm(cbb.solve(g, h))  # @line L4
    # solve(g, h) = (H H^H + alpha I)^(-1) H, and its conjugate transpose is F.
    beta = math.sqrt(p_total / cbb.norm2(f))  # @line L5
    w = cbb.scale(beta, f)
    return w, beta, f  # @line L6


def sum_mse(h: list[list[complex]], f: list[list[complex]], p_total: float, n0: float) -> float:
    """E||s - y / beta||^2 = ||I - H F||_F^2 + (K N0 / P) ||F||_F^2 for W = beta F with tr(W^H W) = P."""
    k_users = len(h)
    e = cbb.sub(cbb.eye(k_users), cbb.matmul(h, f))
    return cbb.norm2(e) + k_users * n0 / p_total * cbb.norm2(f)


def sinr(h: list[list[complex]], w: list[list[complex]], n0: float) -> list[float]:
    """SINR_k = |h_k^H w_k|^2 / (sum over j != k of |h_k^H w_j|^2 + N0)."""
    e = cbb.matmul(h, w)
    out = []
    for k in range(len(h)):
        sig = abs(e[k][k]) ** 2
        out.append(sig / (sum(abs(x) ** 2 for x in e[k]) - sig + n0))
    return out


def sum_rate(h: list[list[complex]], w: list[list[complex]], n0: float) -> float:
    """The sum rate sum log2(1 + SINR_k) in bits per channel use."""
    return sum(math.log2(1.0 + s) for s in sinr(h, w, n0))
test_regularized_zero_forcing_precoding.py 130 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/regularized-zero-forcing-precoding/. The authors are listed in prov/E77HBP.jsonl.

import math
import random

import cbb
from regularized_zero_forcing_precoding import rzf_precoder, sinr, sum_mse, sum_rate


def rand_h(rng: random.Random, k: int, m: int) -> list[list[complex]]:
    return [[cbb.cn(rng, 1.0) for _ in range(m)] for _ in range(k)]


def max_abs(a: list[list[complex]]) -> float:
    return max(abs(x) for row in a for x in row)


def test_example() -> None:
    h = [[2, 1], [1, 1]]
    w, beta, f = rzf_precoder(h, 10.0, 1.0)
    want_f = [[1.4 / 2.44, -0.8 / 2.44], [-0.8 / 2.44, 2.2 / 2.44]]
    assert max_abs(cbb.sub(f, want_f)) < 1e-12
    assert abs(beta - math.sqrt(10 / (8.08 / 2.44**2))) < 1e-12
    s = sinr(h, w, 1.0)
    assert abs(s[0] - 3.4247) < 5e-5 and abs(s[1] - 1.6781) < 5e-5
    assert abs(sum_rate(h, w, 1.0) - 3.5668) < 5e-5
    assert abs(sum_mse(h, f, 10.0, 1.0) - 0.2 * 7.4 / 2.44) < 1e-12


def test_power_constraint() -> None:
    rng = random.Random(1)
    for k, m in [(1, 1), (2, 2), (3, 5), (4, 4), (8, 8)]:
        h = rand_h(rng, k, m)
        pt = rng.uniform(0.1, 100.0)
        w, _, _ = rzf_precoder(h, pt, rng.uniform(0.1, 2.0))
        assert abs(cbb.norm2(w) - pt) < 1e-9 * pt


def test_stationarity_kkt() -> None:
    # The gradient of ||I - H F||^2 + alpha ||F||^2 is H^H (H F - I) + alpha F; it vanishes at the optimum.
    rng = random.Random(2)
    for k, m in [(2, 2), (3, 4), (4, 8)]:
        h = rand_h(rng, k, m)
        pt, n0 = 5.0, 0.7
        alpha = k * n0 / pt
        _, _, f = rzf_precoder(h, pt, n0)
        grad = cbb.add(cbb.matmul(cbb.herm(h), cbb.sub(cbb.matmul(h, f), cbb.eye(k))), cbb.scale(alpha, f))
        assert max_abs(grad) < 1e-9


def test_perturbations_increase_the_mse() -> None:
    rng = random.Random(3)
    h = rand_h(rng, 3, 4)
    pt, n0 = 4.0, 1.0
    _, _, f = rzf_precoder(h, pt, n0)
    best = sum_mse(h, f, pt, n0)
    for _ in range(200):
        d = [[cbb.cn(rng, 1e-2) for _ in range(3)] for _ in range(4)]
        assert sum_mse(h, cbb.add(f, d), pt, n0) >= best - 1e-12


def test_grid_search_real_two_users() -> None:
    # The sum MSE separates over the columns of F. For a real 2 by 2 channel,
    # a grid over each real column finds no better value than the closed form.
    rng = random.Random(4)
    for _ in range(3):
        h = [[rng.gauss(0, 1) for _ in range(2)] for _ in range(2)]
        pt, n0 = 3.0, 1.0
        alpha = 2 * n0 / pt
        _, _, f = rzf_precoder(h, pt, n0)
        best = sum_mse(h, f, pt, n0)
        grid_total = 0.0
        for k in range(2):
            fk = [f[0][k].real, f[1][k].real]
            col_best = math.inf
            for i in range(-60, 61):
                for j in range(-60, 61):
                    a, b = fk[0] + i * 0.02, fk[1] + j * 0.02
                    e0 = (1 if k == 0 else 0) - (h[0][0] * a + h[0][1] * b)
                    e1 = (1 if k == 1 else 0) - (h[1][0] * a + h[1][1] * b)
                    col_best = min(col_best, e0 * e0 + e1 * e1 + alpha * (a * a + b * b))
            grid_total += col_best
        assert best <= grid_total + 1e-12
        assert grid_total - best < 1e-3


def test_minimum_mse_closed_form() -> None:
    # The minimum is alpha tr((H H^H + alpha I)^(-1)).
    rng = random.Random(5)
    for k, m in [(2, 2), (3, 6), (5, 5)]:
        h = rand_h(rng, k, m)
        pt, n0 = 8.0, 1.0
        alpha = k * n0 / pt
        _, _, f = rzf_precoder(h, pt, n0)
        g = cbb.matmul(h, cbb.herm(h))
        for i in range(k):
            g[i][i] += alpha
        gi = cbb.inv(g)
        want = alpha * sum(gi[i][i].real for i in range(k))
        assert abs(sum_mse(h, f, pt, n0) - want) < 1e-10


def test_limits_zero_forcing_and_matched_beams() -> None:
    rng = random.Random(6)
    h = rand_h(rng, 3, 4)
    hh = cbb.herm(h)
    # alpha -> 0: H W is diagonal (zero forcing with a common scale).
    w, _, _ = rzf_precoder(h, 1.0, 1.0, alpha=1e-10)
    e = cbb.matmul(h, w)
    assert max(abs(e[i][j]) for i in range(3) for j in range(3) if i != j) < 1e-8
    assert max(abs(e[i][i] - e[0][0]) for i in range(3)) < 1e-8
    # alpha -> infinity: W is proportional to H^H.
    w, _, _ = rzf_precoder(h, 1.0, 1.0, alpha=1e10)
    s = math.sqrt(1.0 / cbb.norm2(hh))
    assert max_abs(cbb.sub(w, cbb.scale(s, hh))) < 1e-8


def test_beats_channel_inversion_on_average() -> None:
    # With K = M = 4 in Rayleigh fading, channel inversion has a poor average SNR, and RZF is much better.
    rng = random.Random(7)
    t, pt, n0 = 100, 10.0, 1.0
    rzf = zf = 0.0
    for _ in range(t):
        h = rand_h(rng, 4, 4)
        w, _, _ = rzf_precoder(h, pt, n0)
        rzf += sum_rate(h, w, n0)
        w, _, _ = rzf_precoder(h, pt, n0, alpha=1e-12)
        zf += sum_rate(h, w, n0)
    assert rzf / t > zf / t + 1.0

History

Linear transmit filters that minimize an MSE were studied for multiuser and MIMO systems in the early 2000s. Peel, Hochwald and Swindlehurst (2005) showed that plain channel inversion has a poor sum rate when the number of users equals the number of antennas, and proposed the regularized inverse with α=K/ρ\alpha = K / \rho, which they found to maximize the SINR in a large system. In the same year Joham, Utschick and Nossek gave a unified treatment of linear transmit processing and derived the same filter as the transmit Wiener filter. Later work by many groups analyzed RZF with random matrix theory for large arrays and imperfect channel knowledge.

References

  1. Christian B. Peel, Bertrand M. Hochwald and A. Lee Swindlehurst, A vector-perturbation technique for near-capacity multiantenna multiuser communication, Part I: channel inversion and regularization, IEEE Transactions on Communications 53(1), 195-202, 2005, the regularized inverse H^H (H H^H + alpha I)^(-1), the choice alpha = K / rho and its sum rate compared with channel inversion
  2. Michael Joham, Wolfgang Utschick and Josef A. Nossek, Linear transmit processing in MIMO communications systems, IEEE Transactions on Signal Processing 53(8), 2700-2712, 2005, the transmit Wiener filter, which minimizes the MSE under a total power constraint with a common receive gain
  3. Bertrand M. Hochwald, Christian B. Peel and A. Lee Swindlehurst, A vector-perturbation technique for near-capacity multiantenna multiuser communication, Part II: perturbation, IEEE Transactions on Communications 53(3), 537-544, 2005, the regularized form of vector perturbation, which applies the same inverse after the perturbation

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