Algorithmcore
Max-log demapping
Also called max-log LLR approximation.
Approximates each bit LLR by the squared distance to the nearest point with the bit 1, minus that to the nearest point with the bit 0, over N0. It needs no exponentials.
- Time
- Θ(M log M) worst
- Space
- Θ(M) extra
- Where
- M = the number of constellation points; m = the number of bits per point (log2 M)
- Model
- Real RAM
- Properties
- accepts priorsdeterministicnot exactnot needs noise level
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Ephraim Zehavi, 1992
Max-log demapping computes an approximate log-likelihood ratio (LLR) for each bit of a received symbol. The exact LLR of soft demapping is the log of a ratio of two sums of exponentials, one over the points whose bit is and one over the points whose bit is . Max-log keeps only the largest term of each sum. Without priors, the result is the squared distance from the received sample to the nearest point with the bit , minus the squared distance to the nearest point with the bit , divided by . It needs no and no , its signs are the bits of the minimum distance detector, and its error is at most per bit. For Gray square QAM it falls apart into simple piecewise linear functions of the in-phase and quadrature components. Most hardware receivers for bit-interleaved coded modulation use it.
In plain words
For each bit, the receiver asks two questions. Of all the points whose bit is 0, which one is nearest to what I received, and how far is it? And the same for the points whose bit is 1. If the nearest "0" point is much nearer than the nearest "1" point, the bit is very likely 0. The difference of the two squared distances is the answer: its sign gives the bit, and its size gives the confidence. The method ignores all points except the two nearest ones in each comparison. That makes it cheap, and at a good signal level it loses almost nothing.
The problem
The receiver sees , where is one of the points , carries the bit label with bits (most significant first), is a known gain, is the imaginary unit and . The optional prior LLRs are . With the point metric
the exact LLR is , and the max-log LLR is
Without priors, . A positive value favors the bit .
The algorithm
MAX-LOG-DEMAP(y, h, N0, a_0..a_{M-1}, La_0..La_{m-1}) ▷ a_i has the label i; La = 0 without priors- 1
for i ← 0 to M - 1 - 2
d_i ← -|y - h·a_i|² / N0 + Σ_k (1 - 2·b_k(i)) · La_k / 2 - 3
for k ← 0 to m - 1 - 4
B_0 ← -∞ ; B_1 ← -∞ - 5
for i ← 0 to M - 1 - 6
B_{b_k(i)} ← max(B_{b_k(i)}, d_i) - 7
L_k ← B_0 - B_1 - 8
return L_0..L_{m-1} and the extrinsic values E_k ← L_k - La_k
The only difference from the exact demapper is line L6, which uses where the exact demapper uses .
Gray square QAM, one axis at a time. Write , scale each axis to the raw amplitudes with , and put and . Since for the point with raw levels , the in-phase bits depend only on and the quadrature bits only on . For 16-QAM with the labels of the area (in-phase level with the labels ),
and , , , . For example, for the nearest in-phase levels with the first bit and are and , and .
Example
Take Gray 16-QAM, , and , the example of the soft demapping page. Then and , both inside :
| bit | formula | max-log | exact |
|---|---|---|---|
| 0 | |||
| 1 | |||
| 2 | |||
| 3 |
The signs give the label 0111 of the nearest point , and the values are within of the exact ones. The brute-force form gives the same: for bit 1, the nearest point with is and the nearest with is , and .
At , the max-log values are ten times smaller, , while the exact values are . At a low SNR many points contribute to each sum, and the largest term is no longer a good stand-in for the whole sum.
Correctness
Max-log demapping does not compute the exact LLR; what is proved is that it computes the max form and how far that is from the exact value. Lines L4 to L6 keep the invariant that is the largest seen so far among the points with , so line L7 returns . Without priors, , which gives the distance form. Each sum in the exact LLR has terms, each at most its largest, so for each bit value, and . The point with the largest lies in one of the two sets of each bit, so the sign of is the bit of the MAP decision (of the ML decision without priors). The per-axis form for square QAM follows from the separation of into an in-phase and a quadrature term; the term of the other axis is the same in both minima and cancels. The full proof is below.
Proof: MAX-LOG-DEMAP returns the max form, its signs are the MAP bits, and its error is at most ln(M/2)full
The model and the notation are those of the page: with and known, , the points with , the label bits , and the metric of line L2. For a bit and a value , write . Since the labels are all of , each has exactly elements.
Lemma 1 (the fold). Fix . After line L6 has run for the points , for , with . So line L7 returns , and both terms are finite.
Proof. By induction on . For line L4 sets both to . Step : with , line L6 sets to , the maximum over the enlarged set, and leaves the other value unchanged. After both sets are full, and they are nonempty.
Lemma 2 (the distance form). Without priors, . In particular does not depend on .
Proof. Here with , and for any finite set .
Lemma 3 (the sandwich). For a finite set of indices, .
Proof. Let . The sum contains the term and every term is positive, so it is at least . Every term is at most , so the sum is at most . Take logs.
Theorem. Let be the exact LLR of soft demapping.
- for every .
- If is a point with the largest (the MAP decision; without priors, the nearest point to after the gain), then when and when . If is the only maximizer, the inequalities are strict, and the hard decisions are the bits of .
- For and for Gray QPSK, .
Proof. (1) Write . By Lemma 3 with , . Then , which lies in .
(2) Let . Then , so , and because is the largest of all metrics. So the term for is at least the term for , which gives the signs. If is the only maximizer, every has , and since the set is finite the maximum over it is also smaller. Without priors, is largest exactly where is smallest.
(3) For , and the bound of part 1 is . For Gray QPSK, the points are with , the bit 0 fixes and the bit 1 fixes . Expanding the square, with the same for all points, and ; with priors, each bit adds , which keeps this form. For the bit 0, both and over equal the term in plus the same function of (a log-sum-exp in one case and a max in the other), and that function cancels in the difference. So plus the prior, and in the same way .
Proposition (per-axis form for Gray square QAM). Let the points be with , where runs over all pairs of raw levels and the label is the Gray label of followed by that of . Put , , . Without priors, for an in-phase bit ,
and the same holds for a quadrature bit with and .
Proof. , so . An in-phase bit depends only on , and the set of points is the full product of the levels, so
The second term is the same for and and cancels in Lemma 2.
Corollary (16-QAM). With the in-phase levels labeled , the first bit is on and the second bit is on . For , the nearest level with the first bit is , and the nearest with the first bit is if and if . So the bracket is or . For the second bit and , the nearest levels are (bit ) and (bit ), and the bracket is . For the same follows by the symmetry , which swaps and ; it changes the sign of the first bracket and keeps the second. With this is the closed form on the page.
Cost. Line L2 runs times, with extra terms each when there are priors, and line L6 runs times, each a constant number of operations. The total is per symbol with extra space. The per-axis form scans levels for each of the bits, .
Complexity
In the real RAM, lines L1 and L2 cost without priors and with them, and lines L3 to L7 do comparisons. The total is per symbol with extra space; the work is the same as for the exact demapper, but each step is a comparison, not an and a . For Gray square QAM the per-axis form costs in general and with closed forms such as the one for 16-QAM. With a decision region search, the nearest point with each bit value can be found without visiting all points.
Properties
- No noise level needed for the decoder. Without priors, every is the same function of times . A min-sum decoder, a Viterbi decoder or a max-log BCJR decoder gives the same output for any positive scale of its inputs, so the receiver can skip and pass the distance differences.
- Hard decisions are ML decisions. The signs of are the label of the nearest point.
- Error bound. , which is for 16-QAM. The bound is approached only when the terms of one sum are nearly equal and those of the other are not, as at low SNR. At high SNR the second largest term of each sum is usually much smaller than the largest, and the error is small, except near the boundary between two points with the same bit value.
- Exact for BPSK and QPSK. For BPSK each sum has one term. For Gray QPSK, each sum has two terms that differ by the same factor in the numerator and the denominator, and the factor cancels. In both cases .
- Piecewise linear. Each is piecewise linear in the real and imaginary parts of , with breaks where the nearest point with a bit value changes.
- Biased at low SNR. In the example at , while . The magnitudes can be too small or too large, so a fixed scaling does not remove the error.
Variants and improvements
- Exact demapping. Replace by : soft demapping.
- Max-log with a correction. Add a table value of in line L6 only when the two terms are close. This recovers most of the loss at a small cost.
- Scaled max-log. Multiply the LLRs by a constant factor, tuned by simulation for the decoder and the SNR range. It reduces the average error but cannot remove it.
- Per-axis closed forms for QAM. For Gray -QAM each bit is a piecewise linear function of one axis, with closed forms like the 16-QAM one above. OFDM receivers use them per subcarrier.
- MIMO. For a vector channel, max-log needs the nearest vector with each bit value; a list sphere decoder or a tree search finds it without visiting all vectors.
When to use it
Use max-log when the decoder is a min-sum decoder or a max-log BCJR decoder, when is unknown or hard to estimate, and when cost or latency matters, as in hardware for Wi-Fi, LTE and DVB. Use the exact demapper at low SNR with large constellations, and in iterative receivers, where the extrinsic values must be accurate.
Pitfalls
- A sum-product decoder expects exact LLRs. A sum-product LDPC decoder assumes exact LLRs. With max-log inputs it still works but loses a fraction of a dB, more at low rates and with large constellations.
- Scale. If the receiver drops , the decoder must also be scale invariant. A sum-product decoder fed with unscaled distances is wrong.
- Ties. On a decision boundary , and the hard decision is arbitrary. It has probability zero but occurs with quantized inputs; break ties in a fixed way.
- Closed forms depend on the labeling. The 16-QAM formulas above hold for the area labels (in-phase bits first, Gray per axis). A different labeling or bit order needs different formulas.
- The gain. The per-axis forms need and the factor . Dropping on a fading channel gives the same weight to faded and strong symbols, which hurts the decoder.
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/.
"""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))
max_log_demapping.py 120 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/max-log-demapping/. The authors are listed in prov/BTM11T.jsonl.
"""Max-log demapping: approximate bit log-likelihood ratios without exponentials.
The model is y = h x + w with w ~ CN(0, N0), a known gain h and x one of the
M points of a constellation. points[i] is the point with the bit label i, and
bit k of the label (k = 0 is the most significant bit) is (i >> (m - 1 - k)) & 1
with m = log2 M, as in constel.py. The max-log LLR of bit k is
L_k = max_{b_k(i) = 0} d_i - max_{b_k(i) = 1} d_i,
d_i = -|y - h a_i|^2 / N0 + sum_k (1 - 2 b_k(i)) la_k / 2,
which without priors is (min over bit 1 of |y - h a|^2 - min over bit 0) / N0.
A positive value favors the bit 0.
"""
import math
def label_bit(i: int, k: int, m: int) -> int:
"""Bit k (most significant first) of the m-bit label i."""
return (i >> (m - 1 - k)) & 1
def _check(points: list[complex], n0: float) -> int:
big_m = len(points)
if big_m < 2 or big_m & (big_m - 1):
raise ValueError("the number of points must be a power of two")
if n0 <= 0:
raise ValueError("N0 must be positive")
return big_m.bit_length() - 1
def max_log_demap(y: complex, points: list[complex], n0: float, h: complex = 1, la: list[float] | None = None) -> list[float]:
"""The max-log LLRs L_0, ..., L_{m-1} of the bits of one symbol."""
m = _check(points, n0)
d = []
for i, a in enumerate(points): # @line L1
di = -abs(y - h * a) ** 2 / n0 # @line L2
if la is not None:
di += sum((1 - 2 * label_bit(i, k, m)) * la[k] / 2.0 for k in range(m))
d.append(di)
out = []
for k in range(m): # @line L3
best = [-math.inf, -math.inf] # @line L4
for i in range(len(points)): # @line L5
b = label_bit(i, k, m)
if d[i] > best[b]:
best[b] = d[i] # @line L6
out.append(best[0] - best[1]) # @line L7
return out
def max_log_extrinsic(y: complex, points: list[complex], n0: float, h: complex = 1, la: list[float] | None = None) -> list[float]:
"""The extrinsic values L_k - la_k of the max-log demapper."""
post = max_log_demap(y, points, n0, h, la)
if la is None:
return post
return [p - a for p, a in zip(post, la)] # @line L8
def _gray_inv(g: int) -> int:
n = 0
while g:
n ^= g
g >>= 1
return n
def _axis(u: float, side: int) -> list[float]:
"""Per-axis max-log values (min over bit 1 of (u - c)^2 minus min over bit 0) on Gray side-PAM.
The level with label lab has the raw amplitude side - 1 - 2 gray^-1(lab).
"""
q = side.bit_length() - 1
best = [[math.inf, math.inf] for _ in range(q)]
for lab in range(side):
c = side - 1 - 2 * _gray_inv(lab)
dist = (u - c) ** 2
for k in range(q):
b = label_bit(lab, k, q)
if dist < best[k][b]:
best[k][b] = dist
return [b1 - b0 for b0, b1 in best]
def max_log_square_qam(y: complex, big_m: int, n0: float, h: complex = 1) -> list[float]:
"""Max-log LLRs for Gray square M-QAM (as constel.qam), one axis at a time in O(sqrt(M) log M)."""
q2 = big_m.bit_length() - 1
if big_m < 4 or big_m & (big_m - 1) or q2 % 2:
raise ValueError("square QAM needs M = 4^k")
if n0 <= 0:
raise ValueError("N0 must be positive")
if h == 0:
raise ValueError("the gain must be nonzero")
side = 1 << (q2 // 2)
s2 = 2.0 * (big_m - 1) / 3.0
z = y / h
s = math.sqrt(s2)
scale = abs(h) ** 2 / (s2 * n0)
return [scale * v for v in _axis(s * z.real, side) + _axis(s * z.imag, side)]
def max_log_16qam_closed_form(y: complex, n0: float, h: complex = 1) -> list[float]:
"""The closed form for Gray 16-QAM: per axis with u = sqrt(10) Re(y / h) (and the same for Im),
Lambda_0 = 4u if |u| <= 2 else 8(u - sign u), Lambda_1 = 4(|u| - 2), and L = |h|^2 Lambda / (10 N0)."""
if n0 <= 0:
raise ValueError("N0 must be positive")
z = y / h
scale = abs(h) ** 2 / (10.0 * n0)
out0, out1 = [], []
for u in (math.sqrt(10.0) * z.real, math.sqrt(10.0) * z.imag):
if abs(u) <= 2.0:
lam0 = 4.0 * u
else:
lam0 = 8.0 * (u - math.copysign(1.0, u))
out0.append(lam0)
out1.append(4.0 * (abs(u) - 2.0))
return [scale * out0[0], scale * out1[0], scale * out0[1], scale * out1[1]]
test_max_log_demapping.py 181 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/max-log-demapping/. The authors are listed in prov/BTM11T.jsonl.
import math
import random
import unittest
import constel
from max_log_demapping import max_log_16qam_closed_form, max_log_demap, max_log_extrinsic, max_log_square_qam
def brute_max(y, points, n0, h=1, la=None):
"""The max form by brute force: the best metric with bit 0 minus the best with bit 1."""
m = len(points).bit_length() - 1
d = []
for i, a in enumerate(points):
v = -abs(y - h * a) ** 2 / n0
if la is not None:
v += sum((1 - 2 * constel.bits(i, m)[k]) * la[k] / 2.0 for k in range(m))
d.append(v)
out = []
for k in range(m):
b0 = max(d[i] for i in range(len(points)) if constel.bits(i, m)[k] == 0)
b1 = max(d[i] for i in range(len(points)) if constel.bits(i, m)[k] == 1)
out.append(b0 - b1)
return out
def min_distance_form(y, points, n0, h=1):
"""(min over bit 1 of |y - h a|^2 - min over bit 0 of |y - h a|^2) / N0."""
m = len(points).bit_length() - 1
out = []
for k in range(m):
d0 = min(abs(y - h * a) ** 2 for i, a in enumerate(points) if constel.bits(i, m)[k] == 0)
d1 = min(abs(y - h * a) ** 2 for i, a in enumerate(points) if constel.bits(i, m)[k] == 1)
out.append((d1 - d0) / n0)
return out
def exact_llr(y, points, n0, h=1):
"""The exact LLRs as a log-sum-exp over all points."""
m = len(points).bit_length() - 1
d = [-abs(y - h * a) ** 2 / n0 for a in points]
out = []
for k in range(m):
acc = []
for b in (0, 1):
vals = [d[i] for i in range(len(points)) if constel.bits(i, m)[k] == b]
top = max(vals)
acc.append(top + math.log(sum(math.exp(v - top) for v in vals)))
out.append(acc[0] - acc[1])
return out
CONSTELLATIONS = {
"bpsk": constel.pam(2),
"4pam": constel.pam(4),
"8pam": constel.pam(8),
"qpsk": constel.qam(4),
"8psk": constel.psk(8),
"16psk": constel.psk(16, math.pi / 16),
"16qam": constel.qam(16),
"64qam": constel.qam(64),
}
def sample(rng, pts):
h = complex(rng.gauss(0, 1), rng.gauss(0, 1))
n0 = 10 ** rng.uniform(-2.5, 0.5)
x = pts[rng.randrange(len(pts))]
y = h * x + complex(rng.gauss(0, 1), rng.gauss(0, 1)) * math.sqrt(n0 / 2)
return y, n0, h
class TestMaxLogDemapping(unittest.TestCase):
def test_equals_max_form_exactly(self):
rng = random.Random(20261120)
for name, pts in CONSTELLATIONS.items():
for _ in range(60):
y, n0, h = sample(rng, pts)
self.assertEqual(max_log_demap(y, pts, n0, h), brute_max(y, pts, n0, h), name)
def test_min_distance_form(self):
rng = random.Random(3)
for name, pts in CONSTELLATIONS.items():
for _ in range(40):
y, n0, h = sample(rng, pts)
for g, r in zip(max_log_demap(y, pts, n0, h), min_distance_form(y, pts, n0, h)):
self.assertLess(abs(g - r), 1e-9 * max(1.0, abs(r)), name)
def test_bound_against_exact(self):
rng = random.Random(5)
for name, pts in CONSTELLATIONS.items():
bound = math.log(len(pts) / 2)
for _ in range(60):
y, n0, h = sample(rng, pts)
for g, r in zip(max_log_demap(y, pts, n0, h), exact_llr(y, pts, n0, h)):
self.assertLessEqual(abs(g - r), bound + 1e-9, name)
def test_equal_to_exact_for_bpsk_and_qpsk(self):
rng = random.Random(6)
for name in ("bpsk", "qpsk"):
pts = CONSTELLATIONS[name]
for _ in range(100):
y, n0, h = sample(rng, pts)
for g, r in zip(max_log_demap(y, pts, n0, h), exact_llr(y, pts, n0, h)):
self.assertLess(abs(g - r), 1e-9 * max(1.0, abs(r)), name)
def test_scales_with_one_over_n0(self):
rng = random.Random(8)
pts = CONSTELLATIONS["16qam"]
for _ in range(50):
y = complex(rng.gauss(0, 1), rng.gauss(0, 1))
a = max_log_demap(y, pts, 1.0)
b = max_log_demap(y, pts, 0.01)
for u, v in zip(a, b):
self.assertLess(abs(100.0 * u - v), 1e-9 * max(1.0, abs(v)))
def test_signs_give_ml_bits(self):
rng = random.Random(9)
for name, pts in CONSTELLATIONS.items():
m = len(pts).bit_length() - 1
for _ in range(60):
y, n0, h = sample(rng, pts)
ml = constel.bits(constel.ml_detect(y, pts, h), m)
llr = max_log_demap(y, pts, n0, h)
self.assertEqual([1 if v < 0 else 0 for v in llr], ml, name)
def test_square_qam_per_axis(self):
rng = random.Random(10)
for big_m in (4, 16, 64, 256):
pts = constel.qam(big_m)
for _ in range(40):
y, n0, h = sample(rng, pts)
for g, r in zip(max_log_square_qam(y, big_m, n0, h), max_log_demap(y, pts, n0, h)):
self.assertLess(abs(g - r), 1e-9 * max(1.0, abs(r)), big_m)
def test_16qam_closed_form(self):
rng = random.Random(11)
pts = constel.qam(16)
for _ in range(300):
y, n0, h = sample(rng, pts)
for g, r in zip(max_log_16qam_closed_form(y, n0, h), max_log_demap(y, pts, n0, h)):
self.assertLess(abs(g - r), 1e-9 * max(1.0, abs(r)))
def test_page_example(self):
pts = constel.qam(16)
y = 0.5 - 0.2j
for g, r in zip(max_log_demap(y, pts, 0.1), [6.3246, -1.6754, -2.5298, -5.4702]):
self.assertAlmostEqual(g, r, delta=1e-4)
for g, r in zip(exact_llr(y, pts, 0.1), [6.4962, -1.6772, -2.5340, -5.5463]):
self.assertAlmostEqual(g, r, delta=1e-4)
for g, r in zip(max_log_demap(y, pts, 1.0), [0.6325, -0.1675, -0.2530, -0.5470]):
self.assertAlmostEqual(g, r, delta=1e-4)
def test_priors_and_extrinsic(self):
rng = random.Random(12)
for name in ("8psk", "16qam", "64qam"):
pts = CONSTELLATIONS[name]
m = len(pts).bit_length() - 1
for _ in range(40):
la = [rng.uniform(-6, 6) for _ in range(m)]
y, n0, h = sample(rng, pts)
got = max_log_demap(y, pts, n0, h, la)
self.assertEqual(got, brute_max(y, pts, n0, h, la), name)
ext = max_log_extrinsic(y, pts, n0, h, la)
for e, g, a in zip(ext, got, la):
self.assertAlmostEqual(e, g - a, delta=1e-12)
def test_errors(self):
pts = constel.qam(16)
with self.assertRaises(ValueError):
max_log_demap(0.1, pts[:3], 0.3)
with self.assertRaises(ValueError):
max_log_demap(0.1, pts, 0.0)
with self.assertRaises(ValueError):
max_log_square_qam(0.1, 8, 0.3)
if __name__ == "__main__":
unittest.main()
History
The max approximation of a sum of exponentials is old; in decoding it appears as the Viterbi metric and as the max-log form of the BCJR algorithm. For bit metrics of a multilevel constellation, Zehavi in 1992 decoded bit-interleaved 8-PSK trellis codes on the Rayleigh channel with a metric per bit of this form, and Caire, Taricco and Biglieri in 1998 gave the theory of bit-interleaved coded modulation with both the exact and the simplified metrics. With LDPC and turbo codes in Wi-Fi, LTE and DVB, the max-log demapper with per-axis closed forms became the common choice in hardware.
References
- Ephraim Zehavi, 8-PSK trellis codes for a Rayleigh channel, IEEE Transactions on Communications 40(5), 873-884, 1992, the bit interleaver and the bit metrics of the decoder
- Giuseppe Caire, Giorgio Taricco and Ezio Biglieri, Bit-interleaved coded modulation, IEEE Transactions on Information Theory 44(3), 927-946, 1998, the bit metrics of BICM and their simplified form
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 BTM11T Edit this page History Report an error Markdown