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 k bits, decoded by Viterbi (Viterbi 1967): the (133, 171) code of constraint length 7 by default, punctured by puncture (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, row i the output i ([[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: encode maps whole blocks of k bits to n coded bits, decode whole blocks of n LLRs (positive for a 0) to k bits.

Parameters:
  • k (int) – information bits per block.

  • generators (list[int]) – octal generators (write them as 0o133).

  • constraint (int) – constraint length K.

  • hard_decision (bool) – decode the signs of the LLRs only.

  • puncture (str | list[list[int]] | None) – the puncturing pattern.

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 n LLRs (positive for a 0; 0 at the punctured positions is added by the code).

Returns:

k bits per block (uint8).

Return type:

numpy.ndarray

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 k bits.

Returns:

n coded bits per block (uint8).

Return type:

numpy.ndarray

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:

int

Raises:

ValueError – for an invalid parameter (the message names it).

k#

Information bits per block.

Type:

int

n#

Coded bits per block (tail included, after puncturing).

Type:

int

puncture#

The rows of the puncturing pattern (row i the output i), None without puncturing.

Type:

list[list[int]] | None

rate#

Code rate k / n (after puncturing).

Type:

float