Algorithmcore
Maximum ratio transmission
Also called MRT, conjugate beamforming.
Sends one stream along the conjugate of the channel vector, the transmit dual of maximal ratio combining.
- Time
- O(M K) worst
- Space
- O(M K) extra
- Counts
- time mimo O(M^2 N + t M^2) worst
- Where
- K = the number of users; M = the number of transmit antennas; N = the number of receive antennas; t = the number of power iterations
- Model
- Real RAM
- Properties
- deterministiclinearneeds channel at transmitternot needs noise leveloptimal single user single stream
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Titus K. Y. Lo, 1999
Maximum ratio transmission (MRT) is the transmitter that sends one stream from antennas so that the copies add in phase at the receiver. For the channel it sends , which gives the largest possible SNR for the power . It is the transmit dual of maximal ratio combining: MRC weights the receive antennas by the conjugate channel, MRT weights the transmit antennas by it, and both give the gain and the diversity order in i.i.d. Rayleigh fading. With several receive antennas MRT sends along the top eigenvector of ; this is the one-stream case of SVD precoding, which sends up to streams. With single-antenna users, MRT gives each user the beam and ignores the interference between users; this is called conjugate beamforming. Zero-forcing precoding removes that interference at the cost of a smaller beam gain, and regularized zero-forcing precoding moves between the two. When the transmitter knows only a few feedback bits about , codebook-based precoding picks the best beam from a fixed set instead.
In plain words
Several antennas send the same symbol to one receiver. Each signal reaches the receiver with its own delay and strength. The transmitter knows these effects and corrects the phase of each antenna in advance, so all the copies arrive in step and add up. It also puts more power on the antennas with a strong path to the receiver and less on the weak ones. The result is the strongest possible signal at the receiver for the given total power. With many users, the transmitter does the same for each user and accepts that each beam leaks a little to the other users.
The problem
The base station has antennas. In the single-user case the receiver has one antenna and gets with known at the transmitter and . The transmitter sends one unit-power symbol as with , and it wants the largest SNR . With receive antennas the model is with , and the receiver combines with a unit vector . In the multiuser downlink, user gets and ; MRT here is a simple rule, not the solution of an optimization problem.
The algorithm
MRT(h, P)- 1
a ← ‖h‖ - 2
return f ← √P h / a ▷ hᴴ f = √P ‖h‖, a real number MRT-MIMO(H, P)- 3
G ← Hᴴ H - 4
repeat v ← G v / ‖G v‖ until v stops changing ▷ power iteration - 5
λ ← vᴴ G v ▷ the top eigenvalue - 6
c ← H v / ‖H v‖; return (√P v, c, λ) ▷ c is the receive combiner CONJUGATE-BEAMFORMING(h₁, ..., h_K, P)- 7
for each user k: w_k ← MRT(h_k, P/K)
Lines L1 and L2 are the whole single-user algorithm. Line L4 needs a start vector that is not orthogonal to the top eigenvector; the implementation starts once from each nonzero column of and keeps the best result, because at least one column has a component along that eigenvector. Any eigenvalue routine or an SVD of can replace line L4. Line L7 splits the power equally; other splits are a matter of power control.
Example
Take , , and . Then , and line L2 gives . Antenna contributes to the received amplitude, so the three contributions , and are positive real numbers and add in phase to . The SNR is 7, or 8.451 dB. Two simpler schemes with the same power do worse:
| scheme | in dB | |
|---|---|---|
| MRT, | 7 | 8.451 |
| the strongest antenna only, | 4 | 6.021 |
| equal amplitudes and no phase correction, | 3 | 4.771 |
The last row shows why the phase matters: without the phase correction the three terms do not add up in step.
With two receive antennas and , line L3 gives , with the top eigenvalue and . The SNR gain is 2.618 (4.18 dB). The best single transmit antenna is the second one, whose column has squared norm 2 (3.01 dB).
Correctness
The proof is in proofs/correctness.md. Theorem 1 shows by the Cauchy-Schwarz inequality that for every with , with equality exactly for along . Theorem 2 shows that with receive antennas the best SNR is , reached by the top eigenvector and the MRC combiner of line L6, and Lemma 1 shows that the power iteration of line L4 finds it from at least one of its starts. Theorem 3 shows that in i.i.d. Rayleigh fading the MRT SNR has the same Gamma law as MRC over branches, which gives the BPSK error rate for at 10 dB. Lemma 2 shows that conjugate beamforming meets the power constraint and that the normalized interference between two independent isotropic channels has the mean .
Proof: MRT maximizes the received SNR, its MIMO form reaches the top eigenvalue of H^H H, and its SNR law in Rayleigh fading is that of maximal ratio combiningfull
The single-antenna receiver sees with , and one unit-power symbol sent as with . Lines L1 and L2 set .
Theorem 1 (best beamformer for one receive antenna). For every with , the SNR is at most , and the MRT vector reaches this value. Any optimal equals for some phase .
Proof. By the Cauchy-Schwarz inequality, . Equality in Cauchy-Schwarz holds only if is a multiple of , and equality in the second step needs . For the MRT vector, , a positive real number, so the SNR is .
So the receiver gets : the contributions of all antennas add in phase, and the SNR gain over one antenna with the same total power is .
Theorem 2 (several receive antennas). Let with , , with , and a receive vector with , so the SNR after combining is . The largest value over and is . It is reached by with a unit top eigenvector of and , the output of lines L5 and L6.
Proof. For a fixed , Cauchy-Schwarz gives , with equality for ; this is maximal ratio combining. Then . Write in an orthonormal eigenbasis of the Hermitian matrix , with the eigenvalues : gives , with equality for .
Lemma 1 (power iteration). Let and let the start vector have . Then approaches the line through , with an error angle whose tangent is at most , where is the angle between and . Among the nonzero columns of , at least one is such a start.
Proof. Write with . Then , and the ratio of the norm of the part orthogonal to to the part along is . The normalization and the phase fix of line L4 do not change the line. For the start: . Since is not zero, some entry is not zero, and for that column of is a valid start. The code runs from every nonzero column and keeps the largest Rayleigh quotient , which is the result of that good start or a value at least as large; by the proof of Theorem 2 no unit vector has a Rayleigh quotient above .
If , every unit vector of the top eigenspace is optimal, and power iteration converges to one of them.
Theorem 3 (SNR law in Rayleigh fading). If the entries of are i.i.d. , the MRT SNR has the Gamma distribution with shape and mean , the same law as the output SNR of maximal ratio combining over branches. With BPSK and , the bit error probability is
so the diversity order is .
Proof. is a sum of independent unit exponentials, which is Gamma with shape . By Theorem 1 the receiver sees , a real positive gain on BPSK, so the conditional error probability is . Its average over the Gamma law is the classical MRC result for independent Rayleigh branches with the average branch SNR , which is the formula above.
For and dB the formula gives , the MRC check value of the area.
Lemma 2 (multiuser interference with conjugate beamforming). For users with (line L7), the total power is , and the interference that user gets from user is . It vanishes if the channels are orthogonal. If and are independent with i.i.d. entries, the unit vectors and satisfy .
Proof. . The interference term is , which is the expression above. For the mean, condition on . The vector is uniform on the unit sphere of and independent of , so . By symmetry , and its trace is , so and .
So the interference relative to the signal power falls as ; this is the favorable propagation effect that makes conjugate beamforming work in massive MIMO.
The tests check Theorem 1 against random unit vectors and a grid over all unit vectors of , the example values 7, 4 and 3, Theorem 2 by the eigenvector equation, the combined gain and random unit vectors, Lemma 1 on a matrix whose largest column is orthogonal to the top eigenvector, Theorem 3 by a BPSK error count with a Wilson interval, and Lemma 2 by the power, orthogonal channels and the sample mean of .
Complexity
Lines L1 and L2 cost , and conjugate beamforming for users costs , with space for the precoder. The MIMO form costs for and per power iteration, so for iterations. The number of iterations grows with . MRT needs no matrix inversion, which is its main advantage over zero forcing when and are large.
Properties
- Optimal for one stream to one antenna. No other beamformer gives a larger SNR (theorem).
- Array gain and diversity. The SNR is , which has mean in i.i.d. Rayleigh fading and diversity order .
- Same law as MRC. The SNR distributions of MRT with transmit antennas and MRC with receive antennas are the same. This is the uplink-downlink duality in its simplest form.
- No noise level needed. The beam depends only on .
- Interference in the multiuser case. Conjugate beamforming ignores the other users, so at high SNR the SINR is limited by interference and the sum rate saturates, unless grows.
- Local operation. Each antenna needs only its own channel coefficients for its weight, up to the common normalization. This makes MRT the natural precoder for distributed arrays such as cell-free massive MIMO.
Variants and improvements
- MIMO MRT. Send along the top eigenvector of and combine with MRC at the receiver (lines L3 to L6). This is SVD precoding with one stream.
- Conjugate beamforming. One MRT beam per user with a share of the power (line L7). In massive MIMO with , favorable propagation makes the beams nearly orthogonal.
- Equal gain transmission. Keep only the phases: . Every antenna sends the same power, which suits power amplifiers with a per-antenna limit.
- Quantized MRT. Pick the beam from a codebook known at both ends; see codebook-based precoding.
- Zero forcing and regularized zero forcing. Replace by the corresponding column of a channel inverse to remove or reduce the interference between users.
- Statistical MRT. With only the transmit correlation matrix known, send along its top eigenvector.
When to use it
Use MRT for a single stream to one user when the transmitter has a reliable channel estimate, for example from reverse-link pilots in time division duplex. In the multiuser downlink, use conjugate beamforming when is much larger than , at low SNR where noise dominates interference, or when the antennas are distributed and cannot share their channel estimates. At high SNR with close to , interference dominates, and zero forcing or regularized zero forcing give a much higher sum rate.
Pitfalls
- Wrong conjugation. With the model the beam is along . With the model it is along . Mixing the two conventions destroys the phase alignment.
- Stale channel. A phase error on the estimate of reduces the gain. MRT needs the channel at the time of transmission, not at the time of the pilot.
- Interference limit. In the multiuser case the SINR does not grow without bound with . Plan the system with the SINR formula, not with the SNR .
- Power iteration start. A fixed start vector can be orthogonal to the top eigenvector, and then the iteration converges to the wrong eigenvalue. Start from several vectors, or use an eigenvalue routine.
- Two names for two things. The 1999 paper treats one user with several receive antennas. Conjugate beamforming for many users is a later use of the same weights.
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.
# 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)
maximum_ratio_transmission.py 99 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/maximum-ratio-transmission/. The authors are listed in prov/17KZND.jsonl.
"""Maximum ratio transmission (MRT).
Single user, one receive antenna: the received signal is y = h^H x + w with
h in C^M and w ~ CN(0, N0). MRT sends x = sqrt(P) h / ||h|| s, which gives the
SNR P ||h||^2 / N0, the largest possible for the power P.
Single user, several receive antennas: y = H x + w. MRT sends along the
principal right singular vector v of H (the top eigenvector of H^H H), found
here by power iteration, and the receiver combines with H v. The SNR is
lambda_max(H^H H) P / N0.
Multiuser downlink (conjugate beamforming): y_k = h_k^H x + w_k for K users
and x = sum_k w_k s_k with w_k = sqrt(P / K) h_k / ||h_k||.
"""
import math
import cbb
def mrt_vector(h: list[complex], p_total: float) -> list[complex]:
"""The MRT precoder sqrt(P) h / ||h|| for the channel y = h^H x + w."""
nrm = math.sqrt(cbb.norm2(h)) # @line L1
if nrm == 0.0:
raise ValueError("the channel is zero")
return [math.sqrt(p_total) * x / nrm for x in h] # @line L2
def principal_vector(h: list[list[complex]], tol: float = 1e-14, max_iter: int = 10000):
"""The top eigenvalue and a unit eigenvector of G = H^H H, by power iteration.
Returns (lam, v). The iteration starts once from each nonzero column of G
and keeps the best result. The columns span the range of G, which holds
the top eigenvector, so at least one start is not orthogonal to it.
"""
g = cbb.matmul(cbb.herm(h), h) # @line L3
n = len(g)
best_lam, best_v = -1.0, None
for k in range(n):
v = [g[i][k] for i in range(n)]
nrm = math.sqrt(cbb.norm2(v))
if nrm == 0.0:
continue
v = [x / nrm for x in v]
for _ in range(max_iter): # @line L4
gv = cbb.matvec(g, v)
nrm = math.sqrt(cbb.norm2(gv))
if nrm == 0.0:
break
v_next = [x / nrm for x in gv]
# Fix the phase so that the iteration converges as a vector, not only up to a phase.
ref = max(range(n), key=lambda i: abs(v_next[i]))
ph = abs(v_next[ref]) / v_next[ref]
v_next = [x * ph for x in v_next]
diff = math.sqrt(sum(abs(a - b) ** 2 for a, b in zip(v_next, v)))
v = v_next
if diff < tol:
break
lam = cbb.dot(v, cbb.matvec(g, v)).real
if lam > best_lam:
best_lam, best_v = lam, v
if best_v is None:
raise ValueError("the channel is zero")
return best_lam, best_v
def mrt_mimo(h: list[list[complex]], p_total: float):
"""MRT for y = H x + w. Returns (x_dir, combiner, gain).
x_dir = sqrt(P) v is the precoder, combiner = H v / ||H v|| is the unit
receive vector, and gain = lambda_max(H^H H), so the SNR is gain P / N0.
"""
lam, v = principal_vector(h) # @line L5
hv = cbb.matvec(h, v)
nrm = math.sqrt(cbb.norm2(hv))
combiner = [x / nrm for x in hv] # @line L6
return [math.sqrt(p_total) * x for x in v], combiner, lam
def conjugate_beamforming(hs: list[list[complex]], p_total: float) -> list[list[complex]]:
"""The multiuser MRT precoder. hs[k] is h_k; column k of the M by K result is w_k."""
k_users = len(hs)
cols = [mrt_vector(h, p_total / k_users) for h in hs] # @line L7
m = len(hs[0])
return [[cols[k][i] for k in range(k_users)] for i in range(m)]
def sinr(hs: 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), for columns w_j of w."""
k_users = len(hs)
cols = [[row[j] for row in w] for j in range(len(w[0]))]
out = []
for k in range(k_users):
gains = [abs(cbb.dot(hs[k], c)) ** 2 for c in cols]
out.append(gains[k] / (sum(gains) - gains[k] + n0))
return out
test_maximum_ratio_transmission.py 146 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/maximum-ratio-transmission/. The authors are listed in prov/17KZND.jsonl.
import cmath
import math
import random
import cbb
from maximum_ratio_transmission import conjugate_beamforming, mrt_mimo, mrt_vector, principal_vector, sinr
def rand_vec(rng: random.Random, n: int) -> list[complex]:
return [cbb.cn(rng, 1.0) for _ in range(n)]
def snr(h: list[complex], x: list[complex], n0: float) -> float:
return abs(cbb.dot(h, x)) ** 2 / n0
def test_example_vector() -> None:
h = [1 + 1j, 2, -1j]
x = mrt_vector(h, 1.0)
assert abs(cbb.norm2(x) - 1.0) < 1e-12
assert abs(snr(h, x, 1.0) - 7.0) < 1e-12
assert abs(cbb.db(7.0) - 8.451) < 5e-4
# Antenna selection: all power on the strongest antenna, |h_2|^2 = 4.
sel = max(abs(v) ** 2 for v in h)
assert abs(sel - 4.0) < 1e-12
# Equal-phase sending: x = (1, 1, 1) / sqrt(3).
eq = [1 / math.sqrt(3)] * 3
assert abs(snr(h, eq, 1.0) - 3.0) < 1e-12
def test_mrt_beats_every_unit_vector() -> None:
# Cauchy-Schwarz: |h^H x|^2 <= ||h||^2 ||x||^2, with equality for x along h.
rng = random.Random(1)
for m in range(1, 9):
h = rand_vec(rng, m)
best = snr(h, mrt_vector(h, 1.0), 1.0)
assert abs(best - cbb.norm2(h)) < 1e-10
for _ in range(200):
x = rand_vec(rng, m)
x = cbb.scale(1 / math.sqrt(cbb.norm2(x)), x)
assert snr(h, x, 1.0) <= best + 1e-10
def test_grid_search_two_antennas() -> None:
# Every unit vector of C^2 is, up to a common phase, (cos a, sin a e^(j b)).
rng = random.Random(2)
for _ in range(3):
h = rand_vec(rng, 2)
best = cbb.norm2(h)
grid = 0.0
for i in range(201):
a = math.pi / 2 * i / 200
for k in range(200):
b = 2 * math.pi * k / 200
x = [math.cos(a), math.sin(a) * cmath.exp(1j * b)]
grid = max(grid, snr(h, x, 1.0))
assert grid <= best + 1e-12
assert best - grid < 1e-3 * best
def test_principal_vector_example() -> None:
lam, v = principal_vector([[1, 1], [0, 1]])
assert abs(lam - (3 + math.sqrt(5)) / 2) < 1e-12
assert abs(lam - 2.618) < 5e-4
assert abs(cbb.norm2(v) - 1) < 1e-12
def test_principal_vector_when_the_largest_column_misses_it() -> None:
# H^H H = e1 e1^T + 1.1 u u^T with u = (0, 1, 1) / sqrt(2). The largest column of
# H^H H is e1, which is orthogonal to u, so one start from it would return 1.0.
a = math.sqrt(0.55)
lam, v = principal_vector([[1, 0, 0], [0, a, a]])
assert abs(lam - 1.1) < 1e-12
assert abs(abs(v[1]) - 1 / math.sqrt(2)) < 1e-9 and abs(v[0]) < 1e-9
def test_mimo_gain_is_top_eigenvalue() -> None:
rng = random.Random(3)
for m, n in [(2, 2), (3, 2), (2, 4), (4, 4)]:
for _ in range(5):
h = [rand_vec(rng, n) for _ in range(m)]
x, comb, lam = mrt_mimo(h, 1.0)
g = cbb.matmul(cbb.herm(h), h)
gv = cbb.matvec(g, x)
assert max(abs(a - lam * b) for a, b in zip(gv, x)) < 1e-9
# The combined gain |c^H H x|^2 equals lambda_max.
assert abs(abs(cbb.dot(comb, cbb.matvec(h, x))) ** 2 - lam) < 1e-9
# No unit vector gives more: ||H x||^2 <= lambda_max.
for _ in range(50):
z = rand_vec(rng, n)
z = cbb.scale(1 / math.sqrt(cbb.norm2(z)), z)
assert cbb.norm2(cbb.matvec(h, z)) <= lam + 1e-9
# The trace bound: lambda_max >= tr(G) / n.
assert lam >= sum(g[i][i].real for i in range(n)) / n - 1e-9
def test_bpsk_error_rate_matches_two_branch_mrc() -> None:
# MRT with M = 2 in i.i.d. Rayleigh fading has the same SNR law as MRC with L = 2.
rng = random.Random(4)
p_total, n0 = 10.0, 1.0
mu = math.sqrt(10.0 / 11.0)
exact = ((1 - mu) / 2) ** 2 * (1 + 2 * (1 + mu) / 2)
assert abs(exact - 1.5991e-3) < 5e-7
n, errors = 100000, 0
s0 = math.sqrt(n0 / 2)
for _ in range(n):
h = [complex(rng.gauss(0, 0.7071067811865476), rng.gauss(0, 0.7071067811865476)) for _ in range(2)]
nrm = math.sqrt(abs(h[0]) ** 2 + abs(h[1]) ** 2)
s = 1.0 if rng.random() < 0.5 else -1.0
# y = h^H x + w with x = sqrt(P) h / ||h|| s, so y = sqrt(P) ||h|| s + w.
y = math.sqrt(p_total) * nrm * s + rng.gauss(0, s0)
if (y >= 0) != (s > 0):
errors += 1
lo, hi = cbb.wilson(errors, n)
assert lo <= exact <= hi
assert exact * n >= 100
def test_conjugate_beamforming_power_and_orthogonal_users() -> None:
rng = random.Random(5)
hs = [rand_vec(rng, 8) for _ in range(4)]
w = conjugate_beamforming(hs, 6.0)
assert abs(cbb.norm2(w) - 6.0) < 1e-9
# Orthogonal channels: no interference, SINR_k = (P/K) ||h_k||^2 / N0.
hs = [[2.0, 0, 0], [0, 1j, 0], [0, 0, 1 - 1j]]
w = conjugate_beamforming(hs, 3.0)
got = sinr(hs, w, 0.5)
for k in range(3):
assert abs(got[k] - 1.0 * cbb.norm2(hs[k]) / 0.5) < 1e-12
def test_favorable_propagation_mean() -> None:
# For independent isotropic unit vectors in C^M, E|u^H v|^2 = 1/M.
rng = random.Random(6)
for m in (2, 4, 8):
t = 4000
acc = 0.0
for _ in range(t):
u, v = rand_vec(rng, m), rand_vec(rng, m)
acc += abs(cbb.dot(u, v)) ** 2 / (cbb.norm2(u) * cbb.norm2(v))
mean = acc / t
# |u^H v|^2 is Beta(1, M - 1), with standard deviation below 1/M.
assert abs(mean - 1 / m) < 5 * (1 / m) / math.sqrt(t)
History
Lo (1999) named maximum ratio transmission, gave the joint transmit and receive weights for several receive antennas, and showed that it gives the same diversity as maximal ratio combining. With the rise of massive MIMO after Marzetta's work of 2010, the same rule for many users, under the name conjugate beamforming, became the simplest downlink precoder of large arrays, and Ngo, Larsson and Marzetta (2013) compared its energy and spectral efficiency with zero forcing.
References
- Titus K. Y. Lo, Maximum ratio transmission, IEEE Transactions on Communications 47(10), 1458-1461, 1999, the transmit weights proportional to the conjugate channel, the receive combining and the diversity analysis
- David Tse and Pramod Viswanath, Fundamentals of Wireless Communication, Cambridge University Press, 2005, Section 5.3.2, MISO channel (transmit beamforming along the channel vector and its capacity log(1 + P ||h||^2 / N0))
- Hien Quoc Ngo, Erik G. Larsson and Thomas L. Marzetta, Energy and spectral efficiency of very large multiuser MIMO systems, IEEE Transactions on Communications 61(4), 1436-1449, 2013, the analysis of maximum ratio processing in very large arrays and the comparison with zero forcing
- Thomas L. Marzetta, Erik G. Larsson, Hong Yang and Hien Quoc Ngo, Fundamentals of Massive MIMO, Cambridge University Press, 2016, the chapters on downlink linear precoding (conjugate beamforming and its effective SINR)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 17KZND Edit this page History Report an error Markdown