Algorithm Search⌘K

Algorithmadvanced

MMSE turbo equalizer with soft interference cancellation

Also called Tuchler-Koetter-Singer equalizer, SISO MMSE equalizer.

A linear MMSE equalizer that uses decoder priors: it subtracts the soft symbol means and outputs extrinsic LLRs. Exact form O(W^3) per symbol for a window W; a fixed-filter form is far cheaper.

Time
O(K W^3) worst
Space
O(W^2) extra
Where
K = the number of symbols; L = the number of channel taps; W = the window length N1 + N2 + 1
Properties
deterministicnot exact mapextrinsic outputneeds channelneeds noise levelsoft inputsoft output
Origin
Michael Tüchler, Ralf Koetter, Andrew C. Singer, 2002

The MMSE turbo equalizer with soft interference cancellation is the low-cost soft-in soft-out equalizer of turbo equalization. It is a linear MMSE equalizer that also uses prior LLRs from the decoder. For each symbol xnx_n, it turns the priors of the other symbols into soft means and variances, subtracts the mean interference from the received window, and filters the rest with the MMSE filter for those variances. It then turns the filter output into an extrinsic LLR with a Gaussian model. The difference from the turbo equalization page is the scope. That page is the loop: equalizer, deinterleaver, decoder, interleaver, and back. This page is one equalizer for that loop, which replaces the BCJR equalizer. The BCJR equalizer costs O(2L)O(2^L) per symbol for BPSK and LL taps. This one costs O(W3)O(W^3) per symbol in its exact form, for a window of WW samples, and much less in its fixed-filter form.

In plain words

A coded signal passes through a channel with echoes. A decoder already has a guess about each transmitted bit, with a level of confidence. To estimate one symbol, the equalizer uses the guesses for its neighbours. It removes their expected echoes from the received samples, and it trusts this more where the decoder is more confident. What is left is mostly the wanted symbol plus noise and the echoes of the uncertain neighbours. A linear filter, tuned to that remaining uncertainty, then gives the best linear estimate of the symbol. The equalizer ignores the decoder's guess about the symbol itself, so that it returns only new information. This new information goes back to the decoder, and the two repeat.

The problem

The input is a block of KK BPSK symbols xk=1−2bkx_k = 1 - 2 b_k sent through a real channel h=(h0,…,hL−1)h = (h_0, \ldots, h_{L-1}) that the receiver knows:

ym=∑l=0L−1hl xm−l+wm,wm∼N(0,σ2),m=0,…,K+L−2.y_m = \sum_{l=0}^{L-1} h_l\, x_{m-l} + w_m, \qquad w_m \sim N(0, \sigma^2), \qquad m = 0, \ldots, K + L - 2.

The receiver also has a prior LLR La(xk)=ln⁡P(bk=0)/P(bk=1)L_a(x_k) = \ln P(b_k = 0) / P(b_k = 1) for each symbol, from the decoder. The prior gives the soft mean and variance

xˉk=tanh⁡(La(xk)/2),vk=1−xˉk2.\bar x_k = \tanh(L_a(x_k) / 2), \qquad v_k = 1 - \bar x_k^2.

The output is an extrinsic LLR Le(xn)L_e(x_n) for each nn, which must not depend on La(xn)L_a(x_n). A linear MMSE estimate of xnx_n from a window of samples is wanted, not the exact posterior, which the BCJR algorithm gives at exponential cost.

For symbol nn, the window is Y=(yn−N2,…,yn+N1)Y = (y_{n-N_2}, \ldots, y_{n+N_1}), with W=N1+N2+1W = N_1 + N_2 + 1 samples and N1≥L−1N_1 \ge L - 1. It equals HX+wH X + w for the W+L−1W + L - 1 symbols X=(xn−N2−L+1,…,xn+N1)X = (x_{n-N_2-L+1}, \ldots, x_{n+N_1}) and the W×(W+L−1)W \times (W + L - 1) matrix HH with Hij=hi−j+L−1H_{ij} = h_{i-j+L-1}. Column N2+L−1N_2 + L - 1 of HH belongs to xnx_n; call it ss. Symbols outside the block are known zeros, and samples outside it are zero.

The algorithm

  1. SISO-MMSE(y, h, L_a, σ², N1, N2)
  2. 1x̄_k ← tanh(L_a(x_k)/2), v_k ← 1 - x̄_k² for all k
  3. 2for n ← 0 to K - 1 do
  4. 3Y ← (y[n-N2], ..., y[n+N1]); X̄, V ← means and diagonal of variances of the window symbols
  5. 4C ← H V Hᵀ + σ² I + (1 - v_n) s sᵀ ▷ the covariance with x_n unknown
  6. 5f ← C⁻¹ s
  7. 6x̂ ← fᵀ (Y - H X̄ + x̄_n s) ▷ cancel the soft interference
  8. 7μ ← sᵀ f
  9. 8L_e(x_n) ← 2 x̂ / (1 - μ)
  10. 9return L_e

