Contents

Sionna 5G NR Physical Layer (nr/): The PUSCH End-to-End Transceiver Chain

OFDM & NR
#Sionna#5G NR#PUSCH#3GPP

The modules in the previous articles are all “components”; nr/ is the finished chain that wires them together according to the 3GPP specifications. It implements only one channel: the PUSCH (Physical Uplink Shared Channel), but this single chain runs the whole way through CRC, LDPC, interleaving, scrambling, modulation, layer mapping, precoding, resource mapping, and OFDM.

1. Files and Responsibilities

FileFunctionMain Public Classes/FunctionsProtocol Spec
__init__.pyEntry point of the NR physical layer subpackageExports all NR configs, transceiver chains, and utilities (22 symbols in total)—
config.pyAbstract base class for NR configurationConfig(ABC): clone, check_config, show—
carrier_config.pyCarrier configuration (OFDM numerology)CarrierConfig(Config): n_cell_id, cyclic_prefix, subcarrier_spacing, etc.TS 38.211 §4
pusch_dmrs_config.pyPUSCH DMRS configurationPUSCHDMRSConfig(Config): config_type, type_a_position, etc.TS 38.211 §6.4.1.1
pusch_config.pyPUSCH channel configurationPUSCHConfig(Config), check_pusch_configs(List[PUSCHConfig]) -> dictTS 38.211 §6.3, §6.4
tb_config.pyTransport block encoding configurationTBConfig(Config): mcs_index, mcs_table, channel_type, etc.TS 38.214 (incl. Tab. 5.1.3.1-1)
tb_encoder.pyTransport block encodingTBEncoder(Block): segmentation, CRC, FEC, interleaving, scramblingTS 38.214, TS 38.211
tb_decoder.pyTransport block decodingTBDecoder(Block): outputs b_hat, tb_crc_statusTS 38.214, TS 38.211
layer_mapping.pyMIMO layer mapping and demappingLayerMapper(Block), LayerDemapper(Block)TS 38.211 §6.3.1.3 / §7.3.1.3
pusch_pilot_pattern.pyPUSCH pilot patternPUSCHPilotPattern(PilotPattern)Depends on §6.4.1.1
pusch_precoder.pyPUSCH precodingPUSCHPrecoder(Block): applies the per-transmitter precoding matrices to the resource grid—
pusch_transmitter.pyPUSCH transmitterPUSCHTransmitter(Block)—
pusch_channel_estimation.pyPUSCH channel estimationPUSCHLSChannelEstimator(LSChannelEstimator): accounts for stream separation within CDM groupsDepends on §6.4.1.1
pusch_receiver.pyPUSCH receiverPUSCHReceiver(Block)—
utils.pyNR physical layer utilitiesgenerate_prng_seq, decode_mcs_index, calculate_num_coded_bits, calculate_tb_size, MCSDecoderNR, TransportBlockNR, CodedAWGNChannelNRTS 38.211 §5.2.1; TS 38.214

The Four-Level Configuration Hierarchy

The Config abstract base class provides three methods: clone (deep copy), check_config (parameter validation), and show (print the configuration). The four configuration classes nest layer by layer:

CarrierConfig         Carrier/Numerology: subcarrier spacing, CP type, cell ID
└── PUSCHConfig       PUSCH resource allocation: mapping type, layers, antenna ports, symbols
    ├── PUSCHDMRSConfig   DMRS config: configuration type 1/2, additional position
    └── TBConfig          Transport block: MCS index, MCS table, channel type

This nesting is worth memorizing: changing subcarrier_spacing affects the resource-grid size, which in turn affects the DMRS positions and the number of available coded bits, so the validation helper check_pusch_configs exists for a reason—it reports parameter conflicts before the simulation starts, instead of letting a dimension mismatch surface somewhere in the middle of the chain.

The Complete Bit-Level Chain

Inside, TBEncoder follows the standard 38.212 flow:

TB → add TB CRC → code-block segmentation (with CB CRC) → per-segment LDPC encoding
   → rate matching → code-block concatenation → scrambling

PUSCHTransmitter then attaches the physical-layer flow:

TBEncoder → Mapper → LayerMapper → ResourceGridMapper
          → (optional) Precoder → (optional) OFDMModulator

The receiver runs strictly in reverse order:

OFDMDemodulator → channel estimation → MIMO detection (outputs LLRs)
                → LayerDemapper → TBDecoder

On top of a plain LS estimate, PUSCHLSChannelEstimator handles one extra thing: stream separation within DMRS CDM (code-division multiplexing) groups—in the spec, the DMRS of several antenna ports are superimposed on the same resource element and distinguished by orthogonal codes, so the estimation must separate their individual components.

2. Usage Examples

The PUSCH configuration family:

from sionna.phy.nr import CarrierConfig, PUSCHConfig, PUSCHDMRSConfig, TBConfig

carrier_config = CarrierConfig(n_cell_id=41)     # Carrier/Numerology configuration
carrier_config.subcarrier_spacing = 30           # In kHz

pusch_config = PUSCHConfig()
pusch_config.carrier = carrier_config
pusch_config.mapping_type = "A"                  # Mapping type A/B
pusch_config.num_layers = 1
pusch_config.num_antenna_ports = 1
pusch_config.dmrs = PUSCHDMRSConfig(config_type=2)   # DMRS configuration

