TB5GScrambler#

class sionna.phy.fec.scrambling.TB5GScrambler(n_rnti: int | Sequence[int] = 1, n_id: int | Sequence[int] = 1, binary: bool = True, channel_type: str = 'PUSCH', codeword_index: int = 0, *, precision: str | None = None, device: str | None = None, **kwargs)[source]#

Bases: sionna.phy.block.Block

5G NR Scrambler for PUSCH and PDSCH channel.

Implements the pseudo-random bit scrambling as defined in [3GPPTS38211] Sec. 6.3.1.1 for the “PUSCH” channel and in Sec. 7.3.1.1 for the “PDSCH” channel.

Only for the “PDSCH” channel, the scrambler can be configured for two codeword transmission mode. Hereby, codeword_index corresponds to the index of the codeword to be scrambled.

If n_rnti is a list of ints, the scrambler assumes that the second last axis contains len(n_rnti) elements. This allows independent scrambling for multiple independent streams.

Parameters:
  • n_rnti (int | Sequence[int]) – RNTI identifier provided by higher layer. Defaults to 1 and must be in range [0, 65535]. If a list is provided, every list element defines a scrambling sequence for multiple independent streams.

  • n_id (int | Sequence[int]) – Scrambling ID related to cell id and provided by higher layer. Defaults to 1 and must be in range [0, 1023]. If a list is provided, every list element defines a scrambling sequence for multiple independent streams.

  • binary (bool) – Indicates whether bit-sequence should be flipped (i.e., binary operations are performed) or the signs should be flipped (i.e., soft-value/LLR domain-based).

  • channel_type (str) – Can be either 'PUSCH' or 'PDSCH'.

  • codeword_index (int) – Scrambler can be configured for two codeword transmission. codeword_index can be either 0 or 1.

  • 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:
  • x – torch.Tensor. Tensor of arbitrary shape. If n_rnti and n_id are a list, it is assumed that x has shape [..., num_streams, n] where num_streams = len(n_rnti).

  • binaryNone | bool. Overrules the init parameter binary if explicitly given. Indicates whether bit-sequence should be flipped (i.e., binary operations are performed) or the signs should be flipped (i.e., soft-value/LLR domain-based).

Outputs:

x_out – torch.Tensor. Tensor of same shape as x.

Notes

The parameters radio network temporary identifier (RNTI) n_rnti and the datascrambling ID n_id are usually provided by the higher layer protocols.

For inverse scrambling, the same scrambler can be re-used (as the values are flipped again, i.e., result in the original state).

Examples

import torch
from sionna.phy.fec.scrambling import TB5GScrambler

scrambler = TB5GScrambler(n_rnti=1, n_id=1)
bits = torch.randint(0, 2, (10, 100), dtype=torch.float32)
scrambled = scrambler(bits)
unscrambled = scrambler(scrambled)  # Re-use for descrambling
assert torch.allclose(bits, unscrambled)

Attributes

property keep_state: bool#

Required for descrambler, is always True for the TB5GScrambler.

Methods

build(input_shape: torch.Size, **kwargs) None[source]#

Initialize pseudo-random scrambling sequence.

Parameters:

input_shape (torch.Size)