ConvEncoder#

class sionna.phy.fec.conv.ConvEncoder(gen_poly: Tuple[str, ...] | None = None, rate: float = 0.5, constraint_length: int = 3, rsc: bool = False, terminate: bool = False, precision: str | None = None, device: str | None = None, **kwargs)[source]#

Bases: sionna.phy.block.Block

Encodes an information binary tensor to a convolutional codeword.

Currently, only generator polynomials for codes of rate=1/n for n=2,3,4,… are allowed.

Parameters:
  • gen_poly (Tuple[str, ...] | None) – Sequence of strings with each string being a 0,1 sequence. If None, rate and constraint_length must be provided.

  • rate (float) – Valid values are 1/3 and 0.5. Only required if gen_poly is None.

  • constraint_length (int) – Valid values are between 3 and 8 inclusive. Only required if gen_poly is None.

  • rsc (bool) – Boolean flag indicating whether the Trellis generated is recursive systematic or not. If True, the encoder is recursive-systematic. In this case first polynomial in gen_poly is used as the feedback polynomial. Defaults to False.

  • terminate (bool) – Encoder is terminated to all zero state if True. If terminated, the true rate of the code is slightly lower than rate.

  • precision (str | None) – Precision used for internal calculations and outputs. If None, precision is used.

  • device (str | None) – Device for computation (e.g., ‘cpu’, ‘cuda:0’). If None, device is used.

Inputs:

bits – […, k], torch.float. Binary tensor containing the information bits where k is the information length.

Outputs:

cw – […, k/rate], torch.float. Binary tensor containing the encoded codeword for the given input information tensor where rate is \(\frac{1}{\textrm{len}\left(\textrm{gen\_poly}\right)}\) (if gen_poly is provided).

Notes

The generator polynomials from [Moon] are available for various rate and constraint lengths. To select them, use the rate and constraint_length arguments.

In addition, polynomials for any non-recursive convolutional encoder can be given as input via gen_poly argument. Currently, only polynomials with rate=1/n are supported. When the gen_poly argument is given, the rate and constraint_length arguments are ignored.

Various notations are used in the literature to represent the generator polynomials for convolutional codes. In [Moon], the octal digits format is primarily used. In the octal format, the generator polynomial 10011 corresponds to 46. Another widely used format is decimal notation with MSB. In this notation, polynomial 10011 corresponds to 19. For simplicity, the ConvEncoder only accepts the bit format i.e. 10011 as gen_poly argument.

Also note that constraint_length and memory are two different terms often used to denote the strength of a convolutional code. In this sub-package, we use constraint_length. For example, the polynomial 10011 has a constraint_length of 5, however its memory is only 4.

When terminate is True, the true rate of the convolutional code is slightly lower than rate. It equals \(\frac{r*k}{k+\mu}\) where r denotes rate and \(\mu\) is constraint_length - 1. For example when terminate is True, k=100, \(\mu=4\) and rate =0.5, true rate equals \(\frac{0.5*100}{104}=0.481\).

Examples

from sionna.phy.fec.conv import ConvEncoder

encoder = ConvEncoder(rate=0.5, constraint_length=5)
u = torch.randint(0, 2, (10, 100), dtype=torch.float32)
c = encoder(u)
print(c.shape)
# torch.Size([10, 200])

Attributes

property gen_poly: Tuple[str, ...]#

Generator polynomial used by the encoder

property coderate: float#

Rate of the code used in the encoder

property trellis: sionna.phy.fec.conv.utils.Trellis#

Trellis object used during encoding

property terminate: bool#

Indicates if the convolutional encoder is terminated

property k: int | None#

Number of information bits per codeword

property n: int | None#

Number of codeword bits

Methods

build(input_shape: torch.Size)[source]#

Build block and check dimensions.

Parameters:

input_shape (torch.Size) – Shape of input tensor (…, k)