HARQ Event Callback

This notebook demonstrates how to define and use a HARQ event callback.

[1]:
import numpy as np
import time

from neoradium import LdpcCodec, HarqEntity, random, Modem
from neoradium.utils import toLinear

Creating an LDPC Encoder object

[2]:
modulation="16QAM"              # Modulation scheme
coderate = 490/1024             # Target code rate
numLayers = 1                   # To test this with 2 codewords, set this to a value between 5 and 8
txBlockSizes = [10000,10000]    # Transport block size (TBS) (one per codeword)
ldpc = LdpcCodec(modulation, coderate, txBlockSizes, numLayers)
ldpc.print()                    # Print the LDPC encoder's properties

LDPC Encode/Decode Properties:
  Num layers:         1
  Num codewords:      1
  numIter:            5
  nRef:               0
  Modulation:         16QAM
  Coderate:           490/1024
  TBS:                10000
  numLayers:          1
  Base Graph:         1
  Code Block Size:    5280
  Num Code Blocks:    2
  Lifting Size:       240

Defining a callback function and passing it to the HARQ entity

[3]:
# Define a simple call back function which prints the event information:
def handleEvents(event, harqCW):
    # event: The event string. It can be one of ”RXFAILED”, ”RXSUCCESS”, or ”TIMEOUT”
    # harqCW: The instance of HarqCW class that triggered the event
    print(f"HARQ Process {harqCW.process.id}   CW{harqCW.cwIdx+1}: {event:10s}   curTry: {harqCW.curTry}")

# Create the HARQ entity with "Chase Combining" and 8 processes
harq = HarqEntity(ldpc, harqType="CC", numProc=8, eventCallback=handleEvents)

Main transmission loop

[4]:
rangen = random.getGenerator(123)                       # Create new random generator and make results reproducible
modem = Modem(modulation)                               # The Modem instance used for modulation/demodulation

ebNoDb = 3                                              # Set the Eb/No ratio (dB)
snrDb = ebNoDb + 10*np.log10(modem.qm * coderate)       # Convert Eb/No to SNR (dB)
snr = toLinear(snrDb)                                   # Linear SNR
noiseStd = np.sqrt(1/snr)                               # Noise standard deviation

numTransmissions = 50                                   # Total number of transmissions

harq.reset()                                            # Reset HARQ for each execution of this cell
for t in range(numTransmissions):                       # Run this "numTransmissions" times
    txBlocks = []                                       # Transport blocks. One per codeword.
    for c in range(harq.numCW):
        if harq.needNewData[c]:                         # New transmission.
            txBlocks += [random.bits(txBlockSizes[c])]  # Create random bits for the new transport block
        else:                                           # Retransmission
            txBlocks += [None]                          # Set transport block to None to indicate retransmission

    rateMatchedCodeBlocks = harq.encode(txBlocks)        # Prepare the bitstream for transmission

    llrs = []                                           # Received Log-Likelihood Ratios. One per codeword.
    for c in range(harq.numCW):
        channelOutput = modem.modulate(rateMatchedCodeBlocks[c])                    # Modulate the codeblocks
        noisyRxSignal = channelOutput + rangen.awgn(channelOutput.shape, noiseStd)  # Add Noise
        llrs += [ modem.getLLRs(noisyRxSignal, noiseStd**2) ]                       # Calculate the LLRs for each codeword

    decodedTxBlocks, blockErrors = harq.decode(llrs)
    harq.goNext()                                       # Get ready for the next transmission
harq.printStats()                                       # Print HARQ entity's statistics
HARQ Process 0   CW1: RXFAILED     curTry: 0
HARQ Process 1   CW1: RXFAILED     curTry: 0
HARQ Process 2   CW1: RXFAILED     curTry: 0
HARQ Process 3   CW1: RXFAILED     curTry: 0
HARQ Process 4   CW1: RXFAILED     curTry: 0
HARQ Process 5   CW1: RXFAILED     curTry: 0
HARQ Process 6   CW1: RXFAILED     curTry: 0
HARQ Process 7   CW1: RXFAILED     curTry: 0
HARQ Process 0   CW1: RXSUCCESS    curTry: 1
HARQ Process 1   CW1: RXSUCCESS    curTry: 1
HARQ Process 2   CW1: RXSUCCESS    curTry: 1
HARQ Process 3   CW1: RXSUCCESS    curTry: 1
HARQ Process 4   CW1: RXSUCCESS    curTry: 1
HARQ Process 5   CW1: RXSUCCESS    curTry: 1
HARQ Process 6   CW1: RXSUCCESS    curTry: 1
HARQ Process 7   CW1: RXSUCCESS    curTry: 1
HARQ Process 0   CW1: RXFAILED     curTry: 0
HARQ Process 1   CW1: RXFAILED     curTry: 0
HARQ Process 2   CW1: RXFAILED     curTry: 0
HARQ Process 3   CW1: RXFAILED     curTry: 0
HARQ Process 4   CW1: RXFAILED     curTry: 0
HARQ Process 5   CW1: RXFAILED     curTry: 0
HARQ Process 6   CW1: RXFAILED     curTry: 0
HARQ Process 7   CW1: RXFAILED     curTry: 0
HARQ Process 0   CW1: RXSUCCESS    curTry: 1
HARQ Process 1   CW1: RXSUCCESS    curTry: 1
HARQ Process 2   CW1: RXSUCCESS    curTry: 1
HARQ Process 3   CW1: RXSUCCESS    curTry: 1
HARQ Process 4   CW1: RXSUCCESS    curTry: 1
HARQ Process 5   CW1: RXSUCCESS    curTry: 1
HARQ Process 6   CW1: RXSUCCESS    curTry: 1
HARQ Process 7   CW1: RXSUCCESS    curTry: 1
HARQ Process 0   CW1: RXFAILED     curTry: 0
HARQ Process 1   CW1: RXFAILED     curTry: 0
HARQ Process 2   CW1: RXFAILED     curTry: 0
HARQ Process 3   CW1: RXFAILED     curTry: 0
HARQ Process 4   CW1: RXFAILED     curTry: 0
HARQ Process 5   CW1: RXFAILED     curTry: 0
HARQ Process 6   CW1: RXFAILED     curTry: 0
HARQ Process 7   CW1: RXFAILED     curTry: 0
HARQ Process 0   CW1: RXSUCCESS    curTry: 1
HARQ Process 1   CW1: RXSUCCESS    curTry: 1
HARQ Process 2   CW1: RXSUCCESS    curTry: 1
HARQ Process 3   CW1: RXSUCCESS    curTry: 1
HARQ Process 4   CW1: RXSUCCESS    curTry: 1
HARQ Process 5   CW1: RXSUCCESS    curTry: 1
HARQ Process 6   CW1: RXSUCCESS    curTry: 1
HARQ Process 7   CW1: RXSUCCESS    curTry: 1
HARQ Process 0   CW1: RXFAILED     curTry: 0
HARQ Process 1   CW1: RXFAILED     curTry: 0

HARQ Entity Statistics:
  numTxBits (per try):      [260000 240000      0      0]
  numRxBits (per try):      [     0 240000      0      0]
  numTxBlocks (per try):    [26 24  0  0]
  numRxBlocks (per try):    [ 0 24  0  0]
  numTimeouts:              0
  totalTxBlocks:            50
  totalRxBlocks:            24
  totalTxBits:              500000
  totalRxBits:              240000
  throughput:               48.00%
  bler:                     52.00%
  bler1st:                  100.00%
  Avg. retransmissions:     1.00
  Avg. failed transmissions:1.00

[ ]:

[ ]: