# Design of Encoding Algorithm for Underwater Wireless Optical Communication Based on Spinal Code
## 3 Superposition UEP-Spinal Code Algorithm Encoding Principle  
This paper proposes an innovative superimposed Spinal code structure aimed at enhancing the protection of header information in Spinal codes through an unequal error protection mechanism. Given that certain parts of data in a file are more critical than others during data transmission--for instance, in MPEG video streams, I-frames, as key frames, are far more important than P-frames and thus require stricter protection--we have designed an encoding scheme with UEP characteristics. Assume that the \(k\) source blocks of the file to be transmitted are divided into \(r\) distinct subsets, namely \(S_{1}\), \(S_{2}\),..., \(S_{r}\), and the sum of these subsets satisfies the following condition: \(\mid S_{1}\mid+\mid S_{2}\mid+\mid S_{r}\mid=k\). Suppose that for any \(i<j\), the data blocks in the \(i\)-th subset are of higher importance than those in the \(j\)-th subset. In this paper, we assume \(r=2\), meaning the source blocks are divided into two main categories: one subset containing more important blocks (MIBs) and another containing relatively less important blocks (LIBs). Assume that the first \(k\) source blocks belong to MIBs, while the remaining \(k^{\prime}\) (where \(1<k^{\prime}<k\)) source blocks fall into LIBs. When using an encoding scheme with UEP properties, even if errors occur during data transmission, the data blocks in MIBs will be successfully decoded before those in LIBs. This design ensures priority protection for critical data during transmission, significantly improving data transmission reliability and efficiency. Figure 1: Spinal code encoder. For the more important data, additional error-checking codes are generated, while the encoding structure for less important parts is simplified. The tail code decoding in this scheme has fewer layers and a simpler structure compared to traditional Spinal codes, enhancing accuracy. Compared to Spinal codes with the same bandwidth utilization, the proposed scheme improves the reliability of signal transmission in low-SNR conditions by focusing on MIB. The encoding process of the Superposition UEP-Spinal Code is illustrated in Figure 2 and consists of four steps:  
Step 1: Divide the original data to be encoded into two parts. The initial portion of the data (header code) is classified as MIBs, while the remaining data (tail code) are classified as LIBs. In the Superposition UEP-Spinal encoding algorithm, the division of MIBs and LIBs can be adjusted according to the requirements of the transmission task. Then, during the subsequent block partitioning process, the encoding algorithm divides both MIBs and LIBs into non-overlapping blocks of size \(d\). If the length of the last block is insufficient to reach \(d\), padding data will be added to meet the length requirement, ensuring that all blocks are of equal size for easier subsequent processing and transmission. Denote MIBs as \(m_{m}\) and LIBs as \(m_{l}\). Step 2: The encoder first uniformly divides \(m_{m}\) into \(d\) non-overlapping blocks, with each block containing \(k_{1}\) bits, i.e., \(\left(m_{1}^{m},m_{2}^{m},\ldots,m_{d}^{m}\right)\). These blocks \(\left(m_{1}^{m},m_{2}^{m},\ldots,m_{d}^{m}\right)\) are then fed into a Spinal encoder with an initial hash state \(s_{0}^{m}\), following the following equation:  
\[s_{i}^{m}=h^{m}(s_{i-1}^{m},m_{i}^{m}),1\leq i\leq d \tag{6}\]  
Sequentially generating \(d\) new hash states of length \(v\), \(s_{i}^{m}\) refers to the hash state of length \(v\) generated by the \(i\)-th MIB information block. Step 3: The encoder uniformly divides \(m_{l}\) into \(d\) non-overlapping blocks, with each block containing \(k_{2}\) bits. The hash state values generated from \(m_{m}\) are error-correction-encoded to produce \(k_{3}\)-bit parity bits \(m_{c}\).