# Low-Cost Underwater Communication System: A Pilot Study
## 2 System Design
### Binary Phase Shift Keying (De)Modulator  
The implementation of a cheap and simple modem for underwater communication began with BPSK modulation. It is the simplest form of phase modulation, in which the phase of the carrier signal can take two values shifted from each other by \(\pi\). \[x(t)=A\cos{(2\pi f_{c}t+\phi(s))}, \tag{1}\]  
where \(f_{c}\) is a carrier frequency, and phase \(\phi(s)=\{0,\pi\}\) depends on the current symbol value \(s=\{0,1\}\). In practice it is equivalent to  
\[x_{0}(t) = A\cos{(2\pi f_{c}t)},\] \[x_{1}(t) = -A\cos{(2\pi f_{c}t)}. \tag{2}\]  
Carrier frequency \(f_{c}\) for the system is determined by the resonant frequency of the ultrasound transducer. It allows for efficient transmission of the modulated waveform through the transducer. In the case of using a piezoelectric transducer, a cosine waveform can be easily replaced by the square waveform because together with some additional passive elements it can form a band-pass filter. The band-pass filter is necessary to suppress the higher order harmonic frequencies appearing in a square waveform spectrum. The implementation of such modulation in software is extremely simple if the hardware timer is used, which is embedded in each microcontroller. The timer should be programmed to generate a square waveform on the output pin with frequency equal to \(f_{c}\). Additionally, the counter should be configured to count the period of a symbol. After reaching the period, an interrupt is raised, so in the interrupt handling function, one can change the polarity of the output pin without touching any other register of the hardware timer. Consequently, all these steps can be executed in real time as necessary to implement the modulation procedure. The demodulation procedure is much more complicated and time consuming. The analog-to-digital converter (ADC) embedded in the microcontroller has to be used. Thanks to the use of the direct memory access (DMA) subsystem, each sample taken by ADC is placed in a memory buffer. Each time the buffer is full, an interrupt is raised, and its handling function transfers the buffer content to a demodulation thread. The demodulation of the BPSK signal needs to calculate the so-called in-phase (\(I\)) and quadrature (\(Q\)) components:  
\[I(t)=r(t)*\cos{(2\pi f_{c}t)}, \tag{3}\]  
\[Q(t)=r(t)*\sin{(2\pi f_{c}t)}, \tag{4}\]  
where \(r(t)\) is a signal received by the piezoelectric transducer. \(I\) and \(Q\) signals can be treated as traditional complex numbers, where the \(I\) component is a real part and the \(Q\) component is an imaginary part of a number. Therefore, the term IQ signal means a set of samples composed of \(I\)/real and \(Q\)/imaginary parts. This signal is amplified, filtered, and finally directed to the ADC. The forming of the IQ signal is executed in the discrete domain, i.e., an ADC's output discrete signal is multiplied by the cosine and sine functions and then low-pass filtered. The demodulation thread calculates the IQ signal in the discrete domain. The values of the sine and cosine functions are tabulated prior to multiplication to speed up the calculation. Next, a low-pass filter is applied in both channels (i.e., \(I\) and \(Q\)) and the integral over a period of a symbol is calculated. Finally, a decision about a symbol value is calculated. In the case of BPSK, only two possibilities exist, which are relatively easy to discriminate. One can see that this BPSK demodulation procedure works without synchronizing the sine/cosine function with the received carrier frequency. The choice of noncoherent demodulation is based on experiments. Phase locked loop (PLL) is considered. However, the real-time implementation in software is impossible. Simultaneously, the chosen Cortex M4 microcontroller does not have any PLL hardware block. Thus, an assumption is made that each transferred frame contains a priori known sync bits. These bits are used for detection of the start of the frame, as well as a training sequence.