Line L1 converts the priors to soft symbols. A prior of 0 gives mean 0 and variance 1, and a very large prior gives mean ±1\pm 1 and variance 0. Line L3 reads the window. Line L4 is the covariance of YY when xnx_n has mean 0 and variance 1 and every other symbol has its prior mean and variance: the term (1−vn)ssT(1 - v_n) s s^T replaces vnv_n by 1 in HVHTH V H^T. Line L5 is the MMSE filter for that covariance. Line L6 subtracts the mean of YY under the same model, HXˉ−xˉnsH \bar X - \bar x_n s, and filters the rest. Line L7 is the gain of the filter on xnx_n. Line L8 is the LLR of x^\hat x under the model x^∣xn∼N(μxn,μ(1−μ))\hat x \mid x_n \sim N(\mu x_n, \mu (1 - \mu)).

The fixed-filter form replaces VV in line L4 by vˉI\bar v I, with vˉ\bar v the mean of all vkv_k, and runs lines L4 and L5 once per block. Then only lines L6 to L8 run per symbol. The code has both forms; the flag approx selects the second.

Example

One symbol by hand. Take h=(1,0.5)h = (1, 0.5), σ2=0.5\sigma^2 = 0.5, N1=N2=1N_1 = N_2 = 1, five symbols with priors (0,2,0,−2,0)(0, 2, 0, -2, 0) and the samples y=(1.2,0.4,−0.9,−0.8,0.6,0.3)y = (1.2, 0.4, -0.9, -0.8, 0.6, 0.3). For n=2n = 2, line L1 gives xˉ=(0,0.7616,0,−0.7616)\bar x = (0, 0.7616, 0, -0.7616) and v=(1,0.42,1,0.42)v = (1, 0.42, 1, 0.42) for x0x_0 to x3x_3. The window is Y=(y1,y2,y3)=(0.4,−0.9,−0.8)Y = (y_1, y_2, y_3) = (0.4, -0.9, -0.8), and

H=(0.510000.510000.51),s=(0,1,0.5),C=(1.1700.21000.2101.6050.500.51.170).H = \begin{pmatrix} 0.5 & 1 & 0 & 0 \\ 0 & 0.5 & 1 & 0 \\ 0 & 0 & 0.5 & 1 \end{pmatrix}, \quad s = (0, 1, 0.5), \quad C = \begin{pmatrix} 1.170 & 0.210 & 0 \\ 0.210 & 1.605 & 0.5 \\ 0 & 0.5 & 1.170 \end{pmatrix}.

Line L5 gives f=(−0.1043,0.5809,0.1791)f = (-0.1043, 0.5809, 0.1791). The cancelled window is Y−HXˉ=(−0.3616,−1.2808,−0.0384)Y - H \bar X = (-0.3616, -1.2808, -0.0384), because xˉ2=0\bar x_2 = 0. Then x^=−0.7132\hat x = -0.7132, μ=0.6705\mu = 0.6705 and Le(x2)=2(−0.7132)/0.3295=−4.33L_e(x_2) = 2(-0.7132)/0.3295 = -4.33. The five outputs are (4.41,−0.60,−4.33,−0.95,4.08)(4.41, -0.60, -4.33, -0.95, 4.08).

Better priors, fewer errors. On the Proakis B channel (0.407,0.815,0.407)(0.407, 0.815, 0.407) with σ=0.5\sigma = 0.5, N1=N2=4N_1 = N_2 = 4, K=6000K = 6000 symbols (seed 7), the priors are drawn as consistent Gaussian LLRs, La=xσa2/2+N(0,σa2)L_a = x \sigma_a^2 / 2 + N(0, \sigma_a^2) (seed 8). The table gives the error rate of the sign of LeL_e alone. This is a measurement.

prior variance σa2\sigma_a^2 0 1 4 16 perfect
exact form 0.1325 0.1150 0.0778 0.0278 0.0220
fixed-filter form 0.1325 0.1155 0.0875 0.0333 0.0220

The matched filter bound is Q(∥h∥/σ)=0.0230Q(\|h\|/\sigma) = 0.0230. With perfect priors, all the interference is removed, and both forms reach the bound. With no priors, both forms are the plain MMSE equalizer. In between, the exact form is better, because it uses the variance of each neighbour.

Correctness

