Skip to content

Commit

Permalink
add nrPDSCHDecode()
Browse files Browse the repository at this point in the history
  • Loading branch information
catkira committed Oct 29, 2023
1 parent 3292a67 commit f94905e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions py3gpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .nrPDSCHDMRSIndices import nrPDSCHDMRSIndices
from .nrPDSCHDMRS import nrPDSCHDMRS
from .nrPDSCH import nrPDSCH
from .nrPDSCHDecode import nrPDSCHDecode

from .configs.nrCarrierConfig import nrCarrierConfig
from .configs.nrNumerologyConfig import nrNumerologyConfig
Expand Down
30 changes: 30 additions & 0 deletions py3gpp/nrPDSCHDecode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import numpy as np
from py3gpp.nrSymbolDemodulate import nrSymbolDemodulate
from py3gpp.nrPRBS import nrPRBS

def nrPDSCHDecode(sym, mod, nid, rnti):
descrambled_bits = []
n_layers = sym.shape[0]
if n_layers != 1:
raise NotImplementedError('not ready yet')

for i in range (n_layers):
demod_sym = nrSymbolDemodulate(sym[i], mod[i])
cinit = (rnti * 2**15) + (i * 2**14) + nid
prbs_bits = nrPRBS(cinit, len(demod_sym))
descrambled_bits.append(np.multiply(demod_sym, (-prbs_bits*2 + 1)))
descrambled_bits = np.array(descrambled_bits)
return descrambled_bits



if __name__ == '__main__':
modulation = ['16QAM']
nlayers = 1
ncellid = 42
rnti = 6143
data = np.random.randint(0, 2, size=(1, 8000))
import py3gpp
txsym = py3gpp.nrPDSCH(data, modulation, nlayers, ncellid, rnti)
rxbits = nrPDSCHDecode(txsym, modulation, ncellid, rnti)
assert np.array_equal(data, np.round(rxbits<0).astype(int))
16 changes: 16 additions & 0 deletions tests/test_nrPDSCHDecode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np
import pytest

from py3gpp.nrPDSCH import nrPDSCH
from py3gpp.nrPDSCHDecode import nrPDSCHDecode

@pytest.mark.parametrize('ncellid', [0, 1, 2, 3])
@pytest.mark.parametrize('modulation', ['16QAM', 'QPSK', 'BPSK'])
def test_run_nr_pdsch_combined(ncellid, modulation):
modulation = [modulation]
nlayers = 1
rnti = 6143
data = np.random.randint(0, 2, size=(1, 8000))
txsym = nrPDSCH(data, modulation, nlayers, ncellid, rnti)
rxbits = nrPDSCHDecode(txsym, modulation, ncellid, rnti)
assert np.array_equal(data, np.round(rxbits<0).astype(int))

0 comments on commit f94905e

Please sign in to comment.