# MeLa: A Programming Language for a New Multidisciplinary Oceanographic Float
## 4 Experiments
### Detection of Blue Whales
#### 4.2.2 The Blue Whale Detection Algorithm  
Blue whales emit different sounds, called A, B, C, and D calls, which are involved in their social behaviors [26]. We have developed an algorithm that detects the occurrence of D-calls and records the occurrence dates. The spectrogram of D-calls has a very specific shape. This is a narrow band signal that sweeps typically from 80 to 20 Hz, as shown in Figure 9. The algorithm detects this shape in real time. First, the algorithm computes the spectrum \(S\) of the signal with a Fourier transform of 64 samples and a window overlap of 50% (32 samples). After removing noise at low frequencies, below 20 Hz, the algorithm searches for the six highest values of the spectrum and computes a ratio between the two highest over the fifth and sixth highest \((max1(S)+max2(S))/(max5(S)+max6(S))\). This is done for successive time windows resulting in the curve that is shown in Figure 10. The computed ratio is only high when a signal with a narrow frequency band exists. However, the ratio is not always very stable, especially if the signal is weak. Therefore, we compute the STA/LTA average that smoothes the curve, as shown in Figure 11. If the value of the STA/LTA exceeds a trigger value, then the ratio is put inside a buffer to be used in the next step of the algorithm. The frequency at which is found the maximum amplitude of the spectra (Figure 12) is also kept in memory.  
Figure 10: Ratio of spectrum amplitudes for each spectrogram window.  
Figure 9: Spectrogram of a blue whale D-call with low frequencies removed.  
After the value of the STA/LTA drops under the trigger threshold, the two curves are used to discriminate D-calls from other noises. Only the part of the curves between the trigger and detrigger (green highlight) are in memory at this time. In order to remove potentially wrong values at the end or at the beginning of the curve, the time window is truncated. We use the frequency curve on Figure 12 and only select the part between the maximum and minimum value (first minimum), as shown with the two dashed red lines. Subsequently, we count the number of times the frequency changes downward, upward, or keeps the same value (the frequency can only take 32 values corresponding to the frequency bins of the Fourier transform). For the highlighted part of the Figure 12, the frequency goes downward three times and keep the same values five times. Finally, several checks are done in order to validate that the signal corresponds to a blue whale D-call and, if these are all valid, the date of the detection is recorded. The checks have been defined empirically and are the following:  
* The length of the detection must be above 4 successive windows (yellow part of Figure 11).
* The mean value of the ratio must be above 2.5.
* The number of times the frequency goes downward between two successive windows must be more than 3 times the number of times the frequency goes upward.
* The number of times the frequency goes downward must be more than 2.
* The number of times the frequency goes downward must be more than 0.25 times the number of times the frequency stays stable.
* The maximum frequency must be above 40 Hz.
* The maximum frequency must not change by more than 20 Hz between within two points (0.8 s).  
The algorithm could be improved by keeping values before the trigger that is a little late when compared to the D-call arrival. Moreover, the discrimination process could be optimized  
Figure 11: Short Term Average over Long Term Average (STA/LTA) computed from the ratio Figure 10.  
Figure 12: Frequencies corresponding to the maximum amplitudes of the spectrogram.  
with machine learning and input, such as the features listed above or the ratio (Figure 10) and frequency curves (Figure 12).