Claim 1 (the linear MMSE estimate). Model xnx_n as mean 0 and variance 1, and every other symbol in the window as independent with mean xˉk\bar x_k and variance vkv_k. Then x^\hat x of line L6 is the linear MMSE estimate of xnx_n from YY, and μ\mu of line L7 is its covariance with xnx_n. This is a theorem. Under the model, E[Y]=HXˉ−xˉnsE[Y] = H \bar X - \bar x_n s, Cov(Y)=C\mathrm{Cov}(Y) = C and Cov(Y,xn)=s\mathrm{Cov}(Y, x_n) = s, and the linear MMSE estimate is Exn+Cov(xn,Y) Cov(Y)−1(Y−EY)=sTC−1(Y−EY)E x_n + \mathrm{Cov}(x_n, Y)\, \mathrm{Cov}(Y)^{-1} (Y - E Y) = s^T C^{-1} (Y - E Y). The test enumerates all 32 symbol patterns of a small case, builds the mean and the covariance from them, and matches the code to 10−910^{-9}.

Claim 2 (extrinsic). Le(xn)L_e(x_n) does not depend on La(xn)L_a(x_n). This is a theorem: xnx_n enters line L4 through HVHT+(1−vn)ssTH V H^T + (1 - v_n) s s^T, in which the vnv_n terms cancel, and line L6 through −HXˉ+xˉns-H \bar X + \bar x_n s, in which the xˉn\bar x_n terms cancel.

Claim 3 (the Gaussian LLR). For each value of xnx_n, E[x^∣xn]=μxnE[\hat x \mid x_n] = \mu x_n and Var[x^∣xn]=μ−μ2\mathrm{Var}[\hat x \mid x_n] = \mu - \mu^2, with 0≤μ<10 \le \mu < 1. These moments are a theorem. Line L8 is the exact LLR of a Gaussian with these moments, ln⁡N(x^;μ,μ−μ2)/N(x^;−μ,μ−μ2)=2x^/(1−μ)\ln N(\hat x; \mu, \mu - \mu^2) / N(\hat x; -\mu, \mu - \mu^2) = 2 \hat x / (1 - \mu). The Gaussian shape is a heuristic: x^\hat x is a sum of noise and residual symbols, and it is only close to Gaussian. So LeL_e is not the true extrinsic LLR, and the equalizer is not the MAP equalizer.

Special cases, as closed forms. With all priors 0, v=1v = 1, xˉ=0\bar x = 0 and f=(HHT+σ2I)−1sf = (H H^T + \sigma^2 I)^{-1} s, the MMSE linear equalizer. With perfect priors, v=0v = 0, C=σ2I+ssTC = \sigma^2 I + s s^T and Le(xn)=2sT(Y−HXˉ+xˉns)/σ2L_e(x_n) = 2 s^T (Y - H \bar X + \bar x_n s) / \sigma^2, the matched filter after exact cancellation, which is the true LLR for that case. The proofs folder has the details.

Proof: The SISO MMSE equalizer computes the linear MMSE estimate under the prior model, its output is extrinsic, and its LLR is exact for the Gaussian model of the estimatefull

Setting. For symbol nn, the window is Y=HX+wY = H X + w, with HH of size W×(W+L−1)W \times (W + L - 1), w∼N(0,σ2I)w \sim N(0, \sigma^2 I) independent of XX, and σ2>0\sigma^2 > 0. Column j0=N2+L−1j_0 = N_2 + L - 1 of HH is ss, and Xj0=xnX_{j_0} = x_n. The prior model M\mathcal M says: the entries of XX are independent; xnx_n has mean 0 and variance 1; every other entry XjX_j has mean Xˉj\bar X_j and variance VjjV_{jj}, from line L1, or mean 0 and variance 0 if it lies outside the block. Let Xˉ′\bar X' be Xˉ\bar X with entry j0j_0 set to 0, and V′V' be VV with entry j0j_0 set to 1.

Lemma 1 (the moments of the window). Under M\mathcal M, E[Y]=HXˉ′=HXˉ−xˉnsE[Y] = H \bar X' = H \bar X - \bar x_n s, Cov(Y)=HV′HT+σ2I\mathrm{Cov}(Y) = H V' H^T + \sigma^2 I, which is the matrix CC of line L4, and Cov(Y,xn)=s\mathrm{Cov}(Y, x_n) = s.

Proof. E[Y]=HE[X]=HXˉ′E[Y] = H E[X] = H \bar X', and HXˉ′=HXˉ−xˉnHej0=HXˉ−xˉnsH \bar X' = H \bar X - \bar x_n H e_{j_0} = H \bar X - \bar x_n s. The entries of XX are independent, so Cov(X)=V′\mathrm{Cov}(X) = V', and ww is independent of XX, so Cov(Y)=HV′HT+σ2I\mathrm{Cov}(Y) = H V' H^T + \sigma^2 I. Now V′=V+(1−vn)ej0ej0TV' = V + (1 - v_n) e_{j_0} e_{j_0}^T, so HV′HT=HVHT+(1−vn)ssTH V' H^T = H V H^T + (1 - v_n) s s^T, which is line L4. Last, Cov(Y,xn)=H Cov(X,xn)=Hej0⋅1=s\mathrm{Cov}(Y, x_n) = H\, \mathrm{Cov}(X, x_n) = H e_{j_0} \cdot 1 = s. □\square

Theorem 1 (linear MMSE). Among all estimates a+gTYa + g^T Y, the one with the least EM(xn−a−gTY)2E_{\mathcal M}(x_n - a - g^T Y)^2 is x^=fT(Y−EY)\hat x = f^T (Y - E Y) with f=C−1sf = C^{-1} s, which is line L6.

Proof. C⪰σ2I≻0C \succeq \sigma^2 I \succ 0, so CC is invertible. Write the error as xn−a−gTYx_n - a - g^T Y. Its mean square is (Exn−a−gTEY)2+Var(xn−gTY)(E x_n - a - g^T E Y)^2 + \mathrm{Var}(x_n - g^T Y). The first term is 0 for a=−gTEYa = -g^T E Y, since Exn=0E x_n = 0. The second is 1−2gTs+gTCg1 - 2 g^T s + g^T C g, a strictly convex quadratic in gg with gradient 2(Cg−s)2(C g - s), which is zero only at g=C−1s=fg = C^{-1} s = f. So x^=fT(Y−EY)\hat x = f^T (Y - E Y), and by Lemma 1, Y−EY=Y−HXˉ+xˉnsY - E Y = Y - H \bar X + \bar x_n s. □\square

Theorem 2 (extrinsic). Le(xn)L_e(x_n) does not depend on La(xn)L_a(x_n).

Proof. La(xn)L_a(x_n) enters only through xˉn\bar x_n and vnv_n. By Lemma 1, C=HV′HT+σ2IC = H V' H^T + \sigma^2 I, and V′V' does not contain vnv_n. The vector Y−HXˉ+xˉns=Y−HXˉ′Y - H \bar X + \bar x_n s = Y - H \bar X', and Xˉ′\bar X' does not contain xˉn\bar x_n. So ff, x^\hat x, μ\mu and Le(xn)L_e(x_n) do not depend on La(xn)L_a(x_n). □\square

Lemma 2 (0≤μ<10 \le \mu < 1). Let D=C−ssT=HV′′HT+σ2ID = C - s s^T = H V'' H^T + \sigma^2 I, where V′′V'' is V′V' with entry j0j_0 set to 0. Then D≻0D \succ 0, and with α=sTD−1s≥0\alpha = s^T D^{-1} s \ge 0, μ=sTC−1s=α/(1+α)\mu = s^T C^{-1} s = \alpha / (1 + \alpha).

Proof. D⪰σ2I≻0D \succeq \sigma^2 I \succ 0. By the Sherman-Morrison formula, C−1s=(D+ssT)−1s=D−1s/(1+α)C^{-1} s = (D + s s^T)^{-1} s = D^{-1} s / (1 + \alpha), so μ=sTC−1s=α/(1+α)∈[0,1)\mu = s^T C^{-1} s = \alpha / (1 + \alpha) \in [0, 1). □\square

Theorem 3 (the conditional moments). Under M\mathcal M and given xn=b∈{+1,−1}x_n = b \in \{+1, -1\}, E[x^∣xn=b]=μbE[\hat x \mid x_n = b] = \mu b and Var[x^∣xn=b]=μ−μ2\mathrm{Var}[\hat x \mid x_n = b] = \mu - \mu^2.

Proof. Given xn=bx_n = b, Y−EY=bs+H(X′−Xˉ′)+wY - E Y = b s + H (X' - \bar X') + w, where X′X' is XX with entry j0j_0 set to 0. The last two terms have mean 0 and covariance HV′′HT+σ2I=DH V'' H^T + \sigma^2 I = D. So E[x^∣b]=bfTs=μbE[\hat x \mid b] = b f^T s = \mu b and Var[x^∣b]=fTDf=fT(C−ssT)f=fTs−(fTs)2=μ−μ2\mathrm{Var}[\hat x \mid b] = f^T D f = f^T (C - s s^T) f = f^T s - (f^T s)^2 = \mu - \mu^2, using Cf=sC f = s. □\square

Theorem 4 (the LLR of the Gaussian model). If x^∣xn=b\hat x \mid x_n = b is modeled as N(μb,μ−μ2)N(\mu b, \mu - \mu^2) and 0<μ<10 < \mu < 1, then ln⁡p(x^∣b=+1)/p(x^∣b=−1)=2x^/(1−μ)\ln p(\hat x \mid b = +1) / p(\hat x \mid b = -1) = 2 \hat x / (1 - \mu), which is line L8.

Proof. The two Gaussians have the same variance τ2=μ(1−μ)\tau^2 = \mu (1 - \mu), so the log ratio is ((x^+μ)2−(x^−μ)2)/(2τ2)=4μx^/(2μ(1−μ))=2x^/(1−μ)((\hat x + \mu)^2 - (\hat x - \mu)^2) / (2 \tau^2) = 4 \mu \hat x / (2 \mu (1 - \mu)) = 2 \hat x / (1 - \mu). With x=1−2bx = 1 - 2b, xn=+1x_n = +1 is b=0b = 0, so this is the LLR in the sign convention ln⁡P(b=0)/P(b=1)\ln P(b = 0) / P(b = 1). □\square

What is not proved. Theorem 3 gives the true first two moments under M\mathcal M, but x^\hat x given xnx_n is a mixture over the other symbols plus Gaussian noise. It is Gaussian only when no residual symbol variance reaches the output, that is, when HV′′HT=0H V'' H^T = 0 on the support of ff. Then LeL_e is the true extrinsic LLR of x^\hat x. Otherwise the Gaussian model is a heuristic. The prior model M\mathcal M is also a heuristic inside a turbo loop: the decoder outputs are not independent, and they are not exact. So the equalizer is not the MAP equalizer.

Two closed forms. If every prior is 0, then Xˉ=0\bar X = 0, V′=IV' = I and f=(HHT+σ2I)−1sf = (H H^T + \sigma^2 I)^{-1} s, the MMSE linear equalizer for the delay N2N_2. If every prior is perfect, then V′′=0V'' = 0, D=σ2ID = \sigma^2 I, α=∥s∥2/σ2\alpha = \|s\|^2 / \sigma^2, f=s/(σ2+∥s∥2)f = s / (\sigma^2 + \|s\|^2), 1−μ=σ2/(σ2+∥s∥2)1 - \mu = \sigma^2 / (\sigma^2 + \|s\|^2) and Le(xn)=2sT(Y−HXˉ′)/σ2L_e(x_n) = 2 s^T (Y - H \bar X') / \sigma^2. Here x^\hat x given xnx_n is exactly Gaussian, so this is the true LLR. The tests check both forms and an enumeration of Theorem 1 and Theorem 3 to 10−910^{-9}.

Complexity

In the exact form, line L4 builds a W×WW \times W matrix in O(W2(W+L))O(W^2 (W + L)) operations, and line L5 solves it in O(W3)O(W^3). Since L≤N1+1≤WL \le N_1 + 1 \le W, KK symbols cost O(KW3)O(K W^3) time in the real RAM and O(W2)O(W^2) extra space. The window moves by one sample per symbol, so CC shares a (W−1)×(W−1)(W-1) \times (W-1) block with the previous one, and a bordering update of the inverse brings the cost to O(W2)O(W^2) per symbol; the code does not do this. The fixed-filter form solves once, in O(W3)O(W^3), and then costs O(W+L)O(W + L) per symbol if HTfH^T f is computed once; the code computes line L6 directly, in O(W(W+L))O(W (W + L)). The BCJR equalizer, for comparison, costs O(2L)O(2^L) per symbol for BPSK, one step per trellis edge, so the MMSE equalizer pays off for long channels and large alphabets.

Properties

  • Soft in, soft out, extrinsic. The output can go back to a decoder without the prior of the same symbol.
  • It reduces to known equalizers. With no priors, it is the linear MMSE equalizer. With perfect priors, it is the matched filter after cancellation, which reaches the matched filter bound.
  • Not MAP. It is linear in YY and its LLR uses a Gaussian model, so in the first iteration it is worse than the BCJR equalizer on a hard channel such as Proakis B.
  • Needs the channel and the noise level. Both enter CC; an estimate is used in practice.
  • The fixed-filter form is exact for equal variances. When all ∣La∣|L_a| are equal, V=vˉIV = \bar v I in the interior of the block, and the two forms agree there to rounding. The test checks this.

Variants and improvements

  • Fixed-filter form. One filter per block from the mean variance, as above. It trades some performance for a large drop in cost.
  • Frequency-domain form. With a cyclic prefix, the fixed filter becomes one division per frequency, as in frequency domain equalization.
  • Decision feedback. Feed back the soft means of past symbols in a decision feedback structure.
  • Expectation propagation. EP detection also uses Gaussian models of the symbols, but it refines the means and variances from the equalizer's own posterior, not only from the decoder priors.
  • MIMO and CDMA. The same steps with a MIMO channel matrix give the soft MMSE MIMO detector; Wang and Poor (1999) used them for coded CDMA.

When to use it

Use it as the equalizer of a turbo receiver when the BCJR equalizer is too costly: long channels, large alphabets, or MIMO. Use the fixed-filter or frequency-domain form when the cost must be close to that of a plain MMSE equalizer. For short channels with BPSK, the BCJR equalizer is cheap and better, especially in the first iteration.

