Channel Coding
The module chancodebase.py implements the base class ChanCodeBase for all NeoRadium’s channel
coding classes. It encapsulates some basic functionality such as creating, appending, and checking various types of
CRC based on 3GPP TS 38.212.
Here is the hierarchy of current channel coding classes in NeoRadium:
ChanCodeBase(The base class for all channel coding)
- class neoradium.chancodebase.ChanCodeBase
This is the base class for all channel coding classes in NeoRadium.
- classmethod getCrc(bits, poly)
Calculates and returns the CRC based on the bitstream
bitsand the generator polynomial specified bypoly.- Parameters:
bits (NumPy array) – A 1D or 2D NumPy array of bits. If it is a 1D NumPy array, the CRC bits are calculated for the given bitstream and a 1D NumPy array containing the CRC bits is returned. If
bitsis anN x LNumPy array, it is assumed that we haveNbitstreams of lengthL. In this case the CRC bits are calculated for each one ofNbitstreams and anN x CNumPy array is returned whereCis the CRC length.poly (str) –
The string specifying the generator polynomial. The following generator polynomials are supported.
The value of
polyGenerator polynomial
’6’
1100001
’11’
111000100001
’16’
10001000000100001
’24A’
1100001100100110011111011
’24B’
1100000000000000001100011
’24C’
1101100101011000100010111
For more details please refer to 3GPP TS 38.212, Section 5.1.
- Returns:
If
bitsis a 1D NumPy array, the CRC bits are returned in a 1D NumPy array. Ifbitsis anN x LNumPy array, the CRC bits ofNbitstreams are returned in anN x CNumPy array whereCis the CRC length.- Return type:
NumPy array
- classmethod checkCrc(bits, poly)
Checks the CRC bits at the end of the bitstream
bitsand returns True if the CRC is correct (matched) and False if it is not.- Parameters:
bits (NumPy array) – A 1D or 2D NumPy array of bits. If it is a 1D NumPy array, the CRC bits are checked for the given bitstream and a boolean value is returned. If
bitsis anN x LNumPy array, it is assumed that we haveNbitstreams of lengthL. In this case the CRC bits are checked for each one ofNbitstreams and a boolean NumPy array of lengthNis returned specifying the results of CRC check for each bitstream.poly (str) – The string specifying the generator polynomial. See the
getCrc()method above for a list of generator polynomials.
- Returns:
If
bitsis a 1D NumPy array, the CRC check result is returned as a boolean value. Ifbitsis anN x LNumPy array, the CRC check results ofNbitstreams are returned in a boolean NumPy array of lengthN.- Return type:
boolean or NumPy array
- classmethod appendCrc(bits, poly)
Calculates the CRC bits for the bitstream
bits, appends them to the end of the bitstream, and returns the new bitstream containing the original bitstream with CRC bits at the end.This function calls the
getCrc()method to get the CRC bits and then appends them to the end ofbits.- Parameters:
bits (NumPy array) – A 1D or 2D NumPy array of bits. If it is a 1D NumPy array, the CRC bits are calculated for the given bitstream and a 1D NumPy array containing the original bitstream and the CRC bits is returned. If
bitsis anN x LNumPy array, it is assumed that we haveNbitstreams of lengthL. In this case the CRC bits are calculated and appended to the end of each one ofNbitstreams and anN x MNumPy array is returned whereM=L+CandCis the CRC length.poly (str) – The string specifying the generator polynomial. See the
getCrc()method above for a list of generator polynomials.
- Returns:
If
bitsis a 1D NumPy array, the new bitstream with CRC appended to the end is returned in a 1D NumPy array. Ifbitsis anN x LNumPy array, the CRC bits for each one ofNbitstreams are appended to the end and anN x MNumPy array is returned whereM=L+CandCis the CRC length.- Return type:
NumPy array
LDPC
The module ldpc.py contains the API used for
Low-Density Parity Check (LDPC) encoding and
decoding. It implements the class LdpcBase, which is the base class for LDPC coding and is derived
from the ChanCodeBase class. It also implements the classes LdpcEncoder
and LdpcDecoder both of which are derived from LdpcBase.
This implementation is based on 3GPP TS 38.212.
- class neoradium.ldpc.LdpcBase(baseGraphNo=1, modulation='QPSK', txLayers=1, nRef=0)
This is the base class for LDPC coding. Both
LdpcEncoderandLdpcDecoderclasses are derived from this class.- Parameters:
baseGraphNo (int) – The base graph used by the LDPC encoder/decoder. It can be either 1 or 2. The choice of base graph determines the maximum code block size (8448 bits for base graph 1 and 3840 bits for base graph 2). The base graphs are defined as \(H_{BG}\) in 3GPP TS 38.212, Tables 5.3.2-2 and 5.3.2-3.
modulation (str) –
The modulation scheme used by the physical channel based on table 7.3.1.2-1 in 3GPP TR 38.211. Here is a list of supported Modulation Schemes:
Modulation Scheme
Modulation Order (
qm)BPSK
1
QPSK
2
16QAM
4
64QAM
6
256QAM
8
1024QAM
10
txLayers (int) – The number of transmission layers in the physical channel using this LDPC encoder/decoder.
nRef (int) – This is used for Low-Buffer Rate Matching (LBRM). This is the value \(N_{ref}\) as explained in 3GPP TS 38.212, Section 5.4.2.1.
Other Properties:
- baseGraph:
The base graph matrix defined as \(H_{BG}\) in 3GPP 3GPP TS 38.212, Tables 5.3.2-2 and 5.3.2-3.
- maxCodeBlockSize:
The maximum code block size. It is set to 8448 for
baseGraphNo=1, and 3840 forbaseGraphNo=2. This is \(K_{cb}\) in 3GPP TS 38.212, Section 5.2.2.- txBlockSize:
Transport block size. The length of the transport block in bits. The function
getTxBlockSize()could be used to obtain the size of the transport block. Note that a transport block is first appended with a 24-bit CRC. The valuetxBlockSizeincludes the 24-bit CRC. This is \(B\) in 3GPP TS 38.212, Section 5.2.2.- numCodeBlocks:
The number of code blocks. This is a positive integer, determined based on
maxCodeBlockSizeandtxBlockSize. This is \(C\) in 3GPP TS 38.212, Section 5.2.2.- codeBlockSize:
The code block size. This is \(K\) in 3GPP TS 38.212, Section 5.2.2.
- liftingSize:
The lifting size which is used to create a parity-check matrix from the base graph. This value is extracted from 3GPP TS 38.212, Table 5.3.2-1. This is \(Z_c\) in 3GPP TS 38.212, Section 5.2.2.
- setIndex:
The Set index (\(i_{LS}\)) in 3GPP TS 38.212, Table 5.3.2-1.
Note
All of these properties are initialized only after a call to
doSegmentation()orgetRateMatchedCodeBlocks()methods ofLdpcEncoderclass or therecoverRate()method ofLdpcDecoderclass.- isValidCodedBlock(codedBlock)
Checks whether the given
codedBlockis a valid LDPC coded bitstream.- Parameters:
codedBlock (NumPy array) – A NumPy array of bits representing the coded block. The length of
codedBlockmust be a multiple of the propertyliftingSize(\(Z_c\)).- Returns:
True is returned if this is a valid LDPC coded block. Otherwise, this function returns False.
- Return type:
boolean
- class neoradium.ldpc.LdpcEncoder(baseGraphNo=1, modulation='QPSK', txLayers=1, nRef=0, targetRate=0.4384765625)
This is the Low-Density Parity Check (LDPC) encoder class. It is derived from the
LdpcBaseclass and performs the following tasks:Code block segmentation based on 3GPP TS 38.212, Section 5.2.2
LDPC encoding based on 3GPP TS 38.212, Section 5.3.2
Rate Matching with bit selection and interleaving based on 3GPP TS 38.212, Section 5.4.2
- Parameters:
baseGraphNo (int) – The base graph used by this LDPC encoder. It can be either 1 or 2. In NR, base graph 1 is designed for code rates from 1/3 to 22/24 (approximately 0.33-0.92) and base graph 2 from 1/5 to 5/6 (approximately 0.2-0.83). The choice between base graph 1 or 2 is based on the transport block size and the targeted code rate (
targetRate). The choice of base graph then determines the maximum code block size (8448 bits for base graph 1 and 3840 bits for base graph 2). The base graphs are defined as \(H_{BG}\) in 3GPP 3GPP TS 38.212, Tables 5.3.2-2 and 5.3.2-3.modulation (str) –
The modulation scheme used by the physical channel based on table 7.3.1.2-1 in 3GPP TR 38.211. Here is a list of supported Modulation Schemes:
Modulation Scheme
Modulation Order (
qm)BPSK
1
QPSK
2
16QAM
4
64QAM
6
256QAM
8
1024QAM
10
txLayers (int) – The number of transmission layers in the physical channel using this LDPC encoder.
nRef (int) – This is used for Low-Buffer Rate Matching (LBRM). Please refer to 3GPP TS 38.212, Section 5.4.2.1 for more details.
targetRate (float) – The desired code rate which is the ratio of the data bits to the total number of bits transmitted (including the LDPC redundancy bits).
Please refer to the
LdpcBaseclass for a list of properties inherited from the base class.- print(indent=0, title=None, getStr=False)
Prints the properties of this
LdpcEncoderobject.- Parameters:
indent (int) – The number of indentation characters.
title (str) – If specified, it is used as a title for the printed information.
getStr (Boolean) – If True, returns a text string instead of printing it.
- Returns:
If the
getStrparameter is True, then this function returns the information in a text string. Otherwise, nothing is returned.- Return type:
None or str
- doSegmentation(txBlock, fillerBit=0)
The first step in LDPC encoding process is breaking down the transport block into smaller more manageable code blocks. This function receives a transport block
txBlock, performs segmentation based on 3GPP TS 38.212, Section 5.2.2, and outputs a 2DC x KNumPy array containingCcode blocks of lengthK.
- Parameters:
txBlock (NumPy array) – A NumPy array of bits containing the transport block information.
fillerBit (int) –
This parameter is ignored.
Note
NeoRadium no longer uses the filler bits in its newer versions. This parameter will be removed in future releases.
- Returns:
A 2D
C x KNumPy array containingCcode blocks of lengthK.- Return type:
NumPy array
- encode(codeBlocks, puncture=True)
This function encodes a set of code blocks and returns a set of LDPC coded blocks based on the procedure explained in 3GPP TS 38.212, Section 5.3.2.
- Parameters:
codeBlocks (NumPy array) – A
C x KNumPy array containingCcode blocks of lengthKbeing LDPC-encoded by this function.puncture (Boolean) – By default, the first \(2Z_c\) bits of the code blocks are punctured (removed). If
puncture=False, then the first \(2Z_c\) bits are kept in the returned encoded blocks.
- Returns:
A
C x NNumPy array containing theCencoded blocks.- Return type:
NumPy array
- rateMatch(codedBlocks, g=None, concatCBs=True, rv=0)
This function receives a set of encoded blocks and returns the rate-matched output based on the configured code rate. It performs bit selection and interleaving based on 3GPP TS 38.212, Section 5.4.2
- Parameters:
codedBlocks (NumPy array) – A
C x NNumPy array containingCencoded code blocks of lengthNbeing rate-matched by this function.g (int or None) – This is the total number of bits available for transmission of the transport block. It is the value \(G\) in the bit selection process explained in 3GPP TS 38.212, Section 5.4.2.1. If not provided (default), it is calculated as \(G=\lceil \frac {B-24} R \rceil\) where \(B\) is the transport block size and \(R\) is the code rate.
concatCBs (Boolean) – If True (Default), the rate-matched coded blocks are concatenated and a single array of bits is returned. Otherwise, a list of NumPy arrays is returned and each element in the list is the bit array corresponding to each coded block.
rv (int) – The Redundancy Version used with Hybrid Automatic Repeat Request (HARQ). It must be one of 0, 1, 2, or 3. Please refer to 3GPP TS 38.212, Table 5.4.2.1-2 for more details. The default is 0 which means first transmission.
- Returns:
If
concatCBsis True, a 1-D NumPy array is returned containing the concatenation of all rate-matched coded blocks. Otherwise, a list of NumPy arrays is returned and each element in the list is the bit array corresponding to each coded block.- Return type:
NumPy array or list of NumPy arrays
- getRateMatchedCodeBlocks(txBlock, g=None, concatCBs=True, addCrc=True)
This function receives a transport block (
txBlock) and returns the rate-matched output in a single call. It first appends a 24-bit CRC to the transport block and then uses the functionsdoSegmentation(),encode(), andrateMatch(), to perform segmentation, encoding, and rate matching.- Parameters:
txBlock (NumPy array) – A NumPy array of bits containing the transport block information.
g (int or None) – This is the total number of bits available for transmission of the transport block. It is the value \(G\) in the bit selection process explained in 3GPP TS 38.212, Section 5.4.2.1. If not provided (default), it is calculated as \(G=\lceil \frac {B-24} R \rceil\) where \(B\) is the transport block size and \(R\) is the code rate.
concatCBs (Boolean) – If True (Default), the rate-matched coded blocks are concatenated and a single array of bits is returned. Otherwise, a list of NumPy arrays is returned and each element in the list is the bit array corresponding to each coded block.
addCrc (Boolean) – If True a 24-bit CRC is appended to the
txBlockbefore the encoding process. Otherwise, it is assumed that thetxBlockalready includes the 24-bit CRC and therefore a CRC is not appended.
- Returns:
If
concatCBsis True, a 1-D NumPy array is returned containing the concatenation of all rate-matched coded blocks. Otherwise, a list of NumPy arrays is returned and each element in the list is the bit array corresponding to each coded block.- Return type:
NumPy array or list of NumPy arrays
- getDecoder()
This function creates and returns an
LdpcDecoderobject based on the configuration of thisLdpcEncoder. It makes it easier to create a decoder object based on the existing encoder object.- Returns:
An LDPC decoder object created based on this
LdpcEncoder.- Return type:
- class neoradium.ldpc.LdpcDecoder(baseGraphNo=1, modulation='QPSK', txLayers=1, nRef=0)
This is the Low-Density Parity Check (LDPC) decoder class. It is derived from the
LdpcBaseclass and performs rate recovery, LDPC decoding, and code block merging. These are basically the opposite of the encoding tasks rate matching, LDPC encoding, and segmentation which are performed in reverse order.The following example shows a typical use case for decoding the received LDPC-coded information into transport blocks:
An example of LDPC decoding# Rate recovery # Let's assume we have: # An LdpcDecoder object (ldpcDecoder) # The LLRs extracted from a received resource grid (llrs) # The transport block size (txBlockSize) rxCodedBlocks = ldpcDecoder.recoverRate(llrs, txBlockSize) # LDPC-Decoding decodedBlocks = ldpcDecoder.decode(rxCodedBlocks) # CRC-checking and de-segmentation decodedTxBlockWithCRC, crcMatch = ldpcDecoder.checkCrcAndMerge(decodedBlocks) # Checking the CRC of the transport block txBlockCrcMatch = ldpcDecoder.checkCrc(decodedTxBlockWithCRC,'24A') # Removing the transport block CRC decodedTxBlock = decodedTxBlockWithCRC[:-24]
- Parameters:
baseGraphNo (int) – The base graph used by this LDPC decoder. It can be either 1 or 2. In NR, base graph 1 is designed for code rates from 1/3 to 22/24 (approximately 0.33-0.92) and base graph 2 from 1/5 to 5/6 (approximately 0.2-0.83). The choice between base graph 1 or 2 is based on the transport block size and the targeted code rate (
targetRate). The choice of base graph then determines the maximum code block size (8448 bits for base graph 1 and 3840 bits for base graph 2). The base graphs are defined as \(H_{BG}\) in 3GPP 3GPP TS 38.212, Tables 5.3.2-2 and 5.3.2-3.modulation (str) –
The modulation scheme used by the physical channel based on table 7.3.1.2-1 in 3GPP TR 38.211. Here is a list of supported Modulation Schemes:
Modulation Scheme
Modulation Order (
qm)BPSK
1
QPSK
2
16QAM
4
64QAM
6
256QAM
8
1024QAM
10
txLayers (int) – The number of transmission layers in the physical channel using this LDPC decoder.
nRef (int) – This is used for Low-Buffer Rate Matching (LBRM). Please refer to 3GPP TS 38.212, Section 5.4.2.1 for more details.
Note
For a pair of
LdpcEncoder/LdpcDecoderobjects to work properly, all of the above parameters used to configure them should match.Please refer to the
LdpcBaseclass for a list of properties inherited from the base class.- print(indent=0, title=None, getStr=False)
Prints the properties of this
LdpcDecoderobject.- Parameters:
indent (int) – The number of indentation characters.
title (str) – If specified, it is used as a title for the printed information.
getStr (Boolean) – If True, returns a text string instead of printing it.
- Returns:
If the
getStrparameter is True, then this function returns the information in a text string. Otherwise, nothing is returned.- Return type:
None or str
- recoverRate(rxBlock, txBlockSize, harq=None)
This function receives an array of Log-Likelihood Ratios (LLRs) in
rxBlock, and the transport block sizetxBlockSize, and returns a set of rate-recovered LLRs for each code block that is ready for LDPC decoding. This function does the exact opposite of theLdpcEncoder’srateMatch()method. Note that while therateMatch()works with bits, this method works on LLRs.The LLRs are usually obtained by performing demodulation process. The method
getLLRsFromGrid()of thePDSCHfor example can be used to get LLRs from a received resource grid.- Parameters:
rxBlock (NumPy array) – A NumPy array of Log-Likelihood Ratios (LLRs) obtained as a result of demodulation process. Each element is a real LLR value corresponding to each received bit. The larger the LLR value, the more likely it is for that bit to be a
0.txBlockSize (int) – The transport block size. This is the number of bits in a transport block (Not including the 24-bit CRC that is appended to the transport block). For example, in the case of PDSCH communication, this value can be obtained using the method
getTxBlockSize()of thePDSCHclass.harq (
HarqCW) – TheHarqCWobject handling retransmissions for each codeword. If specified, this method uses this object to obtain the ‘Redundancy Version’ and the circular buffer of the previous transmission of the same transport block.
- Returns:
A
C x NNumPy array ofCreceived coded blocks of lengthNcontaining the LLR values for each coded block ready to be LDPC-decoded.- Return type:
NumPy array
- decode(rxCodeBlock, numIter=5, onlyInfoBits=True, outputBelief=False)
This function implements the Layered Belief Propagation algorithm for LDPC-decoding of LLRs into decoded code blocks. This implementation was inspired mostly by LDPC and Polar Codes in 5G Standard set of videos and was written from scratch to efficiently perform the decoding process.
- Parameters:
rxCodeBlock (NumPy array) – A
C x NNumPy array ofCreceived coded blocks of lengthNcontaining the LLR values for each coded block.numIter (int) – The number of iterations in the Layered Belief Propagation decoding algorithm. Larger values in some cases could result in more accurate decoding while making the whole decoding process slower.
onlyInfoBits (Boolean) – If True (default), only the information bits are returned. Otherwise, the parity bits are also included in the returned values together with the information bits.
outputBelief (Boolean) – If True, the calculated final belief values are returned for each bit which is the LLR for the decoded bits. Otherwise (default), hard decision is applied to the final belief values and the decoded bits are returned.
- Returns:
If
onlyInfoBitsis set to True, aC x KNumPy array ofCcode blocks of lengthKis returned, whereKis thecodeBlockSize. Otherwise, the parity bit information is also included in the returned NumPy array which makes each code block longer thanK. The contents of the return NumPy array can be bits or belief values based on theoutputBeliefparameter.- Return type:
NumPy array
- checkCrcAndMerge(rxCodedBlocks)
This function performs CRC checking on the each code block, re-assembles the transport block by combining the code blocks, and returns the transport block together with the results of CRC checks for each code block.
Note that the returned value of this function includes the 24 bits of transport block CRC. The transport block CRC can be checked using the
checkCrc()method.- Parameters:
rxCodedBlocks (NumPy array) – A
C x KNumPy array ofCcode blocks of lengthK. Each code block contains a CRC as its last 24 bits. TherxCodedBlocksis usually the returned value of thedecode()method explained above.- Returns:
txBlock (NumPy array of bits) – The NumPy array containing the transport block together with its 24-bit CRC at the end which can be verified using the
checkCrc()method.crcCheckResults (NumPy array of booleans) – The boolean NumPy array containing the CRC check results for each code block. To have a valid transport block, all of the values in this NumPy array must be True.
Polar Coding
The module polar.py contains the API used for
Polar coding. It implements the class
PolarBase, which is the base class for other polar coding classes and is derived from the
ChanCodeBase class. It also implements the classes PolarEncoder and
PolarDecoder both of which are derived from PolarBase.
This implementation is based on 3GPP TS 38.212.
- class neoradium.polar.PolarBase(payloadSize=0, rateMatchedLen=0, dataType=None, **kwargs)
This is the base class for all polar coding classes. Both
PolarEncoderandPolarDecoderclasses are derived from it. In 5G NR, polar coding is used for the following cases:Downlink Control Information (DCI)
Uplink Control Information (UCI)
Physical Broadcast Channel (PBCH)
- Parameters:
payloadSize (int) – The size of input bitstream not including the CRC bits. This is the value \(A\) in 3GPP TS 38.212, Section 5.2.1.
rateMatchedLen (int) – The total length of rate-matched output bitstream. This is the value \(E\) in 3GPP TS 38.212, Sections 5.3.1 and 5.4.1.
dataType (str or None) –
The type of data using this Polar encoder/decoder. It can be one of the following:
- ”DCI”:
Downlink Control Information
- ”UCI”:
Uplink Control Information
- ”PBCH”:
Physical Broadcast Channel
- None:
Customized Polar Coding.
kwargs (dict) –
A set of optional arguments depending on the
dataType:- iBIL:
Coded bits Interleaving flag. This is a boolean value that indicates whether coded bits interleaving is enabled (True) or disabled (False). By default
iBIL=False. This is the value \(I_{BIL}\) in 3GPP TS 38.212, Section 5.4.1.3. This parameter is ignored if thedataTypeis not None. In this case,iBILis set to True fordataType="UCI", and False fordataType="DCI"anddataType="PBCH"cases.- nMax:
Max value of \(n\) where \(N=2^n\) is the length of the polar code. By default this is set to 10 (which means \(N=1024\). This is the value \(N_{max}\) in 3GPP TS 38.212, Section 5.3.1.2. This parameter is ignored if the
dataTypeis not None. In this case,nMax=10whendataType="UCI", andnMax=9fordataType="DCI"anddataType="PBCH"cases.- iIL:
Input Interleaving flag. This is a boolean value that indicates whether input interleaving is enabled (True) or disabled (False). By default
iIL=False. This is the value \(I_{IL}\) in 3GPP TS 38.212, Section 5.3.1.1. This parameter is ignored if thedataTypeis not None. In this case,iILis set to False fordataType="UCI", and True fordataType="DCI"anddataType="PBCH"cases.- nPC:
Total number of parity-check bits. By default this is set to 0. This is the value \(N_{PC}\) in 3GPP TS 38.212, Section 5.3.1. This parameter is ignored if the
dataTypeis not None. In this case,nPC=0whendataTypeis set to"DCI"or"PBCH". For the"UCI"case, this value may be set to 0 or 3 which is determined based on the procedure explained in 3GPP TS 38.212, Section 5.3.1.2.- nPCwm:
The number of Low-weight, High-Reliability parity-check bits out of the total parity-check bits
nPC. By default this is set to 0. This is the value \(n_{PC}^{wm}\) in 3GPP TS 38.212, Sections 5.3.1.2, 6.3.1.3.1, and 6.3.2.3.1. This parameter is ignored if thedataTypeis not None. In this case,nPCwm=0whendataTypeis set to"DCI"or"PBCH". For the"UCI"case, this value may be set to 0 or 1 which is determined based on the procedure explained in 3GPP TS 38.212, Sections 6.3.1.3.1 and 6.3.2.3.1.- iSeg:
Segmentation flag. This is a boolean value that indicates whether segmentation is enabled (True) or disabled (False). By default
iSeg=False. This is the value \(I_{seg}\) in 3GPP TS 38.212, Section 5.2.1. This parameter is ignored if thedataTypeis not None. In this case,iSeg=FalsewhendataType="DCI"ordataType="PBCH". WhendataType="UCI",iSegis set based on the value ofpayloadSize.- crcPoly:
The CRC polynomial. This is a string specifying the CRC polynomial or None. If specified, it must be one of the values specified in
getCrc()for thepolyparameter. The default value is"11". This parameter is ignored if thedataTypeis not None. In this casecrcPolyis set to"6"or"11"depending onpayloadSizefordataType="UCI", and"24C"fordataType="DCI"anddataType="PBCH"cases.
Other Properties:
- rateMatchedBlockLen:
The number of rate-matched bits transmitted for each code block when segmented. This is the same as
rateMatchedLenif segmentation is disabled. This is the value \(E_r\) in 3GPP TS 38.212, Section 5.5.- codeBlockSize:
The code block size. This is the value \(K\) in 3GPP TS 38.212, Section 5.3.1 which includes the CRC bits (if any).
- polarCodeSize:
The polar code size \(N\). This is always a power of 2.
- msgBits:
A list of indices of the message bits in the coded bitstream.
- frozenBits:
A list of indices of the frozen bits in the coded bitstream.
- pcBits:
A list of indices of the parity-check bits in the coded bitstream. This can be empty depending on
nPC.- generator:
The polar coding generator matrix as a 2-D NumPy array.
- setIoSizes(payloadSize, rateMatchedLen)
This function can be called to re-initialize the class properties. When the
payloadSizeorrateMatchedLenparameters change but other properties remain the same, you can either create a new polar encoder/decoder object or reuse the existing objects and re-initialize them using this method.Note that if there is no change in the values of
payloadSizeandrateMatchedLen, this function returns without doing anything.- Parameters:
payloadSize (int) – The new size of input bitstream not including the CRC bits. This is the value \(A\) in 3GPP TS 38.212, Section 5.2.1.
rateMatchedLen (int) – The new total length of rate-matched output bitstream. This is the value \(E\) in 3GPP TS 38.212, Sections 5.3.1 and 5.4.1.
- class neoradium.polar.PolarEncoder(payloadSize=0, rateMatchedLen=0, dataType=None, **kwargs)
This class is used to encode a bitstream using Polar coding. It is derived from the
PolarBaseclass and performs the following tasks:Segmentation of the transport block based on 3GPP TS 38.212, Section 5.2.1
Polar encoding based on 3GPP TS 38.212, Section 5.3.1
Rate Matching with Sub-block interleaving, bit selection, and interleaving of coded bits based on 3GPP TS 38.212, Section 5.4.1
- Parameters:
payloadSize (int) – The size of input bitstream not including the CRC bits. This is the value \(A\) in 3GPP TS 38.212, Section 5.2.1.
rateMatchedLen (int) – The total length of rate-matched output bitstream. This is the value \(E\) in 3GPP TS 38.212, Sections 5.3.1 and 5.4.1.
dataType (str or None) –
The type of data using this Polar encoder/decoder. It can be one of the following:
- ”DCI”:
Downlink Control Information
- ”UCI”:
Uplink Control Information
- ”PBCH”:
Physical Broadcast Channel
- None:
Customized Polar Coding.
kwargs (dict) –
A set of optional arguments depending on the
dataType:- iBIL:
Coded bits Interleaving flag. This is a boolean value that indicates whether coded bits interleaving is enabled (True) or disabled (False). By default
iBIL=False. This is the value \(I_{BIL}\) in 3GPP TS 38.212, Section 5.4.1.3. This parameter is ignored if thedataTypeis not None. In this case,iBILis set to True fordataType="UCI", and False fordataType="DCI"anddataType="PBCH"cases.- nMax:
Max value of \(n\) where \(N=2^n\) is the length of the polar code. By default this is set to 10 (which means \(N=1024\). This is the value \(N_{max}\) in 3GPP TS 38.212, Section 5.3.1.2. This parameter is ignored if the
dataTypeis not None. In this case,nMax=10whendataType="UCI", andnMax=9fordataType="DCI"anddataType="PBCH"cases.- iIL:
Input Interleaving flag. This is a boolean value that indicates whether input interleaving is enabled (True) or disabled (False). By default
iIL=False. This is the value \(I_{IL}\) in 3GPP TS 38.212, Section 5.3.1.1. This parameter is ignored if thedataTypeis not None. In this case,iILis set to False fordataType="UCI", and True fordataType="DCI"anddataType="PBCH"cases.- nPC:
Total number of parity-check bits. By default this is set to 0. This is the value \(N_{PC}\) in 3GPP TS 38.212, Section 5.3.1. This parameter is ignored if the
dataTypeis not None. In this case,nPC=0whendataTypeis set to"DCI"or"PBCH". For the"UCI"case, this value may be set to 0 or 3 which is determined based on the procedure explained in 3GPP TS 38.212, Section 5.3.1.2.- nPCwm:
The number of Low-weight, High-Reliability parity-check bits out of the total parity-check bits
nPC. By default this is set to 0. This is the value \(n_{PC}^{wm}\) in 3GPP TS 38.212, Sections 5.3.1.2, 6.3.1.3.1, and 6.3.2.3.1. This parameter is ignored if thedataTypeis not None. In this case,nPCwm=0whendataTypeis set to"DCI"or"PBCH". For the"UCI"case, this value may be set to 0 or 1 which is determined based on the procedure explained in 3GPP TS 38.212, Sections 6.3.1.3.1 and 6.3.2.3.1.- iSeg:
Segmentation flag. This is a boolean value that indicates whether segmentation is enabled (True) or disabled (False). By default
iSeg=False. This is the value \(I_{seg}\) in 3GPP TS 38.212, Section 5.2.1. This parameter is ignored if thedataTypeis not None. In this case,iSeg=FalsewhendataType="DCI"ordataType="PBCH". WhendataType="UCI",iSegis set based on the value ofpayloadSize.- crcPoly:
The CRC polynomial. This is a string specifying the CRC polynomial or None. If specified, it must be one of the values specified in
getCrc()for thepolyparameter. The default value is"11". This parameter is ignored if thedataTypeis not None. In this casecrcPolyis set to"6"or"11"depending onpayloadSizefordataType="UCI", and"24C"fordataType="DCI"anddataType="PBCH"cases.
Other Properties:
- rateMatchedBlockLen:
The number of rate-matched bits transmitted for each code block when segmented. This is the same as
rateMatchedLenif segmentation is disabled. This is the value \(E_r\) in 3GPP TS 38.212, Section 5.5.- codeBlockSize:
The code block size. This is the value \(K\) in 3GPP TS 38.212, Section 5.3.1 which includes the CRC bits (if any).
- polarCodeSize:
The polar code size \(N\). This is always a power of 2.
- msgBits:
A list of indices of the message bits in the coded bitstream.
- frozenBits:
A list of indices of the frozen bits in the coded bitstream.
- pcBits:
A list of indices of the parity-check bits in the coded bitstream. This can be empty depending on
nPC.- generator:
The polar coding generator matrix as a 2-D NumPy array.
- print(indent=0, title=None, getStr=False)
Prints the properties of this
PolarEncoderobject.- Parameters:
indent (int) – The number of indentation characters.
title (str) – If specified, it is used as a title for the printed information.
getStr (Boolean) – If True, returns a text string instead of printing it.
- Returns:
If the
getStrparameter is True, then this function returns the information in a text string. Otherwise, nothing is returned.- Return type:
None or str
- doSegmentation(txBlock)
If segmentation is enabled, the first step in Polar encoding process is breaking down the transport block into smaller code blocks. This function receives a transport block
txBlock, performs segmentation depending on the value ofiSegproperty based on 3GPP TS 38.212, Section 5.2.1, and outputs a 2DC x KNumPy array containingCcode blocks of lengthK. Note thatCcan only be 1 or 2 and ifiSeg=False, thenC=1.- Parameters:
txBlock (NumPy array) – A NumPy array of bits containing the transport block information.
- Returns:
A 2D
C x KNumPy array containingCcode blocks of lengthK.- Return type:
NumPy array
- encode(codeBlocks)
This function encodes a set of code blocks and returns a set of Polar-coded code blocks based on the procedure explained in 3GPP TS 38.212, Section 5.3.1.
- Parameters:
codeBlocks (NumPy array) – A
C x KNumPy array containingCcode blocks of lengthKbeing Polar-encoded by this function.- Returns:
A
C x NNumPy array containing theCencoded code blocks.- Return type:
NumPy array
- rateMatch(codeBlocks)
This function receives a set of encoded code blocks and returns the rate-matched code blocks. It first performs Sub-block interleaving based on 3GPP TS 38.212, Section 5.4.1.1, then bit selection is done based on 3GPP TS 38.212, Section 5.4.1.2. Finally, if Coded bits Interleaving is enabled (
iBIL=True), this function applies the procedure in 3GPP TS 38.212, Section 5.4.1.3 for Coded bits Interleaving.- Parameters:
codeBlocks (NumPy array) – A
C x NNumPy array containingCencoded code blocks of lengthNbeing rate-matched by this function.- Returns:
A
C x ENumPy array containing theCrate-matched code blocks of lengthEwhereE=rateMatchedBlockLen.- Return type:
NumPy array
- class neoradium.polar.PolarDecoder(payloadSize=0, rateMatchedLen=0, dataType=None, **kwargs)
This class is used to decode a set of Log-Likelihood-Ratios (LLRs) to a transport block using the Successive Cancellation List (SCL) [2] algorithm. It is derived from the
PolarBaseclass and performs rate recovery and Polar decoding which are basically the opposite of the encoding tasks performed in reverse order.The following example shows a typical use case for decoding the received Polar-coded information into transport blocks:
An example of Polar decodingpayloadLen = 30 # A rateMatchedLen = 120 # E # Creating a polar decoder object for "DCI" data polarDecoder = PolarDecoder(payloadLen, rateMatchedLen, 'dci', sclListSize=8, useMinsum=True) # Rate recovery (Assuming "llrs" contains the LLR values from demodulation process) rateRecoveredRxBlocks = polarDecoder.recoverRate(llrs) # Polar Decoding using SCL algorithm decTxBlock, numCrcErrors = polarDecoder.decode(rateRecoveredRxBlocks)
- Parameters:
payloadSize (int) – The size of input bitstream not including the CRC bits. This is the value \(A\) in 3GPP TS 38.212, Section 5.2.1.
rateMatchedLen (int) – The total length of rate-matched output bitstream. This is the value \(E\) in 3GPP TS 38.212, Sections 5.3.1 and 5.4.1.
dataType (str or None) –
The type of data using this Polar decoder. It can be one of the following:
- ”DCI”:
Downlink Control Information
- ”UCI”:
Uplink Control Information
- ”PBCH”:
Physical broadcast channel
- None:
Customized Polar Coding.
kwargs (dict) –
A set of optional arguments depending on the
dataType:- iBIL:
Coded bits Interleaving flag. This is a boolean value that indicates whether coded bits interleaving is enabled (True) or disabled (False). By default
iBIL=False. This is the value \(I_{BIL}\) in 3GPP TS 38.212, Section 5.4.1.3. This parameter is ignored if thedataTypeis not None. In this case,iBILis set to True fordataType="UCI", and False fordataType="DCI"anddataType="PBCH"cases.- nMax:
Max value of \(n\) where \(N=2^n\) is the length of the polar code. By default this is set to 10 (which means \(N=1024\). This is the value \(N_{max}\) in 3GPP TS 38.212, Section 5.3.1.2. This parameter is ignored if the
dataTypeis not None. In this case,nMax=10whendataType="UCI", andnMax=9fordataType="DCI"anddataType="PBCH"cases.- iIL:
Input Interleaving flag. This is a boolean value that indicates whether input interleaving is enabled (True) or disabled (False). By default
iIL=False. This is the value \(I_{IL}\) in 3GPP TS 38.212, Section 5.3.1.1. This parameter is ignored if thedataTypeis not None. In this case,iILis set to False fordataType="UCI", and True fordataType="DCI"anddataType="PBCH"cases.- nPC:
Total number of parity-check bits. By default this is set to 0. This is the value \(N_{PC}\) in 3GPP TS 38.212, Section 5.3.1. This parameter is ignored if the
dataTypeis not None. In this case,nPC=0whendataTypeis set to"DCI"or"PBCH". For the"UCI"case, this value may be set to 0 or 3 which is determined based on the procedure explained in 3GPP TS 38.212, Section 5.3.1.2.- nPCwm:
The number of Low-weight, High-Reliability parity-check bits out of the total parity-check bits
nPC. By default this is set to 0. This is the value \(n_{PC}^{wm}\) in 3GPP TS 38.212, Sections 5.3.1.2, 6.3.1.3.1, and 6.3.2.3.1. This parameter is ignored if thedataTypeis not None. In this case,nPCwm=0whendataTypeis set to"DCI"or"PBCH". For the"UCI"case, this value may be set to 0 or 1 which is determined based on the procedure explained in 3GPP TS 38.212, Sections 6.3.1.3.1 and 6.3.2.3.1.- iSeg:
Segmentation flag. This is a boolean value that indicates whether segmentation is enabled (True) or disabled (False). By default
iSeg=False. This is the value \(I_{seg}\) in 3GPP TS 38.212, Section 5.2.1. This parameter is ignored if thedataTypeis not None. In this case,iSeg=FalsewhendataType="DCI"ordataType="PBCH". WhendataType="UCI",iSegis set based on the value ofpayloadSize.- crcPoly:
The CRC polynomial. This is a string specifying the CRC polynomial or None. If specified, it must be one of the values specified in
getCrc()for thepolyparameter. The default value is"11". This parameter is ignored if thedataTypeis not None. In this casecrcPolyis set to"6"or"11"depending onpayloadSizefordataType="UCI", and"24C"fordataType="DCI"anddataType="PBCH"cases.- sclListSize:
The list size of the Successive Cancellation List (SCL) algorithm used for decoding. The default is 8.
- useMinsum:
A Boolean value indicating whether the Min-Sum approximation should be used in the SCL algorithm. True (default) means the “Min-Sum” approximation is used resulting in faster decoding with slightly less precise results. False means the actual extrinsic likelihood function based on hyperbolic tangent function is used.
Note
For a pair of
PolarEncoder/PolarDecoderobjects to work properly, the above parameters used to configure them should match.Please refer to
PolarBaseclass for a list of properties inherited from the base class.- print(indent=0, title=None, getStr=False)
Prints the properties of this
PolarDecoderobject.- Parameters:
indent (int) – The number of indentation characters.
title (str) – If specified, it is used as a title for the printed information.
getStr (Boolean) – If True, returns a text string instead of printing it.
- Returns:
If the
getStrparameter is True, then this function returns the information in a text string. Otherwise, nothing is returned.- Return type:
None or str
- recoverRate(rxBlock)
This function receives an array of Log-Likelihood Ratios (LLRs) in
rxBlockand returns a set of rate-recovered LLRs for each code block which are ready for Polar decoding. This function does the exact opposite of thePolarEncoder’srateMatch()method. Note that while therateMatch()works with bits, this method works on LLRs which are usually obtained by performing demodulation process.- Parameters:
rxBlock (NumPy array) – A NumPy array of Log-Likelihood Ratios (LLRs) obtained as a result of demodulation process. Each element is a real LLR value corresponding to a each received bit. The larger the LLR value, the more likely it is for that bit to be a
0.- Returns:
A
C x NNumPy array ofCreceived coded blocks of lengthNcontaining the LLR values for each coded block ready to be polar-decoded.- Return type:
NumPy array
- decode(rxLlrBlocks)
This function implements the Successive Cancellation List (SCL) algorithm for Polar-decoding of LLRs into decoded transport blocks. This implementation was inspired mostly by LDPC and Polar Codes in 5G Standard set of videos and was written from scratch using a recursive algorithm to efficiently perform the SCL decoding process.
- Parameters:
rxLlrBlocks (NumPy array) – A
C x NNumPy array ofCreceived coded blocks of lengthNcontaining the LLR values for each coded block.- Returns:
txBlock (NumPy array of bits) – A 1D NumPy array of length \(A\) containing the decoded transport block bits where \(A\) is equal to the parameter
payloadSize.numCrcErrors (int) – The total number of CRC errors if
crcPolyis not None, otherwise, zero.
References: