Algorithmadvanced
D-BLAST
Also called diagonal BLAST.
Spreads each coded layer diagonally over all transmit antennas and time, so that MMSE nulling and cancelling reaches the outage capacity of slow fading, minus a start-up rate loss.
- Solves
- MIMO detection
- Time
- O(L n^3 m + L n^4 + L B n^2 m + L B n M) worst
- Space
- O(L B n + n m) extra
- Where
- B = the number of symbols in a block; L = the number of layers in a frame; M = the constellation size; m = the number of receive antennas; n = the number of transmit antennas
- Model
- Real RAM
- Properties
- deterministicnot exact mlnot linearmiddle layer sinr sum equals log det
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Gerard J. Foschini, 1996
D-BLAST (diagonal Bell Laboratories layered space-time) is a transmission scheme with a matching receiver for spatial multiplexing over a slow fading channel. The transmitter cuts each coded layer into blocks and sends block on antenna one block time after block , so every layer crosses all antennas on a diagonal of the antenna and time grid. The receiver decodes the layers one after the other. For each block it subtracts the earlier layers, which are already decoded, and nulls the later layers with the ZF or MMSE filter, as in V-BLAST. The difference from V-BLAST is the layering. In V-BLAST each stream stays on one antenna, so in slow fading a stream on a weak antenna fails even when the channel as a whole is good. In D-BLAST every layer sees every antenna, and with MMSE nulling the SINRs of the blocks of a middle layer satisfy (a theorem). So a layer code fails only when the channel is in outage, and D-BLAST reaches the outage capacity of the channel (Tse and Viswanath, Section 8.5). The price is the start-up loss: the frame needs block times for layers, so the rate is of the V-BLAST rate.
In plain words
Several antennas send at the same time. Each message is cut into pieces, and the pieces go out on the antennas in turn, one antenna after another, like a staircase. So every message uses every antenna once. The receiver reads one message at a time. It removes the messages that it already knows and blocks out the ones that it has not read yet. A message that only used one weak antenna would be lost. Here each message gets a fair share of the good and the bad antennas, so it gets through whenever the channel as a whole is good enough. The cost is a little time at the start and at the end of each frame, when some antennas are silent.
The problem
The channel is with fixed for a whole frame (slow fading), the vector sent at time , and independent over time. The transmitter has layers. Each layer is cut into blocks of symbols from a constellation of energy , or of coded symbols. Block of layer (, ) goes out on antenna at block time . So at block time , antenna sends block of layer when , and is silent otherwise. The receiver knows , and for MMSE nulling. It must find the symbols of every layer. ZF nulling needs ; MMSE nulling works for every .
The algorithm
D-BLAST-DETECT(Y, H, S, L, a) ▷ a = 0 for ZF nulling, a = N0/Es for MMSE- 1
for l ← 0 to L - 1 ▷ the layers in order - 2
for k ← 0 to n - 1 ▷ the blocks of layer l - 3
t ← l + k - 4
r ← Y_t - Σ over k' > k of h_k' x̂(layer t - k', block k') ▷ cancel earlier layers - 5
A ← {k' < k : antenna k' is active at time t} ∪ {k} ▷ later layers, nulled - 6
P ← (H_Aᴴ H_A + a I)⁻¹; z_k ← (row k of P H_Aᴴ) r, without bias - 7
γ_k ← the SNR or SINR of z_k - 8
x̂(layer l) ← DECODE(z_0, ..., z_{n-1}; γ_0, ..., γ_{n-1}) - 9
return x̂
Line L4 subtracts the antennas , which carry the layers ; the receiver has already decoded them. Line L5 collects the active antennas , which carry the later layers . Line L6 is the nulling filter of the ZF MIMO detector or the MMSE MIMO detector on these columns, and line L7 records the quality of each block, for ZF and for MMSE. Line L8 is the decoder of the layer code. It gets one output per block and a reliability per block, as for a code over parallel channels. The implementation gives two decoders: slicing each symbol alone (no code), and a repetition code, where the same symbols fill all blocks and the decoder adds the outputs with weights before slicing. The filters of lines L5 and L6 depend only on and on which antennas are active, so a receiver computes them once per channel.
Example
Take , , BPSK and the real channel . The frame has block times:
| block time | antenna 0 | antenna 1 |
|---|---|---|
| 0 | layer 0, block 0 | silent |
| 1 | layer 1, block 0 | layer 0, block 1 |
| 2 | layer 2, block 0 | layer 1, block 1 |
| 3 | silent | layer 2, block 1 |
The rate is of V-BLAST. With ZF nulling, the receiver works as follows, with SNRs in units of .
- Layer 0, block 0 at : antenna 1 is silent, so the receiver combines with alone, the maximal ratio combining SNR .
- Layer 0, block 1 at : antenna 0 carries layer 1, which is not decoded yet, so the receiver nulls it. The SNR is .
- Layer 1: at , block 0 on antenna 0 sees antenna 1, which carries layer 0. The receiver cancels it, so the SNR is again 5. At , block 1 nulls layer 2 on antenna 0 and gets 0.2.
- Layer 2: block 0 cancels layer 1 and gets 5. Block 1 at is alone and gets .
Every layer has one strong block and one weak block, so no layer depends only on the weak direction of . With MMSE nulling at dB (), the middle layer gets and , and . So a layer code can carry bit for each symbol position of a block. One layer ends at each block time, so this is bit per channel use, the full capacity of the channel with equal power, apart from the start-up loss.
Without noise, if the layers carry , and in blocks 0 and 1, the receiver gets , , and , and the ZF receiver recovers every symbol.
Correctness
The proof is in proofs/correctness.md. It shows five things. First, each layer visits each antenna once, and the frame has block times (a closed form). Second, with ZF nulling and no noise, the receiver recovers every layer (a theorem). Third, block 0 of every layer has the maximal ratio combining SNR (a theorem). Fourth, with MMSE nulling and correct decisions on the earlier layers, each layer has , and the last layers have at least this much (a theorem). Fifth, if the noise and interference of the outputs are uncorrelated, the weights give the combined SINR (a closed form). The outage statement then follows from the coding theorem for parallel Gaussian channels, as in Tse and Viswanath, Section 8.5.2.
Proof: D-BLAST visits every antenna with every layer, is exact without noise, and its middle layers see the full log-det rate with MMSE nullingfull
The channel is with fixed over the frame, columns , and independent over . Block of layer is on antenna at block time , for and . Write for ZF and for MMSE. For a set of antennas, is the matrix of their columns and .
Lemma 1 (the layer map). At block time , antenna carries at most one block, namely block of layer when . Each layer has exactly one block on each antenna. The frame uses the block times , so it has of them and carries blocks in antenna slots.
Proof. Block of layer is at . The map is one to one, and its inverse is , so each slot holds at most one block. For a fixed the antennas each occur once. The smallest time is and the largest is .
So the rate is of the rate of full streams.
Lemma 2 (who is cancelled and who is nulled). At the step for block of layer , at time , an active antenna carries the layer , and an active antenna carries the layer .
Proof. , which is less than when and more than when .
Lines L1 and L2 decode the layers in increasing order, so when the receiver reaches layer , every layer is decided. Line L4 subtracts exactly these, and line L5 nulls exactly the active antennas that carry later layers. If the earlier decisions are right, after line L4
Theorem 3 (exact without noise). With ZF nulling (, of full column rank) and for all , the receiver returns every symbol of every layer, with either decoder of line L8.
Proof. By induction over the layers. Suppose that the layers are decided correctly. By Lemma 2 and equation (1), for each block of layer . The ZF filter satisfies , so its row for antenna gives , the transmitted symbol. Slicing returns it at distance 0. With the repetition decoder, every equals the same symbol , so the weighted mean is too. So layer is decided correctly.
Lemma 4 (the SNR or SINR of a block). Assume correct earlier decisions. The output of line L6 has the SNR for ZF and the unbiased SINR for MMSE, where is the set of equation (1).
Proof. By equation (1), this is one step of nulling on the channel , so Lemma 2 of the V-BLAST proof applies with .
Theorem 5 (block 0 is maximal ratio combining). For every layer, block 0 has , and its SNR or SINR is .
Proof. For there is no antenna , so and . For ZF, . For MMSE, .
Theorem 6 (the middle layers see the full rate). With MMSE nulling and correct earlier decisions, every layer has
and every layer has a sum at least this large.
Proof. For and , , so every antenna is active and . These sets grow by one antenna from to . Read in the order , they are the sets of an MMSE-SIC run on with the order : stream is detected when the remaining set is . Theorem 6 of the V-BLAST proof holds for every order, so the sum of is .
For , some antennas are silent, so is a subset of that contains . By Lemma 3 of the V-BLAST proof, removing interferers never lowers the SINR, so each is at least its value for a middle layer, and so is the sum.
Theorem 7 (combining the blocks). Suppose that the unbiased outputs of a layer are , where is a symbol of energy repeated in all blocks, , , and the are uncorrelated. Then the weighted mean is unbiased with SINR , and no other unbiased linear combination has a larger SINR.
Proof. A combination with is unbiased and has error variance . By the Cauchy-Schwarz inequality,
so the error variance is at least , with equality when is proportional to . The SINR is divided by the error variance.
The noise terms of different blocks are independent, because the blocks of a layer are at different block times. With ZF there is no residual interference, so the condition of Theorem 7 always holds. With MMSE, the residual interference of block comes from the later layers that block nulls; it is uncorrelated between blocks when the symbols in different blocks are independent, as for or for coded symbols. For a capacity-achieving code over the blocks, the layer can be decoded when its rate is below , which by Theorem 6 is the log-det rate of . A layer then fails only when this rate is below the target rate, which is the outage event of the channel. This is the outage optimality of D-BLAST in Tse and Viswanath, Section 8.5.
Complexity
The filter of block inverts a matrix of size at most , at a cost of . Over the blocks of a layer this is . The implementation recomputes it for each of the layers; a receiver needs it only for the at most different patterns of active antennas. Each symbol of a block costs up to cancellations of length , one inner product of length , and for slicing. So a frame costs in the real RAM, plus the cost of the layer decoder, with space for the decisions and the filters.
Properties
- Every layer sees every antenna. Block of each layer is on antenna (closed form).
- Rate loss. layers need block times, a fraction of the V-BLAST rate. For and this is (closed form).
- Capacity per layer. With MMSE nulling and correct decisions on earlier layers, each middle layer sees in total (theorem). This is the rate of the channel with equal power and no channel knowledge at the transmitter.
- Outage optimal. With capacity-achieving codes over the blocks, a layer fails only when the channel is in outage, apart from the rate loss (Tse and Viswanath, Section 8.5).
- Error propagation between layers. A layer that is decoded wrong spoils the cancellation in the next layers.
- Measured gain over vertical layering. For 4-QAM with , , a repetition code over the blocks, i.i.d. Rayleigh fading per frame and dB, the test with seed 1505 runs 300 frames of 6 symbols. D-BLAST made 15 symbol errors. Vertical layering, where each antenna repeats its own symbol twice and the receiver uses MMSE V-BLAST, made 63 (measurement).
Variants and improvements
- ZF or MMSE nulling. ZF nulling needs and loses SNR on the blocks that null many layers. MMSE nulling is the version that reaches the capacity identity above (Tse and Viswanath, Section 8.3.4).
- Vertical layering. V-BLAST sends each stream on one antenna. It has no start-up loss and a simpler code structure, but in slow fading a stream on a weak antenna fails.
- Other layer patterns. Later layered schemes assign the layers to the antennas in other patterns, for example cyclic ones that keep every antenna busy. The receiver then cannot always cancel all earlier layers in one pass.
- Space-time codes. The Alamouti code and other space-time codes give diversity with a simple receiver but less multiplexing gain. The diversity-multiplexing tradeoff compares these schemes.
- Iterative receivers. Soft cancellation with a turbo loop, as in turbo equalization, reduces error propagation between layers.
When to use it
Use D-BLAST when the channel stays the same for a whole codeword (slow fading), so that a stream on one antenna can be in a deep fade for its whole length, and when frames are long, so that is much larger than and the start-up loss is small. In fast fading, or when the code is long enough to see many channel states, V-BLAST with per-stream codes reaches the same rate without the diagonal structure. For short frames, the rate loss of block times is large, so a space-time code or a joint detector is often better.
Pitfalls
- Wrong cancellation order. At block time , antenna carries an earlier layer and must be cancelled. Antenna carries a later layer and must be nulled. Mixing them up leaves interference in every block.
- Forgetting the silent antennas. At the start and the end of a frame some antennas are silent. Do not null them; the filter should only include the active antennas, or the receiver loses SNR on the edge layers.
- Ignoring the start-up loss. The rate is of the V-BLAST rate. A comparison at equal that ignores this is unfair to V-BLAST.
- Error propagation. One wrong layer spoils the next layers. Use strong codes and check each layer before cancelling it.
- Correlated interference. If two blocks of one layer null the same later layer and that layer repeats its symbols, the residual interference of the two outputs is correlated, and the combined SINR is lower than . Real codes avoid this because the symbols of different blocks differ.
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)
constel.py 117 lines
# SPDX-License-Identifier: MIT
# Shared helper of the communications pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Constellations, Gray labels and brute-force maximum likelihood detection.
Each constellation function returns a list of M complex points with unit
average energy, ordered by label: points[i] is the point whose bit label is
the integer i, and bits(i, log2 M) gives that label, most significant bit
first. The labels follow the communications area rules:
- M-PAM: the point with amplitude index m = 0, ..., M-1 (raw amplitude
M - 1 - 2m, from the most positive) gets the Gray label gray(m).
So 2-PAM maps bit 0 to +1 and bit 1 to -1.
- Square M-QAM, M = 4^k: the label is the in-phase PAM label followed by the
quadrature PAM label, each of log2(sqrt(M)) bits.
- M-PSK: the point e^(j(2 pi m / M + phase0)) gets the label gray(m).
PAM points are returned as complex numbers with zero imaginary part.
This file imports nothing from cbb.py. It holds no demapper: soft and
max-log demapping are algorithm pages of their own.
"""
import cmath
import itertools
import math
def gray(n: int) -> int:
"""The binary reflected Gray code of n: n XOR (n >> 1)."""
return n ^ (n >> 1)
def _gray_inv(g: int) -> int:
n = 0
while g:
n ^= g
g >>= 1
return n
def bits(i: int, m: int) -> list[int]:
"""The m bits of the integer i, most significant bit first."""
if i < 0 or i >= 1 << m:
raise ValueError("i does not fit in m bits")
return [(i >> (m - 1 - t)) & 1 for t in range(m)]
def _log2(m: int) -> int:
if m < 2 or m & (m - 1):
raise ValueError("M must be a power of two, at least 2")
return m.bit_length() - 1
def pam(m: int) -> list[complex]:
"""Unit-energy M-PAM, ordered by Gray label."""
_log2(m)
s = math.sqrt((m * m - 1) / 3.0)
return [complex((m - 1 - 2 * _gray_inv(lab)) / s, 0.0) for lab in range(m)]
def qam(m: int) -> list[complex]:
"""Unit-energy square M-QAM (M = 4, 16, 64, ...), ordered by label (in-phase bits first)."""
k = _log2(m)
if k % 2:
raise ValueError("square QAM needs M = 4^k")
side = 1 << (k // 2)
s = math.sqrt(2.0 * (m - 1) / 3.0)
raw = [side - 1 - 2 * _gray_inv(lab) for lab in range(side)]
return [complex(raw[lab // side], raw[lab % side]) / s for lab in range(m)]
def psk(m: int, phase0: float = 0.0) -> list[complex]:
"""Unit-energy M-PSK with first point at angle phase0, ordered by Gray label."""
_log2(m)
return [cmath.exp(1j * (2.0 * math.pi * _gray_inv(lab) / m + phase0)) for lab in range(m)]
def energy(points: list[complex]) -> float:
"""The average energy (1/M) sum |p|^2 of equally likely points."""
return sum(abs(p) ** 2 for p in points) / len(points)
def ml_detect(y: complex, points: list[complex], h: complex = 1) -> int:
"""The index of the point p that minimizes |y - h p|^2, by brute force (lowest index on a tie)."""
best, arg = math.inf, -1
for i, p in enumerate(points):
d = abs(y - h * p) ** 2
if d < best:
best, arg = d, i
return arg
def ml_vector(y: list[complex], h: list[list[complex]], points: list[complex]) -> list[int]:
"""The index vector that minimizes ||y - H x||^2 over all M^n vectors x, by brute force.
h is the m by n channel matrix as a list of rows; the result has n indices.
The first minimizer in lexicographic order of the indices wins a tie.
"""
n = len(h[0])
best, arg = math.inf, None
for idx in itertools.product(range(len(points)), repeat=n):
x = [points[i] for i in idx]
d = 0.0
for yi, row in zip(y, h):
d += abs(yi - sum(a * b for a, b in zip(row, x))) ** 2
if d < best:
best, arg = d, idx
return list(arg)
def bit_errors(a, b) -> int:
"""The number of differing bits between two integer labels, or summed over two equal-length lists."""
if isinstance(a, int) and isinstance(b, int):
return bin(a ^ b).count("1")
if len(a) != len(b):
raise ValueError("lengths differ")
return sum(bit_errors(x, y) for x, y in zip(a, b))
d_blast.py 142 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/d-blast/. The authors are listed in prov/YCBK18.jsonl.
"""D-BLAST: diagonal layering with a nulling and cancelling receiver.
The transmitter has n antennas and sends L layers. Each layer is cut into n
blocks of the same length. Block k of layer l goes out on antenna k at block
time l + k, so a frame has L + n - 1 block times, and at block time t the
antenna k carries layer t - k when 0 <= t - k < L and is silent otherwise.
The channel H (m by n) stays the same for the whole frame (slow fading).
The receiver decodes the layers in the order 0, 1, ..., L - 1. For block k
of layer l at time t = l + k, the antennas k' > k carry earlier layers,
which are already decided, so the receiver subtracts them. The active
antennas k' < k carry later layers, so the receiver nulls them with the ZF
(a = 0) or MMSE (a = N0 / Es) filter. It then decodes the layer from the n
filter outputs. Two layer decoders are given: slicing each symbol alone
(no code) and a repetition code, where the same symbols fill all n blocks
and the receiver adds the n outputs with weights that maximize the SNR.
"""
import cbb
def nearest(z: complex, points: list[complex]) -> int:
"""The index of the point nearest to z (the lowest index on a tie)."""
best, arg = float("inf"), -1
for i, p in enumerate(points):
d = abs(z - p) ** 2
if d < best:
best, arg = d, i
return arg
def layer_map(n: int, layers: int) -> list[list[int]]:
"""grid[t][k] is the layer on antenna k at block time t, or -1 if the antenna is silent."""
return [[t - k if 0 <= t - k < layers else -1 for k in range(n)] for t in range(layers + n - 1)]
def rate_fraction(n: int, layers: int) -> float:
"""The fraction L / (L + n - 1) of the V-BLAST rate that the frame carries."""
return layers / (layers + n - 1)
def dblast_transmit(blocks: list[list[list[complex]]], n: int) -> list[list[complex]]:
"""The transmitted vectors of a frame. blocks[l][k] is the list of symbols of block k of layer l."""
layers = len(blocks)
blen = len(blocks[0][0])
out = []
for t, row in enumerate(layer_map(n, layers)):
for s in range(blen):
out.append([blocks[row[k]][k][s] if row[k] >= 0 else 0j for k in range(n)])
return out
def _filter(h: list[list[complex]], k: int, t: int, layers: int, a: float) -> tuple[list[complex], float]:
"""The nulling row for antenna k at block time t and the entry P_kk."""
cols = [c for c in range(k) if t - c < layers] + [k] # @line L5
hk = [[row[c] for c in cols] for row in h]
hh = cbb.herm(hk)
g = cbb.matmul(hh, hk)
for i in range(len(cols)):
g[i][i] += a
try:
p = cbb.inv(g) # @line L6
except ValueError:
raise ValueError("ZF nulling needs independent columns; use MMSE nulling") from None
i = len(cols) - 1
pkk = p[i][i].real
w = [sum(p[i][c] * hh[c][j] for c in range(len(cols))) for j in range(len(h))]
if a > 0:
w = [v / (1.0 - a * pkk) for v in w] # remove the MMSE bias
return w, pkk
def block_sinrs(h: list[list[complex]], layers: int, es: float, n0: float, mmse: bool = True) -> list[list[float]]:
"""sinr[l][k], the SNR (ZF) or unbiased SINR (MMSE) of block k of layer l, assuming correct cancellation."""
n = len(h[0])
a = n0 / es
out = []
for l in range(layers):
row = []
for k in range(n):
_, pkk = _filter(h, k, l + k, layers, a if mmse else 0.0)
row.append(1.0 / (a * pkk) - 1.0 if mmse else (es / n0) / pkk)
out.append(row)
return out
def dblast_detect(
ys: list[list[complex]],
h: list[list[complex]],
points: list[complex],
layers: int,
n0: float = 0.0,
es: float = 1.0,
mmse: bool = False,
repeat: bool = False,
) -> list:
"""The decisions of every layer.
ys holds the received vectors of the frame, (L + n - 1) * blen of them.
Without repeat, the result is out[l][k][s], the point index of symbol s
of block k of layer l. With repeat, every layer carries one list of blen
symbols, repeated in all n blocks, and the result is out[l][s].
"""
n = len(h[0])
if mmse and n0 <= 0:
raise ValueError("MMSE nulling needs N0 > 0")
if len(ys) % (layers + n - 1):
raise ValueError("the frame length must be a multiple of L + n - 1")
blen = len(ys) // (layers + n - 1)
a = n0 / es if mmse else 0.0
dec = [[[0j] * blen for _ in range(n)] for _ in range(layers)] # decided symbols
out = []
for l in range(layers): # @line L1
zs, wts = [], []
for k in range(n): # @line L2
t = l + k # @line L3
w, pkk = _filter(h, k, t, layers, a)
wts.append(1.0 / (a * pkk) - 1.0 if mmse else 1.0 / pkk) # @line L7
zk = []
for s in range(blen):
r = list(ys[t * blen + s])
for c in range(k + 1, n): # @line L4
if t - c >= 0:
x = dec[t - c][c][s]
r = [rv - row[c] * x for rv, row in zip(r, h)]
zk.append(sum(c * v for c, v in zip(w, r)))
zs.append(zk)
if repeat: # @line L8
tot = sum(wts)
idx = [nearest(sum(wt * z[s] for wt, z in zip(wts, zs)) / tot, points) for s in range(blen)]
for k in range(n):
dec[l][k] = [points[i] for i in idx]
out.append(idx)
else:
idx = [[nearest(z, points) for z in zk] for zk in zs]
for k in range(n):
dec[l][k] = [points[i] for i in idx[k]]
out.append(idx)
return out # @line L9
test_d_blast.py 143 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/d-blast/. The authors are listed in prov/YCBK18.jsonl.
import math
import random
import pytest
import cbb
import constel
from d_blast import block_sinrs, dblast_detect, dblast_transmit, layer_map, nearest, rate_fraction
def rayleigh(rng, m, n):
return [[cbb.cn(rng, 1.0) for _ in range(n)] for _ in range(m)]
def test_layer_map_and_rate() -> None:
grid = layer_map(3, 4)
assert grid == [[0, -1, -1], [1, 0, -1], [2, 1, 0], [3, 2, 1], [-1, 3, 2], [-1, -1, 3]]
assert rate_fraction(3, 4) == 4 / 6
for layer in range(4): # every layer visits every antenna once
assert sorted(k for row in grid for k in range(3) if row[k] == layer) == [0, 1, 2]
def test_example_on_the_page() -> None:
h = [[2, 1], [1, 1]]
assert layer_map(2, 3) == [[0, -1], [1, 0], [2, 1], [-1, 2]] and rate_fraction(2, 3) == 0.75
zf = block_sinrs(h, 3, 1.0, 1.0, mmse=False) # in units of Es/N0
assert all(abs(a - b) < 1e-12 for a, b in zip(sum(zf, []), [5, 0.2, 5, 0.2, 5, 2]))
mm = block_sinrs(h, 3, 1.0, 0.1) # Es/N0 = 10 dB
assert abs(mm[0][0] - 50) < 1e-9 and abs(mm[0][1] - 0.4 / 0.17) < 1e-9 and abs(mm[2][1] - 20) < 1e-9
assert abs((1 + mm[1][0]) * (1 + mm[1][1]) - 171) < 1e-9 # det(I + 10 H^T H) = 171
bpsk = constel.pam(2)
x = [[[bpsk[0]], [bpsk[1]]], [[bpsk[1]], [bpsk[1]]], [[bpsk[0]], [bpsk[0]]]]
ys = [cbb.matvec(h, v) for v in dblast_transmit(x, 2)]
assert ys == [[2, 1], [-3, -2], [1, 0], [1, 1]]
assert dblast_detect(ys, h, bpsk, 3) == [[[0], [1]], [[1], [1]], [[0], [0]]]
def test_transmit_puts_block_k_of_layer_l_on_antenna_k_at_time_l_plus_k() -> None:
blocks = [[[complex(10 * l + k, s) for s in range(2)] for k in range(3)] for l in range(4)]
xs = dblast_transmit(blocks, 3)
assert len(xs) == 6 * 2
for l in range(4):
for k in range(3):
for s in range(2):
assert xs[(l + k) * 2 + s][k] == blocks[l][k][s]
assert xs[0][1] == 0j and xs[11][0] == 0j
def test_noiseless_frames_are_recovered() -> None:
rng = random.Random(1501)
pts = constel.qam(16)
for _ in range(25):
n = rng.randint(1, 4)
m = rng.randint(n, 5)
layers = rng.randint(1, 5)
h = rayleigh(rng, m, n)
idx = [[[rng.randrange(16) for _ in range(2)] for _ in range(n)] for _ in range(layers)]
blocks = [[[pts[i] for i in b] for b in lay] for lay in idx]
ys = [cbb.matvec(h, x) for x in dblast_transmit(blocks, n)]
assert dblast_detect(ys, h, pts, layers) == idx
assert dblast_detect(ys, h, pts, layers, n0=1e-9, mmse=True) == idx
rep = [[rng.randrange(16) for _ in range(3)] for _ in range(layers)]
blocks = [[[pts[i] for i in r] for _ in range(n)] for r in rep]
ys = [cbb.matvec(h, x) for x in dblast_transmit(blocks, n)]
assert dblast_detect(ys, h, pts, layers, repeat=True) == rep
def test_first_block_of_a_layer_sees_maximal_ratio_combining() -> None:
rng = random.Random(1502)
h = rayleigh(rng, 3, 3)
s = block_sinrs(h, 5, 1.0, 0.2)
mrc = cbb.norm2([row[0] for row in h]) / 0.2
assert all(abs(row[0] - mrc) < 1e-9 * mrc for row in s)
def test_middle_layer_sinrs_add_up_to_the_capacity() -> None:
# theorem: for a layer l <= L - n, sum_k log2(1 + SINR_k) = log2 det(I + (Es/N0) H^H H)
rng = random.Random(1503)
for _ in range(30):
n = rng.randint(1, 4)
m = rng.randint(1, 5)
layers = rng.randint(n, 6)
h = rayleigh(rng, m, n)
snr = rng.uniform(0.5, 30.0)
g = cbb.matmul(cbb.herm(h), h)
cap = math.log2(abs(cbb.det(cbb.add(cbb.eye(n), cbb.scale(snr, g)))))
s = block_sinrs(h, layers, 1.0, 1.0 / snr)
for l in range(layers - n + 1):
assert abs(sum(math.log2(1 + v) for v in s[l]) - cap) < 1e-9 * (1 + cap)
for l in range(layers - n + 1, layers): # the last layers see fewer interferers
assert sum(math.log2(1 + v) for v in s[l]) >= cap - 1e-9
def test_bad_arguments() -> None:
with pytest.raises(ValueError):
dblast_detect([[0j]] * 3, [[1, 1]], constel.pam(2), 2, n0=0.0, mmse=True)
with pytest.raises(ValueError):
dblast_detect([[0j]] * 4, [[1, 1]], constel.pam(2), 2)
with pytest.raises(ValueError):
dblast_detect([[0j]] * 3, [[1, 1]], constel.pam(2), 2) # ZF with n > m
def test_diagonal_repetition_beats_vertical_repetition_in_slow_fading() -> None:
# measured: 4-QAM, m = n = 2, L = 6, Es/N0 = 6 dB, seed 1505, 300 frames of 6 symbols each
rng = random.Random(1505)
pts = constel.qam(4)
n, m, layers = 2, 2, 6
n0 = 1 / cbb.undb(6.0)
err_d = err_v = 0
for _ in range(300):
h = rayleigh(rng, m, n)
data = [rng.randrange(4) for _ in range(layers)]
blocks = [[[pts[d]] for _ in range(n)] for d in data]
ys = [cbb.awgn(rng, cbb.matvec(h, x), n0) for x in dblast_transmit(blocks, n)]
got = dblast_detect(ys, h, pts, layers, n0, mmse=True, repeat=True)
err_d += sum(g[0] != d for g, d in zip(got, data))
for _ in range(layers // n): # each antenna repeats its own symbol n times
idx = [rng.randrange(4) for _ in range(n)]
x = [pts[i] for i in idx]
ysum = [0j] * m
for _ in range(n):
ysum = cbb.add(ysum, cbb.awgn(rng, cbb.matvec(h, x), n0))
err_v += sum(a != b for a, b in zip(mmse_sic([v / n for v in ysum], h, pts, n0 / n), idx))
print(err_d, err_v)
assert 2 * err_d < err_v
def mmse_sic(y, h, pts, a):
"""MMSE nulling and cancelling with the V-BLAST order, for the vertical baseline."""
r, rem, out = list(y), list(range(len(h[0]))), [0] * len(h[0])
while rem:
hk = [[row[c] for c in rem] for row in h]
g = cbb.add(cbb.matmul(cbb.herm(hk), hk), cbb.scale(a, cbb.eye(len(rem))))
p = cbb.inv(g)
w = cbb.matmul(p, cbb.herm(hk))
i = min(range(len(rem)), key=lambda t: p[t][t].real)
k = rem.pop(i)
out[k] = nearest(sum(c * v for c, v in zip(w[i], r)) / (1 - a * p[i][i].real), pts)
r = [rv - row[k] * pts[out[k]] for rv, row in zip(r, h)]
return out
History
Foschini described the layered space-time architecture with diagonal layers in the Bell Labs Technical Journal in 1996, together with the result that the capacity of a rich-scattering channel grows linearly with the number of antennas. The diagonal structure and the start-up loss made it hard to build, so Wolniansky, Foschini, Golden and Valenzuela built the vertical version, V-BLAST, in 1998. Tse and Viswanath (2005) explained why the diagonal layering matters: with MMSE-SIC it reaches the outage capacity in slow fading, where V-BLAST does not.
References
- Gerard J. Foschini, Layered space-time architecture for wireless communication in a fading environment when using multi-element antennas, Bell Labs Technical Journal 1(2), 41-59, 1996, the diagonal layering of the coded streams over the antennas and the nulling and cancelling receiver
- David Tse and Pramod Viswanath, Fundamentals of Wireless Communication, Cambridge University Press, 2005, Section 8.5 (D-BLAST, an outage-optimal architecture), Section 8.5.2 (coding across the transmit antennas and the start-up loss) and Section 8.3.4 (the MMSE-SIC identity)
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 YCBK18 Edit this page History Report an error Markdown