Pitfalls

  • Feeding back posterior LLRs into line L1. The prior must be the extrinsic output of the decoder. Posteriors count the equalizer's own information twice, and the loop becomes overconfident.
  • Leaving xnx_n with its prior in line L4 or line L6. Then the output is not extrinsic, and Claim 2 fails.
  • Overflow in line L1. Use tanh⁡\tanh, not (eL−1)/(eL+1)(e^L - 1)/(e^L + 1), for large ∣La∣|L_a|.
  • A noise variance that is too small in line L4. With perfect priors, CC tends to ssTs s^T as σ2→0\sigma^2 \to 0, and the LLRs become huge. Do not set σ2\sigma^2 to 0.
  • Edge effects. At the ends of the block, the window reaches outside. Treat missing symbols as known zeros and missing samples as zero, as in the code, or use a terminated block.

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)
soft_interference_cancellation_equalizer.py 89 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/soft-interference-cancellation-equalizer/. The authors are listed in prov/G8QTJ4.jsonl.

"""The MMSE turbo equalizer with soft interference cancellation (Tuchler, Koetter and Singer).

BPSK symbols x_k = 1 - 2 b_k in {+1, -1} pass a real channel h of L taps:
y_m = sum_l h_l x_(m-l) + w_m, w_m ~ N(0, sigma2), for m = 0, ..., K + L - 2.
The prior LLRs La_k = ln P(b_k = 0) / P(b_k = 1) give the soft symbols
xbar_k = tanh(La_k / 2) with variances v_k = 1 - xbar_k^2.

For symbol n, the window Y = (y_(n-N2), ..., y_(n+N1)) of W = N1 + N2 + 1
samples is H X + noise, with X = (x_(n-N2-L+1), ..., x_(n+N1)) and
H[i][j] = h[i - j + L - 1]. The column of H for x_n is s, with s_i = h[i - N2].
The estimate treats x_n as unknown (mean 0, variance 1), so that its own
prior does not enter, and uses the priors of all other symbols:
    C = H V H^T + sigma2 I + (1 - v_n) s s^T,  f = C^-1 s,
    xhat = f^T (Y - H xbar + xbar_n s),        mu = s^T f,
    Le_n = 2 xhat / (1 - mu).
The approximate form replaces V by the average variance vbar times I, so f
is computed once per block.

Samples outside 0..K+L-2 are 0, and symbols outside 0..K-1 are known zeros
(mean 0, variance 0); then such samples carry no signal and get weight 0.
"""

import math

import cbb


def soft_symbols(la: list[float]) -> tuple[list[float], list[float]]:
    """The means tanh(La / 2) and variances 1 - mean^2 of BPSK symbols with prior LLRs La."""
    xbar = [math.tanh(v / 2.0) for v in la]
    return xbar, [1.0 - m * m for m in xbar]


def window_matrix(h: list[float], w: int) -> list[list[float]]:
    """The W by (W + L - 1) matrix H with H[i][j] = h[i - j + L - 1]."""
    taps = len(h)
    return [[float(h[i - j + taps - 1]) if 0 <= i - j + taps - 1 < taps else 0.0 for j in range(w + taps - 1)] for i in range(w)]


def _real_solve(a: list[list[float]], b: list[float]) -> list[float]:
    return [v.real for v in cbb.solve(a, b)]


def siso_equalize(
    y: list[float], h: list[float], la: list[float], sigma2: float, n1: int, n2: int, approx: bool = False
) -> list[float]:
    """Extrinsic LLRs Le_n for n = 0, ..., K-1, where K = len(la) and len(y) = K + L - 1."""
    taps, k = len(h), len(la)
    if taps < 1 or sigma2 <= 0 or n1 < taps - 1 or n2 < 0 or len(y) != k + taps - 1:
        raise ValueError("need L >= 1, sigma2 > 0, N1 >= L - 1, N2 >= 0 and len(y) = K + L - 1")
    w = n1 + n2 + 1
    hm = window_matrix(h, w)
    j0 = n2 + taps - 1
    s = [hm[i][j0] for i in range(w)]
    xbar, var = soft_symbols(la)  # @line L1

    def sym(t: int) -> tuple[float, float]:
        return (xbar[t], var[t]) if 0 <= t < k else (0.0, 0.0)

    def sample(m: int) -> float:
        return float(y[m]) if 0 <= m < len(y) else 0.0

    f_fixed = None
    if approx:
        vbar = sum(var) / k
        c = [[vbar * sum(hm[i][j] * hm[r][j] for j in range(w + taps - 1)) + (sigma2 if i == r else 0.0) + (1 - vbar) * s[i] * s[r] for r in range(w)] for i in range(w)]  # @line L4
        f_fixed = _real_solve(c, s)  # @line L5
    out = []
    for n in range(k):  # @line L2
        yw = [sample(n - n2 + i) for i in range(w)]  # @line L3
        xs = [sym(n - n2 - taps + 1 + j) for j in range(w + taps - 1)]  # @line L3
        mx = [m for m, _ in xs]  # @line L3
        if approx:
            f = f_fixed
        else:
            vn = xs[j0][1]
            c = [
                [sum(hm[i][j] * xs[j][1] * hm[r][j] for j in range(w + taps - 1)) + (sigma2 if i == r else 0.0) + (1 - vn) * s[i] * s[r] for r in range(w)]
                for i in range(w)
            ]  # @line L4
            f = _real_solve(c, s)  # @line L5
        resid = [yw[i] - sum(hm[i][j] * mx[j] for j in range(w + taps - 1)) + mx[j0] * s[i] for i in range(w)]  # @line L6
        xhat = sum(fi * ri for fi, ri in zip(f, resid))  # @line L6
        mu = sum(si * fi for si, fi in zip(s, f))  # @line L7
        out.append(2.0 * xhat / (1.0 - mu))  # @line L8
    return out  # @line L9
