## 5 QC-RL-LDPC Encoding  
The encoding of QC-RL-LDPC codes, as shown in Figure 4, always involves the HR part and then as many chunks in the IR part as are required to efficiently decode the message in the receiver.  
The encoding of the HR part, that is, determining \(\mathbf{p}_{\mathrm{HR}}\), can be performed with one of the known efficient LDPC encoding algorithms, utilizing the QC feature. In [36], we presented a CPU-based QC-LDPC encoder implementation, which can also be used as an HR part encoder implementation in the QC-RL-LDPC system presented in this article. If this implementation is used, for the sake of code construction, it is important to note that the parity check matrix \(\mathbf{H}_{\mathrm{HR}}\), in addition to being in QC form, should follow the ALT (almost lower-triangular) form, as in the Richardson-Urbanke encoding [14], that is,  
\[\mathbf{H}_{\mathrm{HR}}=\begin{bmatrix}\mathbf{A}&\mathbf{B}&\mathbf{T}\\ \mathbf{C}&\mathbf{D}&\mathbf{E}\end{bmatrix} \tag{5}\]where **T** is a lower-triangular matrix and all submatrices are CPMs. Cyclic changes in CPMs should preferably be selected so that \(\mathbf{\Phi}=\textbf{ET}^{-1}\textbf{B}+\textbf{D}\) is an identity matrix, \(\mathbf{\Phi}=\textbf{I}_{g\times g}\), which can be achieved by fulfilling a condition originally proposed in [37]. As a result of the encoding of the HR information vector **u**, the code vector \(\textbf{c}=[\textbf{u},\textbf{p}_{\text{HR}}]\) is obtained. The Details of the encoding algorithm for QC-LDPC and its microcontroller implementation can be found in [14; 36; 37].  
The IR encoding is based on the \(\textbf{H}_{\text{IR}}\) parity check matrix, which can be expressed as follows:  
\[\textbf{H}_{\text{IR}}=\begin{bmatrix}\textbf{H}_{1}\\ \textbf{H}_{2}\\ \vdots\\ \textbf{H}_{L}\end{bmatrix},\hskip 28.452756 pt\textbf{H}_{l}=\begin{bmatrix} \textbf{P}^{s_{R}+l_{1}},\textbf{P}^{s_{R}+l_{2}},\ldots,\textbf{P}^{s_{R}+l _{C}}\end{bmatrix},\hskip 10.0 ptl=1,2,\ldots,L \tag{6}\]  
where each macrorow \(\textbf{H}_{l}\) defines the parity checks (7) in GF(2) arithmetic for the \(l\)th chunk of incremental redundancy, \(\textbf{p}_{\text{IR}l}\).  
\[\textbf{H}_{l}\cdot\textbf{c}^{\text{T}}+\textbf{P}_{IR_{l}}=\mathbf{0} \tag{7}\]  
The consecutive chunks for \(l=1,2,\ldots,L\) can be computed as in the following expression:  
\[\textbf{P}_{IR_{l}}=\textbf{H}_{l}\cdot\textbf{c}^{\text{T}}=\textbf{P}^{s_{R +l_{1}}}\textbf{c}_{1}^{\text{T}}+\textbf{P}^{s_{R}+l_{2}}\textbf{c}_{2}^{ \text{T}}+\ldots+\textbf{P}^{s_{R}+l_{C}}\textbf{c}_{C}^{\text{T}} \tag{8}\]  
Every chunk calculation as in (8) requires elementary operations of the type \(\textbf{P}^{s_{R}+l_{i}}\textbf{c}_{j}^{\text{T}}\), as well as additions over GF(2), where every \(\textbf{P}^{s_{R}+l_{j}}\) is either:  
* a zero matrix, in which case the product \(\textbf{P}^{s_{R}+l_{j}}\textbf{c}_{j}^{\text{T}}\) is **0**;
* or a circular shift of an identity matrix by \(s_{R+l_{j}}\) positions, in which case it can be easily verified that the product \(\textbf{P}^{s_{R}+l_{i}}\textbf{c}_{j}^{\text{T}}\) is a circular shift of \(\textbf{c}_{j}^{\text{T}}\) by \(s_{R+l,j}\) positions.  
Therefore, computing (8) for the QC case requires elementary operations of circular shifts of binary length-\(P\) subvectors in \(\textbf{c}^{\text{T}}\), as well as modulo-2 additions of length-\(P\) subvectors. Implementation in the microcontroller can be developed in C language, in which modulo-2 additions are realized with an \"/\" operator, and the circular shifts can be realized by using a bitwise shift operation and a bitwise OR operation, as in the following example:  
output = (input << offset) | (input >> (size - offset));  
where offset is the cyclic shift value and size is equivalent to the submatrix size \(P\). Using this instruction for the circular shift, the input value can be represented in uint32_t type (if \(P\leq 32\)), while the size and offset can be represented in any unsigned type, for example, uint8_t. The output value is in the same format as the input.