# Real-Time Method and Implementation of Head-Wave Extraction for Ultrasonic Imaging While Drilling
## 2 Digital Extraction Method of Echo Head Waves  
The improved energy ratio head-wave arrival extraction algorithm is based on the \(STA/LTA\) method. The \(STA/LTA\) method focuses on the time-domain characteristics of waveform recordings to detect the head wave using two types of information--the amplitude (energy) difference between the noise and echo signals and the notable change in signal energy before and after the arrival of the head wave. The expression of this method is shown in Equation (1), where \(R(n)\) is the average ratio of \(STA/LTA\) at the sample point \(n\), \(LTAn\) and \(STAn\) are the average energies of long and short windows, respectively, \(NS\) and \(NL\) are the number of samples contained in short and long windows, respectively, \(i\) is the sample point number and \(x(i)\) represents the discrete waveform record. \(STAn\) quickly responds to waveform amplitude changes, unlike \(LTAn\), whose response is much slower. Thus, the energy ratio \(STAn/LTAn\) can represent waveform amplitude changes.  
\[R(n)=\frac{STA_{n}}{LTA_{n}}=\left(\frac{1}{N_{S}}{\sum_{i=n-N_{S}+1}^{i=n}x(i )^{2}}\right)\Big{/}\left(\frac{1}{N_{L}}{\sum_{i=n-N_{L}+1}^{i=n}x(i)^{2}} \right) \tag{1}\]  
In actual processing, \(R(n)\) is calculated by sliding the time window on the waveform record. When \(R(n)\) is greater than the preset threshold \(\alpha\), the echo signal is considered to have already arrived. However, in cases of echo signals with a poor SNR, setting \(\alpha\) too low may result in false detection, whereas the opposite (setting \(\alpha\) too high) may result in head waves being missed. The anti-noise performance of the algorithm can be improved by replacing the energy function with the characteristic function and introducing the weighted coefficient to calculate the mean ratio of both long and short windows [27].  
According to the characteristics of FPGA, an improved long-short window energy ratio function \(Z(n)\) was defined (Equation (2)), which effectively combines the characteristic function method and the weighting coefficient method. The expression of \(CF(i)\) is shown in Equation (3).  
\[Z(n)=\frac{\left(\frac{1}{N_{S}}{\sum_{i=n-N_{S}+1}^{i=n}CF(i)}\right)^{2}}{ \left(\frac{1}{N_{L}}{\sum_{i=n-N_{L}+1}^{i=n}CF(i)}\right)^{2}} \tag{2}\]  
\[CF(i)=x(i)^{2}-x(i-1)\cdot x(i+1) \tag{3}\]  
Figure 1 demonstrates the effect of using either the \(STA/LTA\) method or the improved \(STA/LTA\) method to process a low-SNR UILWD echo signal. It can be seen that the response of the improved \(STA/LTA\) method to the reflected echo is greatly improved. Meanwhile, the response to the noise signal remains basically unchanged, thereby providing a broader threshold setting range for the algorithm while greatly improving its anti-noise ability.  
In the peak-to-peak amplitude detection method, the amplitude is equal to the maximum peak of the echo signal minus the maximum trough value. The expression is shown in Equation (4), where \(Amp\) is the amplitude value and \(x(i)\) is the discrete waveform record.  
\[Amp=x(i)_{\max}-x(i)_{\min} \tag{4}\]