test_soft_interference_cancellation_equalizer.py 134 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/soft-interference-cancellation-equalizer/. The authors are listed in prov/G8QTJ4.jsonl.

import itertools
import math
import random

import pytest

import cbb
from soft_interference_cancellation_equalizer import siso_equalize, soft_symbols, window_matrix

PROAKIS_B = [0.407, 0.815, 0.407]


def received(rng, x, h, sigma):
    return [v.real + rng.gauss(0.0, sigma) for v in cbb.conv(x, h)]


def test_no_priors_give_the_mmse_linear_equalizer():
    rng = random.Random(3)
    h, s2, n1, n2, k = [1.0, 0.5], 0.2, 2, 2, 12
    x = [rng.choice((-1, 1)) for _ in range(k)]
    y = received(rng, x, h, math.sqrt(s2))
    le = siso_equalize(y, h, [0.0] * k, s2, n1, n2)
    w = n1 + n2 + 1
    hm = window_matrix(h, w)
    s = [row[n2 + len(h) - 1] for row in hm]
    r = [[sum(a * b for a, b in zip(hm[i], hm[q])) + (s2 if i == q else 0.0) for q in range(w)] for i in range(w)]
    f = [v.real for v in cbb.solve(r, s)]
    mu = sum(a * b for a, b in zip(f, s))
    for n in range(n2 + len(h) - 1, k - n1):
        z = sum(f[i] * y[n - n2 + i] for i in range(w))
        assert abs(le[n] - 2 * z / (1 - mu)) < 1e-9


def test_perfect_priors_give_the_matched_filter_after_cancellation():
    rng = random.Random(4)
    h, s2, n1, n2, k = PROAKIS_B, 0.3, 3, 2, 10
    x = [rng.choice((-1, 1)) for _ in range(k)]
    y = received(rng, x, h, math.sqrt(s2))
    le = siso_equalize(y, h, [50.0 * v for v in x], s2, n1, n2)
    for n in range(k):
        clean = cbb.conv([v if t != n else 0 for t, v in enumerate(x)], h)
        mf = sum(h[l] * (y[n + l] - clean[n + l].real) for l in range(len(h)))
        assert abs(le[n] - 2 * mf / s2) < 1e-9


def test_lmmse_by_enumeration_and_the_gaussian_moments():
    h, s2, n1, n2 = [0.9, -0.5], 0.4, 1, 1
    la = [0.7, -1.3, 2.1, 0.4, -0.2]
    y = [0.3, -1.1, 0.8, 0.5, -0.4, 0.2]
    n = 2
    le = siso_equalize(y, h, la, s2, n1, n2)
    xbar, _ = soft_symbols(la)
    rows = range(n - n2, n + n1 + 1)
    p1 = [(1 + m) / 2 for m in xbar]
    p1[n] = 0.5
    my = [0.0] * len(rows)
    cyy = [[0.0] * len(rows) for _ in rows]
    cxy = [0.0] * len(rows)
    for xs in itertools.product((1, -1), repeat=len(la)):
        p = math.prod(p1[t] if xs[t] == 1 else 1 - p1[t] for t in range(len(la)))
        clean = [v.real for v in cbb.conv(list(xs), h)]
        vals = [clean[m] for m in rows]
        for i, a in enumerate(vals):
            my[i] += p * a
            cxy[i] += p * xs[n] * a
            for q, b in enumerate(vals):
                cyy[i][q] += p * a * b
    cyy = [[cyy[i][q] - my[i] * my[q] + (s2 if i == q else 0.0) for q in range(len(rows))] for i in range(len(rows))]
    g = [v.real for v in cbb.solve(cyy, cxy)]
    xhat = sum(gi * (y[m] - mi) for gi, m, mi in zip(g, rows, my))
    mu = sum(gi * ci for gi, ci in zip(g, cxy))
    assert abs(le[n] - 2 * xhat / (1 - mu)) < 1e-9
    for sign in (1, -1):
        mean = 0.0
        second = 0.0
        for xs in itertools.product((1, -1), repeat=len(la)):
            if xs[n] != sign:
                continue
            p = 2 * math.prod(p1[t] if xs[t] == 1 else 1 - p1[t] for t in range(len(la)))
            clean = [v.real for v in cbb.conv(list(xs), h)]
            z = sum(gi * (clean[m] - mi) for gi, m, mi in zip(g, rows, my))
            mean += p * z
            second += p * z * z
        var = second - mean * mean + s2 * sum(gi * gi for gi in g)
        assert abs(mean - sign * mu) < 1e-9
        assert abs(var - (mu - mu * mu)) < 1e-9


