comnum.TurboCode#
- class comnum.TurboCode(k, *, iterations=8, max_log=False, qpp=None, seed=7, puncture=None)#
The turbo code of LTE: two (13, 15) recursive systematic codes in parallel, rate about 1/3, decoded by iterative log-MAP (Berrou, Glavieux & Thitimajshima 1993). The interleaver is the QPP
(f1, f2)if given ("lte": the coefficients of LTE fork, TS 36.212 Table 5.1.3-3), else a random permutation.puncturepunctures the systematic and the two parity streams by a pattern of three rows applied at every information index (the tail bits are kept): the name"turbo_1_2"(systematic 1 1, parity 1: 1 0, parity 2: 0 1, the rate-1/2 code of Berrou et al. 1993, Sec. II) or the rows of a pattern.- Parameters:
k (int) – information bits per block.
iterations (int) – decoding iterations.
max_log (bool) – max-log-MAP (else log-MAP, the exact Jacobian logarithm).
qpp (str | tuple[int, int] | None) – the QPP interleaver
(f1, f2), or"lte".seed (int) – seed of the random interleaver.
puncture (str | list[list[int]] | None) – the puncturing pattern (three rows).
- Raises:
ValueError – for an invalid parameter or input (the message names it).
Examples
>>> import comnum, numpy as np >>> code = comnum.TurboCode(40, qpp=(3, 10), puncture="turbo_1_2") >>> (code.n, round(code.rate, 3)) (92, 0.435)
- decode(llr)#
Decode whole blocks of LLRs (iterative log-MAP).
- Parameters:
llr (array_like) – a multiple of
nLLRs (positive for a 0).- Returns:
kbits per block (uint8).- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
Examples
>>> import comnum, numpy as np >>> code = comnum.TurboCode(40) >>> b = comnum.bits(40, comnum.Rng(1)) >>> bool(np.array_equal(code.decode(2.0 - 4.0 * code.encode(b)), b)) True
- encode(bits)#
Encode whole blocks.
- Parameters:
bits (array_like) – a multiple of
kbits.- Returns:
ncoded bits per block (uint8).- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
Examples
>>> import comnum >>> comnum.TurboCode(40).encode(comnum.bits(80, comnum.Rng(1))).size 264
- puncture#
The rows of the puncturing pattern (systematic, parity 1, parity 2),
Nonewithout puncturing.