tb_config = TBConfig(mcs_index=13, mcs_table=3, channel_type="PUSCH")
tb_config.show()

Note that subcarrier_spacing here is an integer in kHz (30 means 30 kHz), while the OFDM-level ResourceGrid uses Hz (30e3)—don’t mix the two.

The PUSCH end-to-end transceiver chain:

import torch
from sionna.phy.nr import PUSCHConfig, PUSCHTransmitter, PUSCHReceiver
from sionna.phy.channel import AWGN

pusch_config = PUSCHConfig()
pusch_transmitter = PUSCHTransmitter(pusch_config)
pusch_receiver = PUSCHReceiver(pusch_transmitter)

x, b = pusch_transmitter(16)     # x: [16, 1, 1, 14, 48], b: [16, 1, 1352]
no = 0.1
awgn = AWGN()
y = awgn([x, no])                # Superimpose AWGN on the resource grid
b_hat = pusch_receiver(y, no)    # Recovered transport bits

There is a thoughtful design here: PUSCHReceiver(pusch_transmitter) takes the transmitter directly as an argument, and the receiver reads the resource grid, pilot pattern, number of layers, and all other configurations from it. Moreover, PUSCHTransmitter returns the transmitted resource grid x and the original bits b in one call, so you don’t have to track the bit stream yourself when computing BER statistics.

AWGN accepts list-style input [x, no] (the Block precision conversion supports multiple inputs) and adds noise directly on the resource grid.

Transport block (TB) encoding and decoding:

import torch
from sionna.phy.nr import TBEncoder, TBDecoder

encoder = TBEncoder(target_tb_size=1000, num_coded_bits=2000,
                    target_coderate=0.5, num_bits_per_symbol=4,
                    n_rnti=1, n_id=1)
decoder = TBDecoder(encoder, num_bp_iter=20)

b = torch.randint(0, 2, (16, 1, encoder.num_bits_per_tb), dtype=torch.float32)
c = encoder(b)                                 # Bits after encoding + interleaving + scrambling
bits_hat, crc_ok = decoder(torch.randn_like(c))  # Input is channel LLRs

target_tb_size is the desired transport-block size; the actual value is constrained by the spec to a legal set, so you must use encoder.num_bits_per_tb rather than target_tb_size when generating bits—this is an easy pitfall. The decoder additionally returns crc_ok, indicating whether the TB-level CRC passed, which is exactly the basis for BLER statistics.

Layer mapping and PUSCH precoding:

import torch
from numpy.random import default_rng
from sionna.phy.nr import LayerMapper, LayerDemapper, PUSCHPrecoder

mapper = LayerMapper(num_layers=2)
demapper = LayerDemapper(mapper, num_bits_per_symbol=4)

precoding_matrices = torch.randn(1, 1, 2, 4, 2, dtype=torch.complex64)
precoder = PUSCHPrecoder(precoding_matrices)

LayerDemapper needs to know num_bits_per_symbol because it has to split the symbol LLRs on the layers back into bit LLRs, and that information is not captured by layer mapping.

MCS decoding and TB size computation:

from sionna.phy.nr import (generate_prng_seq, decode_mcs_index,
                           calculate_tb_size, calculate_num_coded_bits)

seq = generate_prng_seq(100, 12345)              # Gold pseudorandom sequence of length 31

mod_order, rate = decode_mcs_index(14, table_index=1)   # Modulation order and code rate from the MCS index

tb_size, cb_size, num_cb, tb_crc, cb_crc, cw_len = calculate_tb_size(
    modulation_order=4, target_coderate=0.5, num_coded_bits=4800, num_layers=1)

num_bits = calculate_num_coded_bits(4, 50, 14, 12, 2)   # Coded bits that fit in one slot

generate_prng_seq produces the Gold sequence defined in 38.211 §5.2.1, used for scrambling and various pseudorandom sequences:

c(n)=(x1(n+Nc)+x2(n+Nc)) mod 2c(n) = \left(x_1(n + N_c) + x_2(n + N_c)\right) \bmod 2

decode_mcs_index looks up the modulation order and target code rate from the MCS table, and calculate_num_coded_bits computes the actual number of usable coded bits from “modulation order, number of allocated PRBs, number of OFDM symbols, number of symbols occupied by DMRS, number of layers”—these three functions are the go-to combination for link-level budgeting.

3. Summary

A few things worth keeping in mind about nr/:

  1. Configuration is hierarchical: PUSCHConfig.carrier points to a CarrierConfig; changing an upper level propagates to the lower ones, and check_config will block illegal combinations for you;
  2. Units are not consistent: in the NR configuration subcarrier_spacing is an integer in kHz, while the OFDM layer uses Hz;
  3. The receiver is constructed from the transmitter, so the two sides’ configurations are naturally consistent and you don’t have to worry about mistyped parameters;
  4. Read the TB size from num_bits_per_tb—don’t use target_tb_size directly.

The final article wraps up the series with a pass through signal/ and utils/, the two general-purpose foundations.

Comments

Loading comments…

    ← Back to home