## 3 Simulation of Underwater Electric Field Communication
### CSMA/CA Channel Backoff Algorithm Design and Simulation Analysis
#### 4.2.4 Channel Detection  
Before applying the CSMA /CA-based protocol to the electronic communication system, there was another key issue that needed to be addressed--channel state detection. The flowchart of the channel detection algorithm is shown in Algorithm 3. The channel detection algorithm was mainly designed based on the Raspberry Pi serial port. Firstly, the serial library function ser. read (ser. inwaiting(0)) is used to read all the real-time data from the Raspberry Pi serial port, which is the received data of the underwater current field communication. The Python-specific string library function data_rev.find() is used for string recognition, to detect the frame header of the data packet. When the frame header is detected, it indicates that the underwater channel is occupied, and the channel detection flag is set to 1. Then, combined with the data packet composition in the previous section, the position of the frame header is detected first by the function Data_rev.index(), and then it is determined whether the next byte after the frame header in the data packet is the target address of the local ID. If they are the same, the three-dimensional position coordinates in the data packet are extracted. Otherwise, the next round of loop detection is performed. ```
\(\textbf{\emph{Sub}}_{\textbf{\emph{PWM}}}\textbf{\emph{handware}}\)(18, 12000, 0) \(\textbf{\emph{Data\_buf}}=0\) \(\textbf{\emph{while}}\)(1) \(\textbf{\emph{Delay}}(t)\) endif endif \(\textbf{\emph{Set\_PWM}}\textbf{\emph{handware}}\)(18, 12000, 50000) endif else \(\textbf{\emph{Lart\_rc}}\textbf{\emph{flag}}=0\) endif endif \(\textbf{\emph{Set\_PWM}}\textbf{\emph{handware}}\)(18, 12000, 50000) endif endwhile
```  
**Algorithm 2**_Cont_. #### 4.2.4 Channel Detection  
Before applying the CSMA /CA-based protocol to the electronic communication system, there was another key issue that needed to be addressed--channel state detection. The flowchart of the channel detection algorithm is shown in Algorithm 3. The channel detection algorithm was mainly designed based on the Raspberry Pi serial port. Firstly, the serial library function ser. read (ser. inwaiting(0)) is used to read all the real-time data from the Raspberry Pi serial port, which is the received data of the underwater current field communication. The Python-specific string library function data_rev.find() is used for string recognition, to detect the frame header of the data packet. When the frame header is detected, it indicates that the underwater channel is occupied, and the channel detection flag is set to 1. Then, combined with the data packet composition in the previous section, the position of the frame header is detected first by the function Data_rev.index(), and then it is determined whether the next byte after the frame header in the data packet is the target address of the local ID. If they are the same, the three-dimensional position coordinates in the data packet are extracted. Otherwise, the next round of loop detection is performed. ```


Underwater Electric Field Dynamic Multi-Node Communication System Water Tank Experiment Verification

#### 4.3.1 Experimental Validation of Underwater Electric Field Mobile Communication Based on AUV

In this article, a 2 FSK underwater electric field communication system was built and integrated into an AUV for multi-node underwater electric field experimental testing [35; 36]. The underwater electric field physical communication system based on 2 FSK includes the Raspberry Pi main control board, FPGA digital communication system, and 2 FSK peripheral analog circuit, as shown in Figure 11. Raspberry Pi interacts with FPGA digital communication system through the UART interface, and FPGA uses digital-to-analog conversion to output 2 FSK modulated waves to the 2 FSK analog circuit. The 2 FSK analog circuit transmits the underwater-received electric field communication signal to FPGA for processing through the ADC driver.