def test_extrinsic_output_ignores_its_own_prior():
    rng = random.Random(5)
    h, s2, k = PROAKIS_B, 0.25, 9
    la = [rng.uniform(-3, 3) for _ in range(k)]
    y = [rng.gauss(0, 1) for _ in range(k + len(h) - 1)]
    base = siso_equalize(y, h, la, s2, 3, 3)
    for n in range(k):
        changed = list(la)
        changed[n] = -changed[n] + 4.0
        assert abs(siso_equalize(y, h, changed, s2, 3, 3)[n] - base[n]) < 1e-9


def test_approximate_form_is_exact_when_all_variances_are_equal():
    rng = random.Random(6)
    h, s2, n1, n2, k = PROAKIS_B, 0.25, 3, 3, 14
    la = [rng.choice((-1.5, 1.5)) for _ in range(k)]
    y = [rng.gauss(0, 1) for _ in range(k + len(h) - 1)]
    exact = siso_equalize(y, h, la, s2, n1, n2)
    approx = siso_equalize(y, h, la, s2, n1, n2, approx=True)
    for n in range(n2 + len(h) - 1, k - n1):
        assert abs(exact[n] - approx[n]) < 1e-9


def test_bit_error_rate_with_perfect_priors_matches_the_matched_filter_bound():
    rng = random.Random(1)
    k, sigma = 10000, 0.5
    x = [rng.choice((-1, 1)) for _ in range(k)]
    y = received(rng, x, PROAKIS_B, sigma)
    le = siso_equalize(y, PROAKIS_B, [50.0 * v for v in x], sigma * sigma, 2, 2, approx=True)
    errors = sum((l < 0) != (v < 0) for l, v in zip(le, x))
    p = cbb.qfunc(math.sqrt(sum(v * v for v in PROAKIS_B)) / sigma)
    assert k * p >= 100
    lo, hi = cbb.wilson(errors, k)
    assert lo <= p <= hi


def test_bad_input():
    with pytest.raises(ValueError):
        siso_equalize([0.0] * 4, [1.0, 0.5], [0.0] * 3, 0.0, 1, 1)
    with pytest.raises(ValueError):
        siso_equalize([0.0] * 4, [1.0, 0.5], [0.0] * 3, 0.1, 0, 1)
    with pytest.raises(ValueError):
        siso_equalize([0.0] * 3, [1.0, 0.5], [0.0] * 3, 0.1, 1, 1)

History

Wang and Poor (1999) combined soft interference cancellation with an MMSE filter in an iterative receiver for coded CDMA. Tüchler, Koetter and Singer (2002) and Tüchler, Singer and Koetter (2002) worked out the MMSE equalizer with a priori information for turbo equalization, with exact and approximate forms, and showed that it comes close to the MAP equalizer at much lower cost. Koetter, Singer and Tüchler (2004) gave a tutorial on the method.

References

  1. Michael Tüchler, Ralf Koetter and Andrew C. Singer, Turbo equalization: principles and new results, IEEE Transactions on Communications 50(5), 2002, pages 754 to 767, the linear MMSE equalizer with a priori information inside the turbo loop, its exact and approximate forms, and the comparison with the MAP equalizer
  2. Michael Tüchler, Andrew C. Singer and Ralf Koetter, Minimum mean squared error equalization using a priori information, IEEE Transactions on Signal Processing 50(3), 2002, pages 673 to 683, the MMSE filter whose coefficients are recomputed for each symbol from the prior means and variances
  3. Ralf Koetter, Andrew C. Singer and Michael Tüchler, Turbo equalization, IEEE Signal Processing Magazine 21(1), 2004, pages 67 to 80, a tutorial on turbo equalization with the MAP and the MMSE equalizers
  4. Xiaodong Wang and H. Vincent Poor, Iterative (turbo) soft interference cancellation and decoding for coded CDMA, IEEE Transactions on Communications 47(7), 1999, pages 1046 to 1061, soft interference cancellation with the decoder outputs, followed by an MMSE filter

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example