Getting Started with 5G Toolkit

This is first quick and simple tutorial for getting newbies started with 5G Toolkit. The tutorial is organized as follows:

  1. Import Python Librariers

  2. Generate the objects required for implementations

  3. Generate Payload (bits/blocks) and CRC encode it.

  4. Symbol Map the encoded bits

  5. Pass symbols through the channels.

  6. Demap the noisy symbols

  7. Compute the CRC Check for block error detection

  8. BER/BLER Computation

  9. Constellation Diagram

  10. Link Level Simulation

This tutorial will simulation the following setup image1

Import Python Libraries

import toolkit5G as tk
2023-07-29 19:08:21.651000: I tensorflow/core/util/] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-07-29 19:08:21.779554: I tensorflow/core/platform/] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-07-29 19:08:22.478801: W tensorflow/compiler/tf2tensorrt/utils/] TF-TRT Warning: Could not find TensorRT
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import numpy as np
# %matplotlib widget
import matplotlib.pyplot as plt

Import 5G Toolkit Libraries

import sys

from toolkit5G.CRC import CRCEncoder
from toolkit5G.CRC import CRCDecoder
from toolkit5G.SymbolMapping import Mapper
from toolkit5G.SymbolMapping import Demapper
from toolkit5G.ChannelProcessing import AddNoise
# from IPython.display import display, HTML
# display(HTML("<style>.container { width:80% !important; }</style>"))

Create Objects

num_bits_per_symbol = 4
demapping_method    = "app"

crcEncoder    = CRCEncoder(crcType="CRC24C") # Create object of CRC Encoder
crcDecoder    = CRCDecoder("CRC24C")         # Create object of CRC Decoder
qamMapper     = Mapper("qam",num_bits_per_symbol)   # Create Mapper Object
qamDemapper   = Demapper(demapping_method = "app",
                         num_bits_per_symbol = num_bits_per_symbol,
                         hard_out = True)           # Create Demapper Object
awgn          = AddNoise()

Payload Bits Generation and Encoding

  • The payload bits are segregated into blocks where each block has a certain number of bits.

numBlocks     = 100
nBitsPerBlock = 384
bits          = np.random.randint(0, 2, size = (numBlocks,nBitsPerBlock)) # Bits to be Encoded
crcBits       = crcEncoder(bits)

Symbol Mapper

  • Maps the bits to symbols

  • The order of mapping (modulation order) is set on to the object itself.

symbols       = qamMapper(crcBits)

AWGN Channel

  • Pass the symbols to be passed through the noisy channel.

  • Control the amount of noise to be added.

snr           = 100
rxsymbols     = awgn(symbols, (1/snr))

Demapping the Symbols

  • Demaps the bits to symbols

  • The order of mapping (modulation order) is set on to the object itself.

bitsEst       = qamDemapper([np.complex64(rxsymbols), 1/snr])

CRC Decoder: Error Detection

  • Remove the CRC bits

  • Compute CRC check: Wheather all the bits in a blocks are correct or not.

rBits, checks = crcDecoder(bitsEst)

BER and Block Error Computation

Compute the

  • block error rate: \(\frac{\text{blocks in Error}}{\text{Total number of blocks}}\)

  • bit error rate: \(\frac{\text{bits in Error}}{\text{Total number of bits}}\)

ber = np.mean(np.abs(bits-rBits))
bler= 1-np.mean(checks)

print("  Bit error rate = "+str(ber))
print("Block error rate = "+str(bler))

  Bit error rate = 0.0
Block error rate = 0.0

Constellation Diagram

Compare the constellation of the transmitted and received (noisy) symbols.

fig, ax = plt.subplots()

ax.scatter(np.real(rxsymbols), np.imag(rxsymbols), color = "red", marker=".", s=2, label="Received Symbols")
ax.scatter(np.real(symbols), np.imag(symbols), color = "blue", label="Transmitted Symbols")

ax.set_xlabel("Real part $\mathfrak{R} \{x\}$")
ax.set_ylabel("Imaginary part $\mathfrak{I} \{x\}$")
ax.set_title("Contellation Diagram for 16-QAM symbols")

plt.savefig("Constellation.svg", dpi=9600, transparent=True, format="svg")

Performance Evaluations

Display BER/BLER vs SNR.

fig,ax = plt.subplots(1,2, figsize=(15,6))
ls = [":*","-o","--P"]
for i in np.arange(modOrder.size):
    ax[0].semilogy(SNRdB,  ber[i], ls[i], lw=3, ms=9)
    ax[1].semilogy(SNRdB, bler[i], ls[i], lw=3, ms=9)

ax[0].set_xlabel("SNR (dB)")
ax[0].set_ylabel("Bit error rate")
ax[0].set_title("BER vs SNR (dB) for different modulation order")
ax[0].set_xticks(SNRdB, minor=False);

ax[1].set_xlabel("SNR (dB)")
ax[1].set_ylabel("Block error rate")
ax[1].set_title("BLER vs SNR (dB) for different modulation order")
ax[1].set_xticks(SNRdB, minor=False);

plt.savefig("BERvsSNR.svg", dpi=9600, transparent=True, format="svg")
[ ]: