comnum.PolarCode#

class comnum.PolarCode(n, k, *, design_ebn0_db=2.0, crc=None, list_size=1)#

A polar code of length n (a power of two) and k information bits, built by the Gaussian approximation at design_ebn0_db (Trifonov 2012); decoded by SC (Arıkan 2009), or SC list of size list_size (Tal & Vardy 2015) with the CRC crc choosing the path (CA-SCL).

Parameters:
  • n (int) – coded bits per block, a power of two.

  • k (int) – information bits per block.

  • design_ebn0_db (float) – the Eb/N0 of the construction (dB).

  • crc (str, optional) – the CRC of the list decoder (a name of Crc).

  • list_size (int) – the list size L (1 for SC).

Raises:

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

Examples

>>> import comnum, numpy as np
>>> code = comnum.PolarCode(128, 64, crc="crc6", list_size=8)
>>> b = comnum.bits(64, comnum.Rng(2))
>>> llr = 4.0 * (1.0 - 2.0 * code.encode(b))
>>> bool(np.array_equal(code.decode(llr), b))
True
decode(llr)#

Decode whole blocks of LLRs (SC or CA-SCL).

Parameters:

llr (array_like) – a multiple of n LLRs (positive for a 0).

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.PolarCode(64, 32)
>>> b = comnum.bits(32, 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 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.PolarCode(64, 32).encode(comnum.bits(64, comnum.Rng(1))).size
128
info_positions#

The positions of the information and CRC bits (int64).

Type:

numpy.ndarray

k#

Information bits per block.

Type:

int

n#

Coded bits per block.

Type:

int

rate#

Code rate.

Type:

float