Skip to content

Commit

Permalink
Fix cyclic prefix length of first symbol for 5g NR PUSCH
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schäufele <[email protected]>
  • Loading branch information
danielschaeufele committed Oct 1, 2024
1 parent 0aeca34 commit 6d80e7e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
23 changes: 16 additions & 7 deletions sionna/nr/carrier_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""
# pylint: disable=line-too-long

import numpy as np

from .config import Config

class CarrierConfig(Config):
Expand Down Expand Up @@ -244,16 +246,23 @@ def kappa(self):
@property
def cyclic_prefix_length(self):
r"""
float, read-only : Cyclic prefix length
np.ndarray[float], read-only : Vector of cyclic prefix length of all
symbols in the current slot as defined in Section 5.3.1 [3GPP38211]_
:math:`N_{\text{CP},l}^{\mu} \cdot T_{\text{c}}` [s]
"""
if self.cyclic_prefix=="extended":
cp = 512*self.kappa*2**(-self.mu)
cp = np.zeros(self.num_symbols_per_slot)
if self.cyclic_prefix == "extended":
cp[:] = 512 * self.kappa * 2 ** (-self.mu)
else:
cp = 144*self.kappa*2**(-self.mu)
if self.slot_number in [0, 7*2**self.mu]:
cp += 16*self.kappa
return cp*self.t_c
cp[:] = 144 * self.kappa * 2 ** (-self.mu)

# Extend cyclic prefix for l=0 or l=7*2^\mu
long_cp_period = 7 * 2 ** self.mu
l_start = self.slot_number * self.num_symbols_per_slot
for i in range(l_start % long_cp_period,
self.num_symbols_per_slot, long_cp_period):
cp[i] += 16 * self.kappa
return cp * self.t_c

#-------------------#
#---Class methods---#
Expand Down
4 changes: 3 additions & 1 deletion sionna/nr/pusch_transmitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def __init__(self,
subcarrier_spacing=self._subcarrier_spacing,
num_tx=self._num_tx,
num_streams_per_tx=self._num_layers,
cyclic_prefix_length=self._cyclic_prefix_length,
# TODO: pass vector of cyclic prefix lengths
# (requires rewrite of channel simulation code)
cyclic_prefix_length=self._cyclic_prefix_length[1],
pilot_pattern=self._pilot_pattern,
dtype=dtype)

Expand Down
43 changes: 42 additions & 1 deletion test/unit/nr/test_pusch_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import tensorflow as tf
import sionna
from sionna.nr import PUSCHConfig
from sionna.nr import PUSCHConfig, CarrierConfig
from sionna import config

script_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -228,3 +228,44 @@ def test_precoding_against_reference(self):
for i in range(5):
pusch_config.tpmi = i
self.assertTrue(np.allclose(pusch_config.dmrs_grid_precoded/np.sqrt(3), ref[i]))


class TestCarrierConfig(unittest.TestCase):
"""Tests for the CarrierConfig Class"""

def test_cyclic_prefix_length(self):
carrier_config = CarrierConfig(subcarrier_spacing=15, slot_number=0)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, ([5.2] + [4.69]*6)*2, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=15, slot_number=1)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, ([5.2] + [4.69]*6)*2, decimal=2)

carrier_config = CarrierConfig(subcarrier_spacing=30, slot_number=0)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [2.86] + [2.34]*13, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=30, slot_number=1)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [2.86] + [2.34]*13, decimal=2)

carrier_config = CarrierConfig(subcarrier_spacing=60, slot_number=0)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [1.69] + [1.17]*13, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=60, slot_number=1)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [1.17] * 14, decimal=2)

carrier_config = CarrierConfig(subcarrier_spacing=60, slot_number=0, cyclic_prefix='extended')
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [4.17] * 12, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=60, slot_number=1, cyclic_prefix='extended')
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [4.17] * 12, decimal=2)

carrier_config = CarrierConfig(subcarrier_spacing=120, slot_number=0)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [1.11] + [0.59] * 13, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=120, slot_number=1)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [0.59] * 14, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=120, slot_number=2)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [0.59] * 14, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=120, slot_number=3)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [0.59] * 14, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=120, slot_number=4)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [1.11] + [0.59] * 13, decimal=2)

carrier_config = CarrierConfig(subcarrier_spacing=240, slot_number=0)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [0.81] + [0.29] * 13, decimal=2)
carrier_config = CarrierConfig(subcarrier_spacing=240, slot_number=1)
np.testing.assert_array_almost_equal(carrier_config.cyclic_prefix_length * 1e6, [0.29] * 14, decimal=2)

0 comments on commit 6d80e7e

Please sign in to comment.