# Compression of Multibeam Echosounders Bathymetry and Water Column Data
## 4 FAPEC Tailoring for the KMALL Data Format
### MRZ Pre-Processing Stage  
The second algorithm we propose is focused on MRZ datagrams, the most used ones in oceanographic research and industry, yet no tailored compression algorithms have been developed so far.  
Following the same procedure as in the previous section, the first step is to identify the larger subdatagrams. Assuming a maximum size datagram of 366.456 kB, sounding subdatagrams can take up to 245.760 kB, and seabed imaging up to 120 kB (see Figure 4). That is, in maximum size MRZ datagrams, sounding and seabed imaging subdatagrams occupy 99.8% of the total size. Hence, we only focus on these two subdatagrams while the others are directly sent to the entropy coder, as we did in MWC compression. Note that in the worst case (just one sounding and no seabed imaging) it still represents 74% of the total size.  
Figure 7: Raw representation of MWC phase data from an EM2040 echosounder.  
The algorithm we propose exploits the periodicity of the sounding subdatagrams. Each sounding subdatagram contains several numerical fields (different types of integers and floats, see [13]), but the same field is located every 120 bytes, as these subdatagrams have a fixed length. For simplicity, efficiency and speed, we process each subdatagram as 16-bit samples with an interleaving step of \(I=60\). Then, our approach consists in computing the prediction errors by subtracting the previous subdatagram from the current one. Furthermore, we reorder the prediction errors in such a way that the same fields from all subdatagrams are placed together. Reordering ensures that long sequences of the same data type are sent to the entropy coder, which improves the performance. Formally, given \(N_{Sd}\) soundings with \(I\) 16-bit samples \(S_{i,j}\),  
\[E_{i+j\cdot N_{Sd}}=S_{i,j}-S_{i-1,j},\quad 1\leq i<N_{Sd},\quad 0\leq j<I. \tag{11}\]  
Note that the first sounding \(i=0\) is directly copied to the prediction errors sequence:  
\[E_{j\cdot N_{Sd}}=S_{0,j},\quad 0\leq j<I. \tag{12}\]  
Before continuing, we briefly explain why using 16-bit samples and reordering the prediction errors improves the performance of the entropy coder. FAPEC supports sample sizes from 4 to 28 bits. In order to keep the synchronism, we must choose a value that is a multiple of 8 bits. Moreover, due to the presence of float numbers, the chosen sample size must be a divisor of 32. Hence, the only possible choices are 8 bits or 16 bits. Finally, 16 bits are preferred because, for a given sample rate, these maximize the bit rate at the compressor output. Note that using 16 bits means splitting floats into two parts: the first one (sign, exponent and 7 bits of mantissa) not changing much between soundings [17] and the second one being mostly noise as the resolution of an echosounder is below that of floating point numbers. With this approach, FAPEC will be able to efficiently compress half of the floats (and most of the integer values), whereas the other half will be barely compressed.  
The importance of reordering samples is related to the data blocks used by the FAPEC core (see Section 3 or [14]). The order inside a block is relevant for run-length encoding. Furthermore, if similar samples fall in different blocks, then the block entropy will be higher, and hence, the performance will be lower.  
Finally, seabed imaging samples are predicted from the previous sample:  
\[E_{i}=S_{i}-S_{i-1},\quad 0\leq i<N_{Sb} \tag{13}\]  
where \(N_{Sb}\) is obtained by summing all the _S1 numSamples_ fields in the sounding datagrams.  
The same approach followed in this section could be applied to other cases, namely, just identifying the header or metadata indicating the type of data structure, and then applying a simple delta decorrelator (with the adequate symbol size and interleaving values) followed by an entropy coder.