tb_config.py (29325B)
1 # 2 # SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 # SPDX-License-Identifier: Apache-2.0 4 # 5 """TB configuration for the nr (5G) sub-package of the Sionna library. 6 """ 7 8 from .config import Config 9 from .utils import select_mcs 10 11 class TBConfig(Config): 12 # pylint: disable=line-too-long 13 r""" 14 The TBConfig objects sets parameters related to the transport block 15 encoding, as described in TS 38.214 [3GPP38214]_. 16 17 All configurable properties can be provided as keyword arguments during the 18 initialization or changed later. 19 20 The TBConfig is configured by selecting the modulation and coding scheme 21 (MCS) tables and index. 22 23 Example 24 ------- 25 >>> tb_config = TBConfig(mcs_index=13) 26 >>> tb_config.mcs_table = 3 27 >>> tb_config.channel_type = "PUSCH" 28 >>> tb_config.show() 29 30 The following tables provide an overview of the corresponding coderates and 31 modulation orders. 32 33 .. table:: MCS Index Table 1 (Table 5.1.3.1-1 in [3GPP38214]_) 34 :align: center 35 36 +-------------------+--------------------+-------------------------+-----------------------+ 37 | | MCS Index | | Modulation Order | | Target Coderate | | Spectral Efficiency | 38 | | :math:`I_{MCS}` | | :math:`Q_m` | | :math:`R\times[1024]` | | | 39 +===================+====================+=========================+=======================+ 40 | 0 | 2 | 120 | 0.2344 | 41 +-------------------+--------------------+-------------------------+-----------------------+ 42 | 1 | 2 | 157 | 0.3066 | 43 +-------------------+--------------------+-------------------------+-----------------------+ 44 | 2 | 2 | 193 | 0.3770 | 45 +-------------------+--------------------+-------------------------+-----------------------+ 46 | 3 | 2 | 251 | 0.4902 | 47 +-------------------+--------------------+-------------------------+-----------------------+ 48 | 4 | 2 | 308 | 0.6016 | 49 +-------------------+--------------------+-------------------------+-----------------------+ 50 | 5 | 2 | 379 | 0.7402 | 51 +-------------------+--------------------+-------------------------+-----------------------+ 52 | 6 | 2 | 449 | 0.8770 | 53 +-------------------+--------------------+-------------------------+-----------------------+ 54 | 7 | 2 | 526 | 1.0273 | 55 +-------------------+--------------------+-------------------------+-----------------------+ 56 | 8 | 2 | 602 | 1.1758 | 57 +-------------------+--------------------+-------------------------+-----------------------+ 58 | 9 | 2 | 679 | 1.3262 | 59 +-------------------+--------------------+-------------------------+-----------------------+ 60 | 10 | 4 | 340 | 1.3281 | 61 +-------------------+--------------------+-------------------------+-----------------------+ 62 | 11 | 4 | 378 | 1.4766 | 63 +-------------------+--------------------+-------------------------+-----------------------+ 64 | 12 | 4 | 434 | 1.6953 | 65 +-------------------+--------------------+-------------------------+-----------------------+ 66 | 13 | 4 | 490 | 1.9141 | 67 +-------------------+--------------------+-------------------------+-----------------------+ 68 | 14 | 4 | 553 | 2.1602 | 69 +-------------------+--------------------+-------------------------+-----------------------+ 70 | 15 | 4 | 616 | 2.4063 | 71 +-------------------+--------------------+-------------------------+-----------------------+ 72 | 16 | 4 | 658 | 2.5703 | 73 +-------------------+--------------------+-------------------------+-----------------------+ 74 | 17 | 6 | 438 | 2.5664 | 75 +-------------------+--------------------+-------------------------+-----------------------+ 76 | 18 | 6 | 466 | 2.7305 | 77 +-------------------+--------------------+-------------------------+-----------------------+ 78 | 19 | 6 | 517 | 3.0293 | 79 +-------------------+--------------------+-------------------------+-----------------------+ 80 | 20 | 6 | 567 | 3.3223 | 81 +-------------------+--------------------+-------------------------+-----------------------+ 82 | 21 | 6 | 616 | 3.6094 | 83 +-------------------+--------------------+-------------------------+-----------------------+ 84 | 22 | 6 | 666 | 3.9023 | 85 +-------------------+--------------------+-------------------------+-----------------------+ 86 | 23 | 6 | 719 | 4.2129 | 87 +-------------------+--------------------+-------------------------+-----------------------+ 88 | 24 | 6 | 772 | 4.5234 | 89 +-------------------+--------------------+-------------------------+-----------------------+ 90 | 25 | 6 | 822 | 4.8164 | 91 +-------------------+--------------------+-------------------------+-----------------------+ 92 | 26 | 6 | 873 | 5.1152 | 93 +-------------------+--------------------+-------------------------+-----------------------+ 94 | 27 | 6 | 910 | 5.3320 | 95 +-------------------+--------------------+-------------------------+-----------------------+ 96 | 28 | 6 | 948 | 5.5547 | 97 +-------------------+--------------------+-------------------------+-----------------------+ 98 99 .. table:: MCS Index Table 2 (Table 5.1.3.1-2 in [3GPP38214]_) 100 :align: center 101 102 +-------------------+--------------------+-------------------------+-----------------------+ 103 | | MCS Index | | Modulation Order | | Target Coderate | | Spectral Efficiency | 104 | | :math:`I_{MCS}` | | :math:`Q_m` | | :math:`R\times[1024]` | | | 105 +===================+====================+=========================+=======================+ 106 | 0 | 2 | 120 | 0.2344 | 107 +-------------------+--------------------+-------------------------+-----------------------+ 108 | 1 | 2 | 193 | 0.3770 | 109 +-------------------+--------------------+-------------------------+-----------------------+ 110 | 2 | 2 | 308 | 0.6016 | 111 +-------------------+--------------------+-------------------------+-----------------------+ 112 | 3 | 2 | 449 | 0.8770 | 113 +-------------------+--------------------+-------------------------+-----------------------+ 114 | 4 | 2 | 602 | 1.1758 | 115 +-------------------+--------------------+-------------------------+-----------------------+ 116 | 5 | 4 | 378 | 1.4766 | 117 +-------------------+--------------------+-------------------------+-----------------------+ 118 | 6 | 4 | 434 | 1.6953 | 119 +-------------------+--------------------+-------------------------+-----------------------+ 120 | 7 | 4 | 490 | 1.9141 | 121 +-------------------+--------------------+-------------------------+-----------------------+ 122 | 8 | 4 | 553 | 2.1602 | 123 +-------------------+--------------------+-------------------------+-----------------------+ 124 | 9 | 4 | 616 | 2.4063 | 125 +-------------------+--------------------+-------------------------+-----------------------+ 126 | 10 | 4 | 658 | 2.5703 | 127 +-------------------+--------------------+-------------------------+-----------------------+ 128 | 11 | 6 | 466 | 2.7305 | 129 +-------------------+--------------------+-------------------------+-----------------------+ 130 | 12 | 6 | 517 | 3.0293 | 131 +-------------------+--------------------+-------------------------+-----------------------+ 132 | 13 | 6 | 567 | 3.3223 | 133 +-------------------+--------------------+-------------------------+-----------------------+ 134 | 14 | 6 | 616 | 3.6094 | 135 +-------------------+--------------------+-------------------------+-----------------------+ 136 | 15 | 6 | 666 | 3.9023 | 137 +-------------------+--------------------+-------------------------+-----------------------+ 138 | 16 | 6 | 719 | 4.2129 | 139 +-------------------+--------------------+-------------------------+-----------------------+ 140 | 17 | 6 | 772 | 4.5234 | 141 +-------------------+--------------------+-------------------------+-----------------------+ 142 | 18 | 6 | 822 | 4.8164 | 143 +-------------------+--------------------+-------------------------+-----------------------+ 144 | 19 | 6 | 873 | 5.1152 | 145 +-------------------+--------------------+-------------------------+-----------------------+ 146 | 20 | 8 | 682.5 | 5.3320 | 147 +-------------------+--------------------+-------------------------+-----------------------+ 148 | 21 | 8 | 711 | 5.5547 | 149 +-------------------+--------------------+-------------------------+-----------------------+ 150 | 22 | 8 | 754 | 5.8906 | 151 +-------------------+--------------------+-------------------------+-----------------------+ 152 | 23 | 8 | 797 | 6.2266 | 153 +-------------------+--------------------+-------------------------+-----------------------+ 154 | 24 | 8 | 841 | 6.5703 | 155 +-------------------+--------------------+-------------------------+-----------------------+ 156 | 25 | 8 | 885 | 6.9141 | 157 +-------------------+--------------------+-------------------------+-----------------------+ 158 | 26 | 8 | 916.5 | 7.1602 | 159 +-------------------+--------------------+-------------------------+-----------------------+ 160 | 27 | 8 | 948 | 7.4063 | 161 +-------------------+--------------------+-------------------------+-----------------------+ 162 163 .. table:: MCS Index Table 3 (Table 5.1.3.1-3 in [3GPP38214]_) 164 :align: center 165 166 +-------------------+--------------------+-------------------------+-----------------------+ 167 | | MCS Index | | Modulation Order | | Target Coderate | | Spectral Efficiency | 168 | | :math:`I_{MCS}` | | :math:`Q_m` | | :math:`R\times[1024]` | | | 169 +===================+====================+=========================+=======================+ 170 | 0 | 2 | 30 | 0.0586 | 171 +-------------------+--------------------+-------------------------+-----------------------+ 172 | 1 | 2 | 40 | 0.0781 | 173 +-------------------+--------------------+-------------------------+-----------------------+ 174 | 2 | 2 | 50 | 0.0977 | 175 +-------------------+--------------------+-------------------------+-----------------------+ 176 | 3 | 2 | 64 | 0.1250 | 177 +-------------------+--------------------+-------------------------+-----------------------+ 178 | 4 | 2 | 78 | 0.1523 | 179 +-------------------+--------------------+-------------------------+-----------------------+ 180 | 5 | 2 | 99 | 0.1934 | 181 +-------------------+--------------------+-------------------------+-----------------------+ 182 | 6 | 2 | 120 | 0.2344 | 183 +-------------------+--------------------+-------------------------+-----------------------+ 184 | 7 | 2 | 157 | 0.3066 | 185 +-------------------+--------------------+-------------------------+-----------------------+ 186 | 8 | 2 | 193 | 0.3770 | 187 +-------------------+--------------------+-------------------------+-----------------------+ 188 | 9 | 2 | 251 | 0.4902 | 189 +-------------------+--------------------+-------------------------+-----------------------+ 190 | 10 | 2 | 308 | 0.6016 | 191 +-------------------+--------------------+-------------------------+-----------------------+ 192 | 11 | 2 | 379 | 0.7402 | 193 +-------------------+--------------------+-------------------------+-----------------------+ 194 | 12 | 2 | 449 | 0.8770 | 195 +-------------------+--------------------+-------------------------+-----------------------+ 196 | 13 | 2 | 526 | 1.0273 | 197 +-------------------+--------------------+-------------------------+-----------------------+ 198 | 14 | 2 | 602 | 1.1758 | 199 +-------------------+--------------------+-------------------------+-----------------------+ 200 | 15 | 4 | 340 | 1.3281 | 201 +-------------------+--------------------+-------------------------+-----------------------+ 202 | 16 | 4 | 378 | 1.4766 | 203 +-------------------+--------------------+-------------------------+-----------------------+ 204 | 17 | 4 | 434 | 1.6953 | 205 +-------------------+--------------------+-------------------------+-----------------------+ 206 | 18 | 4 | 490 | 1.9141 | 207 +-------------------+--------------------+-------------------------+-----------------------+ 208 | 19 | 4 | 553 | 2.1602 | 209 +-------------------+--------------------+-------------------------+-----------------------+ 210 | 20 | 4 | 616 | 2.4063 | 211 +-------------------+--------------------+-------------------------+-----------------------+ 212 | 21 | 6 | 438 | 2.5564 | 213 +-------------------+--------------------+-------------------------+-----------------------+ 214 | 22 | 6 | 466 | 2.7305 | 215 +-------------------+--------------------+-------------------------+-----------------------+ 216 | 23 | 6 | 517 | 3.0293 | 217 +-------------------+--------------------+-------------------------+-----------------------+ 218 | 24 | 6 | 567 | 3.3223 | 219 +-------------------+--------------------+-------------------------+-----------------------+ 220 | 25 | 6 | 616 | 3.6094 | 221 +-------------------+--------------------+-------------------------+-----------------------+ 222 | 26 | 6 | 666 | 3.9023 | 223 +-------------------+--------------------+-------------------------+-----------------------+ 224 | 27 | 6 | 719 | 4.2129 | 225 +-------------------+--------------------+-------------------------+-----------------------+ 226 | 28 | 6 | 772 | 4.5234 | 227 +-------------------+--------------------+-------------------------+-----------------------+ 228 229 230 .. table:: MCS Index Table 4 (Table 5.1.3.1-4 in [3GPP38214]_) 231 :align: center 232 233 +-------------------+--------------------+-------------------------+-----------------------+ 234 | | MCS Index | | Modulation Order | | Target Coderate | | Spectral Efficiency | 235 | | :math:`I_{MCS}` | | :math:`Q_m` | | :math:`R\times[1024]` | | | 236 +===================+====================+=========================+=======================+ 237 | 0 | 2 | 120 | 0.2344 | 238 +-------------------+--------------------+-------------------------+-----------------------+ 239 | 1 | 2 | 193 | 0.3770 | 240 +-------------------+--------------------+-------------------------+-----------------------+ 241 | 2 | 2 | 449 | 0.8770 | 242 +-------------------+--------------------+-------------------------+-----------------------+ 243 | 3 | 4 | 378 | 1.4766 | 244 +-------------------+--------------------+-------------------------+-----------------------+ 245 | 4 | 4 | 490 | 1.9141 | 246 +-------------------+--------------------+-------------------------+-----------------------+ 247 | 5 | 4 | 616 | 2.4063 | 248 +-------------------+--------------------+-------------------------+-----------------------+ 249 | 6 | 6 | 466 | 2.7305 | 250 +-------------------+--------------------+-------------------------+-----------------------+ 251 | 7 | 6 | 517 | 3.0293 | 252 +-------------------+--------------------+-------------------------+-----------------------+ 253 | 8 | 6 | 567 | 3.3223 | 254 +-------------------+--------------------+-------------------------+-----------------------+ 255 | 9 | 6 | 616 | 3.6094 | 256 +-------------------+--------------------+-------------------------+-----------------------+ 257 | 10 | 6 | 666 | 3.9023 | 258 +-------------------+--------------------+-------------------------+-----------------------+ 259 | 11 | 6 | 719 | 4.2129 | 260 +-------------------+--------------------+-------------------------+-----------------------+ 261 | 12 | 6 | 772 | 4.5234 | 262 +-------------------+--------------------+-------------------------+-----------------------+ 263 | 13 | 6 | 822 | 4.8154 | 264 +-------------------+--------------------+-------------------------+-----------------------+ 265 | 14 | 6 | 873 | 5.1152 | 266 +-------------------+--------------------+-------------------------+-----------------------+ 267 | 15 | 8 | 682.5 | 5.3320 | 268 +-------------------+--------------------+-------------------------+-----------------------+ 269 | 16 | 8 | 711 | 5.5547 | 270 +-------------------+--------------------+-------------------------+-----------------------+ 271 | 17 | 8 | 754 | 5.8906 | 272 +-------------------+--------------------+-------------------------+-----------------------+ 273 | 18 | 8 | 797 | 6.2266 | 274 +-------------------+--------------------+-------------------------+-----------------------+ 275 | 19 | 8 | 841 | 6.5703 | 276 +-------------------+--------------------+-------------------------+-----------------------+ 277 | 20 | 8 | 885 | 6.9141 | 278 +-------------------+--------------------+-------------------------+-----------------------+ 279 | 21 | 8 | 916.5 | 7.1602 | 280 +-------------------+--------------------+-------------------------+-----------------------+ 281 | 22 | 8 | 948 | 7.4063 | 282 +-------------------+--------------------+-------------------------+-----------------------+ 283 | 23 | 10 | 805.5 | 7.8662 | 284 +-------------------+--------------------+-------------------------+-----------------------+ 285 | 24 | 10 | 853 | 8.3301 | 286 +-------------------+--------------------+-------------------------+-----------------------+ 287 | 25 | 10 | 900.5 | 8.7939 | 288 +-------------------+--------------------+-------------------------+-----------------------+ 289 | 26 | 10 | 948 | 9.2578 | 290 +-------------------+--------------------+-------------------------+-----------------------+ 291 292 """ 293 294 def __init__(self, **kwargs): 295 self._name = "Transport Block Configuration" 296 super().__init__(**kwargs) 297 self.check_config() 298 299 #-----------------------------# 300 #---Configurable parameters---# 301 #-----------------------------# 302 303 @property 304 def mcs_index(self): 305 r"""Modulation and coding scheme (MCS) index (denoted as :math:`I_{MCS}` 306 in [3GPP38214]_)""" 307 self._ifndef("mcs_index", 14) # 16-QAM, r=0.54 308 return self._mcs_index 309 310 @mcs_index.setter 311 def mcs_index(self, value): 312 assert value in range(29), \ 313 "mcs_index must be in range from 0 to 28." 314 self._mcs_index = value 315 316 @property 317 def mcs_table(self): 318 r"""Indicates which MCS table from [3GPP38214]_ to use. Starts with "1". 319 """ 320 self._ifndef("mcs_table", 1) 321 return self._mcs_table 322 323 @mcs_table.setter 324 def mcs_table(self, value): 325 assert value in range(1,5), \ 326 "mcs_table must be in range from 1 to 4" 327 self._mcs_table = value 328 329 @property 330 def channel_type(self): 331 r"""5G NR physical channel type. Valid choices are "PDSCH" and "PUSCH". 332 """ 333 self._ifndef("channel_type", "PUSCH") 334 return self._channel_type 335 336 @channel_type.setter 337 def channel_type(self, value): 338 assert value in ("PUSCH", "PDSCH"), \ 339 'Only "PUSCH" and "PDSCH are supported' 340 self._channel_type = value 341 342 @property 343 def n_id(self): 344 r""" 345 int, None (default), [0, 1023] : Data scrambling initialization 346 :math:`n_\text{ID}`. Data Scrambling ID related to cell id and 347 provided by higher layer. If `None`, the 348 :class:`~sionna.nr.PUSCHConfig` will automatically set 349 :math:`n_\text{ID}=N_\text{ID}^{cell}`. 350 """ 351 self._ifndef("n_id", None) 352 return self._n_id 353 354 @n_id.setter 355 def n_id(self, value): 356 if value is None: 357 self._n_id = None 358 else: 359 assert value in range(1024), \ 360 "n_id must be in range from 0 to 1023" 361 self._n_id = value 362 363 ### 364 ### Derived (read-only) parameters 365 ### 366 367 @property 368 def name(self): 369 return "Transport Block Configuration" 370 371 @property 372 def target_coderate(self): 373 r""" 374 float, read-only: Target coderate of the TB as defined by the selected 375 MCS""" 376 _, r = select_mcs(self._mcs_index, 377 self._mcs_table, 378 channel_type=self._channel_type) 379 return r 380 381 @property 382 def num_bits_per_symbol(self): 383 r""" 384 int, read-only: Modulation order as defined by the selected MCS""" 385 m, _ = select_mcs(self._mcs_index, 386 self._mcs_table, 387 channel_type=self._channel_type) 388 return m 389 390 @property 391 def tb_scaling(self): 392 r"""float, 1. (default), read-only: TB scaling factor for PDSCH as 393 defined in [3GPP38214]_ Tab. 5.1.3.2-2.""" 394 return 1. # only 1. supported at the moment 395 396 #-------------------# 397 #---Class methods---# 398 #-------------------# 399 400 def check_config(self): 401 """Test if configuration is valid""" 402 attr_list = ["mcs_index", 403 "mcs_table", 404 "channel_type", 405 "n_id" 406 ] 407 for attr in attr_list: 408 value = getattr(self, attr) 409 setattr(self, attr, value)