comnum.ConvolutionalCode#
- class comnum.ConvolutionalCode(k, *, generators=Ellipsis, constraint=7, hard_decision=False, puncture=None)#
A terminated rate-1/n convolutional code on blocks of
kbits, decoded by Viterbi (Viterbi 1967): the (133, 171) code of constraint length 7 by default, punctured bypuncture(Cain, Clark & Geist 1979): the name of a pattern of a standard ("ieee80211_2_3","ieee80211_3_4","ieee80211_5_6"of IEEE 802.11-2020, Sec. 17.3.5.6 and 19.3.11.6;"dvbs_2_3","dvbs_3_4","dvbs_5_6","dvbs_7_8"of ETSI EN 300 421, Table 1) or the rows of a pattern, rowithe outputi([[1, 1, 0], [1, 0, 1]]). The receiver puts a zero LLR at every punctured position.The code follows the contract of every code of the package:
encodemaps whole blocks ofkbits toncoded bits,decodewhole blocks ofnLLRs (positive for a 0) tokbits.- Parameters:
- Raises:
ValueError – for an invalid parameter or input (the message names it).
Examples
>>> import comnum, numpy as np >>> code = comnum.ConvolutionalCode(100) >>> b = comnum.bits(100, comnum.Rng(1)) >>> c = code.encode(b) >>> llr = 4.0 * (1.0 - 2.0 * c) >>> bool(np.array_equal(code.decode(llr), b)) True >>> punctured = comnum.ConvolutionalCode(100, puncture="ieee80211_3_4") >>> (punctured.n, round(punctured.rate, 3)) (142, 0.704) >>> bool(np.array_equal(punctured.decode(4.0 * (1.0 - 2.0 * punctured.encode(b))), b)) True
- decode(llr)#
Decode whole blocks of LLRs (Viterbi).
- Parameters:
llr (array_like) – a multiple of
nLLRs (positive for a 0; 0 at the punctured positions is added by the code).- 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.ConvolutionalCode(10) >>> b = comnum.bits(20, comnum.Rng(1)) >>> bool(np.array_equal(code.decode(1.0 - 2.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.ConvolutionalCode(10).encode(comnum.bits(20, comnum.Rng(1))).size 64
- free_distance()#
The free distance of the (punctured) code (see
free_distance()).- Returns:
the free distance.
- Return type:
- Raises:
ValueError – for an invalid parameter (the message names it).
- puncture#
The rows of the puncturing pattern (row
ithe outputi),Nonewithout puncturing.