ViterbiDecoder#

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

Bases: sionna.phy.block.Block

Applies Viterbi decoding to a sequence of noisy codeword bits.

Implements the Viterbi decoding algorithm [Viterbi] that returns an estimate of the information bits for a noisy convolutional codeword. Takes as input either LLR values (method = 'soft_llr') or hard bit values (method = 'hard') and returns a hard decided estimation of the information bits.

Parameters:
  • encoder (ConvEncoder | None) – If encoder is provided as input, the following input parameters are not required and will be ignored: gen_poly, rate, constraint_length, rsc, terminate. They will be inferred from the encoder object itself. If None, the above parameters must be provided explicitly.

  • gen_poly (Tuple[str, ...] | None) – Tuple 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 encoder is recursive-systematic for given generator polynomials. True indicates encoder is recursive-systematic. False indicates encoder is feed-forward non-systematic. Defaults to False.

  • terminate (bool) – Boolean flag indicating whether the codeword is terminated. True indicates codeword is terminated to all-zero state. False indicates codeword is not terminated. Defaults to False.

  • method (str) – Valid values are 'soft_llr' or 'hard'. In computing path metrics, 'soft_llr' expects channel LLRs as input. 'hard' assumes a binary symmetric channel (BSC) with 0/1 values as inputs. In case of 'hard', inputs will be quantized to 0/1 values.

  • return_info_bits (bool) – Boolean flag indicating whether only the information bits or all codeword bits are returned. Defaults to True.

  • 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:

inputs – […, n], torch.float. Tensor containing the (noisy) channel output symbols where n denotes the codeword length.

Outputs:

output – […, rate * n], torch.float. Binary tensor containing the estimates of the information bit tensor.

Notes

A full implementation of the decoder rather than a windowed approach is used. For a given codeword of duration T, the path metric is computed from time 0 to T and the path with optimal metric at time T is selected. The optimal path is then traced back from T to 0 to output the estimate of the information bit vector used to encode. For larger codewords, note that the current method is sub-optimal in terms of memory utilization and latency. This method is also excluded from torch.compile using @torch.compiler.disable because the Viterbi algorithm’s inherently sequential structure (forward pass, traceback, output extraction) causes extremely long compilation times due to loop unrolling.

Examples

from sionna.phy.fec.conv import ViterbiDecoder

decoder = ViterbiDecoder(rate=0.5, constraint_length=5)
llr = torch.randn(10, 200)  # Received LLRs
u_hat = decoder(llr)
print(u_hat.shape)
# torch.Size([10, 100])

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 encoder is terminated during codeword generation.

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)