Skip to content

Commit

Permalink
add nrPDSCH() and nrPDSCHDecode() to PDSCH example
Browse files Browse the repository at this point in the history
  • Loading branch information
catkira committed Oct 29, 2023
1 parent 7a953ef commit 4cb9d65
Showing 1 changed file with 29 additions and 53 deletions.
82 changes: 29 additions & 53 deletions examples/pdsch_tx_rx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,22 +12,22 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'CRC': '24A', 'L': 24, 'BGN': 1, 'C': 2, 'Lcb': 24, 'F': 244.0, 'Zc': 240, 'K': 5280, 'N': 15840}\n"
"{'CRC': '24A', 'L': 24, 'BGN': 1, 'C': 2, 'Lcb': 24, 'F': 404.0, 'Zc': 320, 'K': 7040, 'N': 21120}\n"
]
}
],
"source": [
"A = 10000 # Transport block length, positive integer\n",
"rate = 449/1024 # Target code rate, 0<R<1\n",
"A = 10000 # Transport block length\n",
"rate = 449 / 1024 # Target code rate\n",
"rv = 0 # Redundancy version, 0-3\n",
"modulation = 'QPSK'\n",
"modulation = '16QAM'\n",
"nlayers = 1\n",
"\n",
"cbs_info = nrDLSCHInfo(A, rate)\n",
Expand All @@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -54,64 +54,40 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# channel\n",
"if True:\n",
" nid = 1\n",
" pdsch_bits = nrPDSCH(np.expand_dims(ch_in, 0), [modulation], 1, nid, 0)\n",
" ch_out = nrPDSCHDecode(pdsch_bits, [modulation], nid, 0)\n",
"else:\n",
" ch_out = 1-2*(ch_in)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"block length B = 16320, number of information bits K = 5280, code rate R = 0.3333333333333333, i_ls = 7\n",
"decoding segment 0 ...\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"block length B = 21760, number of information bits K = 7040, code rate R = 0.3333333333333333, i_ls = 2\n",
"decoding segment 0 ...\n",
"decoding segment 1 ...\n",
"decoding finished after 25 iterations\n",
"code block CRC: 0\n",
"transport block CRC: [0]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Traceback (most recent call last):\n",
" File \"_pydevd_bundle/pydevd_cython.pyx\", line 1134, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch\n",
" File \"_pydevd_bundle/pydevd_cython.pyx\", line 311, in _pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend\n",
" File \"/home/benja/.local/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py\", line 2062, in do_wait_suspend\n",
" keep_suspended = self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)\n",
" File \"/home/benja/.local/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py\", line 2098, in _do_wait_suspend\n",
" time.sleep(0.01)\n",
"KeyboardInterrupt\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb Cell 4\u001b[0m line \u001b[0;36m1\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu-18.04/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb#W3sdnNjb2RlLXJlbW90ZQ%3D%3D?line=9'>10</a>\u001b[0m out,tb_err \u001b[39m=\u001b[39m nrCRCDecode(blk, cbs_info[\u001b[39m'\u001b[39m\u001b[39mCRC\u001b[39m\u001b[39m'\u001b[39m])\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu-18.04/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb#W3sdnNjb2RlLXJlbW90ZQ%3D%3D?line=10'>11</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mtransport block CRC: \u001b[39m\u001b[39m{\u001b[39;00mtb_err\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[0;32m---> <a href='vscode-notebook-cell://wsl%2Bubuntu-18.04/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb#W3sdnNjb2RlLXJlbW90ZQ%3D%3D?line=12'>13</a>\u001b[0m np\u001b[39m.\u001b[39marray_equal(in_, out)\n",
"\u001b[1;32m/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb Cell 4\u001b[0m line \u001b[0;36m1\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu-18.04/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb#W3sdnNjb2RlLXJlbW90ZQ%3D%3D?line=9'>10</a>\u001b[0m out,tb_err \u001b[39m=\u001b[39m nrCRCDecode(blk, cbs_info[\u001b[39m'\u001b[39m\u001b[39mCRC\u001b[39m\u001b[39m'\u001b[39m])\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu-18.04/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb#W3sdnNjb2RlLXJlbW90ZQ%3D%3D?line=10'>11</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mtransport block CRC: \u001b[39m\u001b[39m{\u001b[39;00mtb_err\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[0;32m---> <a href='vscode-notebook-cell://wsl%2Bubuntu-18.04/home/benja/git/py3gpp/examples/pdsch_tx_rx.ipynb#W3sdnNjb2RlLXJlbW90ZQ%3D%3D?line=12'>13</a>\u001b[0m np\u001b[39m.\u001b[39marray_equal(in_, out)\n",
"File \u001b[0;32m_pydevd_bundle/pydevd_cython.pyx:1443\u001b[0m, in \u001b[0;36m_pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32m_pydevd_bundle/pydevd_cython.pyx:700\u001b[0m, in \u001b[0;36m_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32m_pydevd_bundle/pydevd_cython.pyx:1143\u001b[0m, in \u001b[0;36m_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32m_pydevd_bundle/pydevd_cython.pyx:1134\u001b[0m, in \u001b[0;36m_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32m_pydevd_bundle/pydevd_cython.pyx:311\u001b[0m, in \u001b[0;36m_pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend\u001b[0;34m()\u001b[0m\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py:2062\u001b[0m, in \u001b[0;36mPyDB.do_wait_suspend\u001b[0;34m(self, thread, frame, event, arg, exception_type)\u001b[0m\n\u001b[1;32m 2059\u001b[0m from_this_thread\u001b[39m.\u001b[39mappend(frame_custom_thread_id)\n\u001b[1;32m 2061\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_threads_suspended_single_notification\u001b[39m.\u001b[39mnotify_thread_suspended(thread_id, stop_reason):\n\u001b[0;32m-> 2062\u001b[0m keep_suspended \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)\n\u001b[1;32m 2064\u001b[0m frames_list \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 2066\u001b[0m \u001b[39mif\u001b[39;00m keep_suspended:\n\u001b[1;32m 2067\u001b[0m \u001b[39m# This means that we should pause again after a set next statement.\u001b[39;00m\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py:2098\u001b[0m, in \u001b[0;36mPyDB._do_wait_suspend\u001b[0;34m(self, thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)\u001b[0m\n\u001b[1;32m 2095\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_call_input_hook()\n\u001b[1;32m 2097\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprocess_internal_commands()\n\u001b[0;32m-> 2098\u001b[0m time\u001b[39m.\u001b[39;49msleep(\u001b[39m0.01\u001b[39;49m)\n\u001b[1;32m 2100\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcancel_async_evaluation(get_current_thread_id(thread), \u001b[39mstr\u001b[39m(\u001b[39mid\u001b[39m(frame)))\n\u001b[1;32m 2102\u001b[0m \u001b[39m# process any stepping instructions\u001b[39;00m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
"transport block CRC: [0]\n",
"output equals input: True\n"
]
}
],
"source": [
"ch_out = double(1-2*(ch_in))\n",
"raterec = nrRateRecoverLDPC(ch_out, A, rate, rv, modulation, nlayers)\n",
"raterec = nrRateRecoverLDPC(ch_out[0], A, rate, rv, modulation, nlayers)\n",
"\n",
"dec_bits, iters = nrLDPCDecode(raterec, cbs_info['BGN'], 25)\n",
"print(f'decoding finished after {iters} iterations')\n",
Expand All @@ -122,7 +98,7 @@
"out, tb_err = nrCRCDecode(blk, cbs_info['CRC'])\n",
"print(f'transport block CRC: {tb_err}')\n",
"\n",
"np.array_equal(in_, out)"
"print(f'output equals input: {np.array_equal(in_, out)}')"
]
}
],
Expand Down

0 comments on commit 4cb9d65

Please sign in to comment.