Algorithm Search⌘K

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.

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
Properties
deterministicnot exact mlnot linearmiddle layer sinr sum equals log det
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 nn blocks and sends block kk on antenna kk one block time after block k−1k - 1, so every layer crosses all nn 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 nn blocks of a middle layer satisfy ∑klog⁡2(1+SINRk)=log⁡2det⁡(I+(Es/N0)HHH)\sum_k \log_2(1 + \mathrm{SINR}_k) = \log_2 \det(I + (E_s / N_0) H^H H) (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 L+n−1L + n - 1 block times for LL layers, so the rate is L/(L+n−1)L / (L + n - 1) 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 yt=Hxt+wty_t = H x_t + w_t with H∈Cm×nH \in \mathbb{C}^{m \times n} fixed for a whole frame (slow fading), xt∈Cnx_t \in \mathbb{C}^n the vector sent at time tt, and wt∼CN(0,N0I)w_t \sim \mathcal{CN}(0, N_0 I) independent over time. The transmitter has LL layers. Each layer is cut into nn blocks of BB symbols from a constellation S\mathcal{S} of energy EsE_s, or of coded symbols. Block kk of layer ll (0≤k<n0 \le k < n, 0≤l<L0 \le l < L) goes out on antenna kk at block time l+kl + k. So at block time tt, antenna kk sends block kk of layer t−kt - k when 0≤t−k<L0 \le t - k < L, and is silent otherwise. The receiver knows HH, and N0N_0 for MMSE nulling. It must find the symbols of every layer. ZF nulling needs m≥nm \ge n; MMSE nulling works for every mm.

The algorithm

  1. D-BLAST-DETECT(Y, H, S, L, a) ▷ a = 0 for ZF nulling, a = N0/Es for MMSE
  2. 1for l ← 0 to L - 1 ▷ the layers in order
  3. 2for k ← 0 to n - 1 ▷ the blocks of layer l
  4. 3t ← l + k
  5. 4r ← Y_t - Σ over k' > k of h_k' x̂(layer t - k', block k') ▷ cancel earlier layers
  6. 5A ← {k' < k : antenna k' is active at time t} ∪ {k} ▷ later layers, nulled
  7. 6P ← (H_Aᴴ H_A + a I)⁻¹; z_k ← (row k of P H_Aᴴ) r, without bias
  8. 7γ_k ← the SNR or SINR of z_k
  9. 8x̂(layer l) ← DECODE(z_0, ..., z_{n-1}; γ_0, ..., γ_{n-1})
  10. 9return x̂

Line L4 subtracts the antennas k′>kk' > k, which carry the layers t−k′<lt - k' < l; the receiver has already decoded them. Line L5 collects the active antennas k′<kk' < k, which carry the later layers t−k′>lt - k' > l. 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, (Es/N0)/Pkk(E_s / N_0) / P_{kk} for ZF and 1/(aPkk)−11 / (a P_{kk}) - 1 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 BB symbols fill all nn blocks and the decoder adds the outputs with weights γk\gamma_k before slicing. The filters of lines L5 and L6 depend only on kk and on which antennas are active, so a receiver computes them once per channel.

Example

Take n=m=2n = m = 2, L=3L = 3, BPSK and the real channel H=(2111)H = \begin{pmatrix} 2 & 1 \\ 1 & 1 \end{pmatrix}. The frame has L+n−1=4L + n - 1 = 4 block times:

block time tt 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 3/43 / 4 of V-BLAST. With ZF nulling, the receiver works as follows, with SNRs in units of Es/N0E_s / N_0.

  • Layer 0, block 0 at t=0t = 0: antenna 1 is silent, so the receiver combines with h0h_0 alone, the maximal ratio combining SNR ∥h0∥2=5\|h_0\|^2 = 5.
  • Layer 0, block 1 at t=1t = 1: antenna 0 carries layer 1, which is not decoded yet, so the receiver nulls it. The SNR is 1/[(HTH)−1]11=1/5=0.21 / [(H^T H)^{-1}]_{11} = 1/5 = 0.2.
  • Layer 1: at t=1t = 1, block 0 on antenna 0 sees antenna 1, which carries layer 0. The receiver cancels it, so the SNR is again 5. At t=2t = 2, 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 t=3t = 3 is alone and gets ∥h1∥2=2\|h_1\|^2 = 2.

Every layer has one strong block and one weak block, so no layer depends only on the weak direction of HH. With MMSE nulling at Es/N0=10E_s / N_0 = 10 dB (a=0.1a = 0.1), the middle layer gets γ0=50\gamma_0 = 50 and γ1=0.4/0.17≈2.35\gamma_1 = 0.4 / 0.17 \approx 2.35, and (1+50)(1+2.35)=171=det⁡(I+10HTH)(1 + 50)(1 + 2.35) = 171 = \det(I + 10 H^T H). So a layer code can carry log⁡2171≈7.42\log_2 171 \approx 7.42 bit for each symbol position of a block. One layer ends at each block time, so this is log⁡2det⁡(I+10HTH)\log_2 \det(I + 10 H^T H) 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 (+1,−1)(+1, -1), (−1,−1)(-1, -1) and (+1,+1)(+1, +1) in blocks 0 and 1, the receiver gets y0=(2,1)y_0 = (2, 1), y1=(−3,−2)y_1 = (-3, -2), y2=(1,0)y_2 = (1, 0) and y3=(1,1)y_3 = (1, 1), 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 L+n−1L + n - 1 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 ∥h0∥2Es/N0\|h_0\|^2 E_s / N_0 (a theorem). Fourth, with MMSE nulling and correct decisions on the earlier layers, each layer l≤L−nl \le L - n has ∑klog⁡2(1+γk)=log⁡2det⁡(I+(Es/N0)HHH)\sum_k \log_2(1 + \gamma_k) = \log_2 \det(I + (E_s / N_0) H^H H), and the last n−1n - 1 layers have at least this much (a theorem). Fifth, if the noise and interference of the nn outputs are uncorrelated, the weights γk\gamma_k give the combined SINR ∑kγk\sum_k \gamma_k (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 yt=Hxt+wty_t = H x_t + w_t with H∈Cm×nH \in \mathbb{C}^{m \times n} fixed over the frame, columns h0,…,hn−1h_0, \ldots, h_{n-1}, and wt∼CN(0,N0I)w_t \sim \mathcal{CN}(0, N_0 I) independent over tt. Block kk of layer ll is on antenna kk at block time l+kl + k, for 0≤l<L0 \le l < L and 0≤k<n0 \le k < n. Write a=0a = 0 for ZF and a=N0/Esa = N_0 / E_s for MMSE. For a set AA of antennas, HAH_A is the matrix of their columns and PA=(HAHHA+aI)−1P^A = (H_A^H H_A + a I)^{-1}.

Lemma 1 (the layer map). At block time tt, antenna kk carries at most one block, namely block kk of layer t−kt - k when 0≤t−k<L0 \le t - k < L. Each layer has exactly one block on each antenna. The frame uses the block times 0,…,L+n−20, \ldots, L + n - 2, so it has L+n−1L + n - 1 of them and carries LnL n blocks in (L+n−1)n(L + n - 1) n antenna slots.

Proof. Block kk of layer ll is at (t,k)=(l+k,k)(t, k) = (l + k, k). The map (l,k)↦(l+k,k)(l, k) \mapsto (l + k, k) is one to one, and its inverse is (t,k)↦(t−k,k)(t, k) \mapsto (t - k, k), so each slot holds at most one block. For a fixed ll the antennas k=0,…,n−1k = 0, \ldots, n - 1 each occur once. The smallest time is 0+00 + 0 and the largest is (L−1)+(n−1)(L - 1) + (n - 1). □\square

So the rate is Ln/((L+n−1)n)=L/(L+n−1)L n / ((L + n - 1) n) = L / (L + n - 1) of the rate of nn full streams.

Lemma 2 (who is cancelled and who is nulled). At the step for block kk of layer ll, at time t=l+kt = l + k, an active antenna k′>kk' > k carries the layer t−k′<lt - k' < l, and an active antenna k′<kk' < k carries the layer t−k′>lt - k' > l.

Proof. t−k′=l+(k−k′)t - k' = l + (k - k'), which is less than ll when k′>kk' > k and more than ll when k′<kk' < k. □\square

Lines L1 and L2 decode the layers in increasing order, so when the receiver reaches layer ll, every layer t−k′<lt - k' < l 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

r=HAxt,A+wt,A={k′<k:0≤t−k′<L}∪{k}.(1)r = H_A x_{t, A} + w_t, \qquad A = \{k' < k : 0 \le t - k' < L\} \cup \{k\}. \tag{1}

Theorem 3 (exact without noise). With ZF nulling (a=0a = 0, HH of full column rank) and wt=0w_t = 0 for all tt, the receiver returns every symbol of every layer, with either decoder of line L8.

Proof. By induction over the layers. Suppose that the layers 0,…,l−10, \ldots, l - 1 are decided correctly. By Lemma 2 and equation (1), r=HAxt,Ar = H_A x_{t, A} for each block kk of layer ll. The ZF filter PAHAHP^A H_A^H satisfies PAHAHHA=IP^A H_A^H H_A = I, so its row for antenna kk gives zk=xt,kz_k = x_{t, k}, the transmitted symbol. Slicing returns it at distance 0. With the repetition decoder, every zkz_k equals the same symbol ss, so the weighted mean is ss too. So layer ll is decided correctly. □\square

Lemma 4 (the SNR or SINR of a block). Assume correct earlier decisions. The output zkz_k of line L6 has the SNR (Es/N0)/PkkA(E_s / N_0) / P^A_{kk} for ZF and the unbiased SINR 1/(aPkkA)−11 / (a P^A_{kk}) - 1 for MMSE, where AA is the set of equation (1).

Proof. By equation (1), this is one step of nulling on the channel HAH_A, so Lemma 2 of the V-BLAST proof applies with K=AK = A. □\square

Theorem 5 (block 0 is maximal ratio combining). For every layer, block 0 has A={0}A = \{0\}, and its SNR or SINR is ∥h0∥2Es/N0\|h_0\|^2 E_s / N_0.

Proof. For k=0k = 0 there is no antenna k′<0k' < 0, so A={0}A = \{0\} and PA=1/(∥h0∥2+a)P^A = 1 / (\|h_0\|^2 + a). For ZF, (Es/N0)/PA=∥h0∥2Es/N0(E_s / N_0) / P^A = \|h_0\|^2 E_s / N_0. For MMSE, 1/(aPA)−1=(∥h0∥2+a)/a−1=∥h0∥2/a=∥h0∥2Es/N01 / (a P^A) - 1 = (\|h_0\|^2 + a) / a - 1 = \|h_0\|^2 / a = \|h_0\|^2 E_s / N_0. □\square

Theorem 6 (the middle layers see the full rate). With MMSE nulling and correct earlier decisions, every layer l≤L−nl \le L - n has

∑k=0n−1log⁡2(1+γk)=log⁡2det⁡(I+EsN0HHH),\sum_{k = 0}^{n - 1} \log_2(1 + \gamma_k) = \log_2 \det\left(I + \frac{E_s}{N_0} H^H H\right),

and every layer l>L−nl > L - n has a sum at least this large.

Proof. For l≤L−nl \le L - n and k′<kk' < k, t−k′=l+k−k′≤l+n−1≤L−1t - k' = l + k - k' \le l + n - 1 \le L - 1, so every antenna k′<kk' < k is active and A={0,…,k}A = \{0, \ldots, k\}. These sets grow by one antenna from k=0k = 0 to k=n−1k = n - 1. Read in the order k=n−1,n−2,…,0k = n - 1, n - 2, \ldots, 0, they are the sets KtK_t of an MMSE-SIC run on HH with the order (n−1,n−2,…,0)(n - 1, n - 2, \ldots, 0): stream kk is detected when the remaining set is {0,…,k}\{0, \ldots, k\}. Theorem 6 of the V-BLAST proof holds for every order, so the sum of log⁡2(1+γk)\log_2(1 + \gamma_k) is log⁡2det⁡(I+(Es/N0)HHH)\log_2 \det(I + (E_s / N_0) H^H H).

For l>L−nl > L - n, some antennas k′<kk' < k are silent, so AA is a subset of {0,…,k}\{0, \ldots, k\} that contains kk. By Lemma 3 of the V-BLAST proof, removing interferers never lowers the SINR, so each γk\gamma_k is at least its value for a middle layer, and so is the sum. □\square

Theorem 7 (combining the blocks). Suppose that the nn unbiased outputs of a layer are zk=s+ekz_k = s + e_k, where ss is a symbol of energy EsE_s repeated in all blocks, E[ek]=0E[e_k] = 0, E∣ek∣2=Es/γkE|e_k|^2 = E_s / \gamma_k, and the eke_k are uncorrelated. Then the weighted mean zˉ=∑kγkzk/∑kγk\bar z = \sum_k \gamma_k z_k / \sum_k \gamma_k is unbiased with SINR ∑kγk\sum_k \gamma_k, and no other unbiased linear combination has a larger SINR.

Proof. A combination ∑kckzk\sum_k c_k z_k with ∑kck=1\sum_k c_k = 1 is unbiased and has error variance ∑k∣ck∣2Es/γk\sum_k |c_k|^2 E_s / \gamma_k. By the Cauchy-Schwarz inequality,

1=∣∑kck∣2=∣∑kckγkγk∣2≤(∑k∣ck∣2γk)(∑kγk),1 = \left|\sum_k c_k\right|^2 = \left|\sum_k \frac{c_k}{\sqrt{\gamma_k}} \sqrt{\gamma_k}\right|^2 \le \left(\sum_k \frac{|c_k|^2}{\gamma_k}\right)\left(\sum_k \gamma_k\right),

so the error variance is at least Es/∑kγkE_s / \sum_k \gamma_k, with equality when ckc_k is proportional to γk\gamma_k. The SINR is EsE_s divided by the error variance. □\square

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 kk comes from the later layers that block kk nulls; it is uncorrelated between blocks when the symbols in different blocks are independent, as for n=2n = 2 or for coded symbols. For a capacity-achieving code over the nn blocks, the layer can be decoded when its rate is below ∑klog⁡2(1+γk)\sum_k \log_2(1 + \gamma_k), which by Theorem 6 is the log-det rate of HH. 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 kk inverts a matrix of size at most k+1k + 1, at a cost of O(k2m+k3)O(k^2 m + k^3). Over the nn blocks of a layer this is O(n3m+n4)O(n^3 m + n^4). The implementation recomputes it for each of the LL layers; a receiver needs it only for the at most nn different patterns of active antennas. Each symbol of a block costs up to n−1n - 1 cancellations of length mm, one inner product of length mm, and O(M)O(M) for slicing. So a frame costs O(Ln3m+Ln4+LBn2m+LBnM)O(L n^3 m + L n^4 + L B n^2 m + L B n M) in the real RAM, plus the cost of the layer decoder, with O(LBn+nm)O(L B n + n m) space for the decisions and the filters.

Properties

  • Every layer sees every antenna. Block kk of each layer is on antenna kk (closed form).
  • Rate loss. LL layers need L+n−1L + n - 1 block times, a fraction L/(L+n−1)L / (L + n - 1) of the V-BLAST rate. For n=4n = 4 and L=20L = 20 this is 20/23≈0.8720 / 23 \approx 0.87 (closed form).
  • Capacity per layer. With MMSE nulling and correct decisions on earlier layers, each middle layer sees log⁡2det⁡(I+(Es/N0)HHH)\log_2 \det(I + (E_s / N_0) H^H H) in total (theorem). This is the rate of the channel HH with equal power and no channel knowledge at the transmitter.
  • Outage optimal. With capacity-achieving codes over the nn 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 n−1n - 1 layers.
  • Measured gain over vertical layering. For 4-QAM with m=n=2m = n = 2, L=6L = 6, a repetition code over the nn blocks, i.i.d. Rayleigh fading per frame and Es/N0=6E_s / N_0 = 6 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 m≥nm \ge n 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 LL is much larger than nn 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 n−1n - 1 block times is large, so a space-time code or a joint detector is often better.

Pitfalls

  • Wrong cancellation order. At block time tt, antenna k′>kk' > k carries an earlier layer and must be cancelled. Antenna k′<kk' < k 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 L/(L+n−1)L / (L + n - 1) of the V-BLAST rate. A comparison at equal LL that ignores this is unfair to V-BLAST.
  • Error propagation. One wrong layer spoils the next n−1n - 1 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 ∑kγk\sum_k \gamma_k. 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.

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)
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

  1. 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
  2. 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.

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
  • at least three sources
  • a scene preset for the example