# Application of Dynamic Time Warping to Determine the Shear Wave Velocity from the Down-Hole Test
## 4 Methodology  
### dtw  
Dynamic Time Warping (DTW) is a well-known method of assessing the similarity between two signals or time series. DTW, in contrast to the simple Euclidean distance measure, is resistant to signal shifts in time and their stretching or shortening. It gives the opportunity to compare each pair of values of both signals in order to find the best match with respect to the smallest distance [11]. Assuming two signals, A of length n and B of length m are given as  
\[\mathrm{A}=(\mathrm{a}_{1},\mathrm{a}_{2},\ldots,\mathrm{a}_{\mathrm{n}}), \tag{9}\]  
\[\mathrm{B}=(\mathrm{b}_{1},\mathrm{b}_{2},\ldots,\mathrm{b}_{\mathrm{m}}), \tag{10}\]  
it is possible to compare each value of \(\mathrm{a}_{\mathrm{i}}\) with \(\mathrm{b}_{\mathrm{j}}\) using a chosen distance function, for example,  
\[\delta(\mathrm{i},\mathrm{j})=|\mathrm{a}_{\mathrm{i}}-\mathrm{b}_{\mathrm{j }}|. \tag{11}\]  
The results of the above function can be presented in the form of a two-dimensional n-by-m matrix. An example of such a comparison of two signals is shown in Figure 3, where the distance values are marked against a color scale. The task of DTW is to indicate the so-called warping path (W), i.e., a sequence of points, so as to minimize the distance between the A and B values. It can be defined as  
\[\mathrm{W}=(\mathrm{w}_{1},\mathrm{w}_{2},\ldots,\mathrm{w}_{\mathrm{K}}), \tag{12}\]  
where \(\mathrm{w}_{\mathrm{k}}\) corresponds to the point \((\mathrm{i},\mathrm{j})_{\mathrm{k}}\). The optimal warping path is the one for which the sum of the distances between the values along the path is the smallest. It is also the best match between the A and B signals. Thus, the DTW measure can be defined as follows [11]:  
\[\mathrm{DTW}(\mathrm{A},\mathrm{B})=\min_{\mathrm{W}}\Bigl{\{}\sum_{k=1}^{ \mathrm{P}}\delta(\mathrm{w}_{\mathrm{k}})\Bigr{\}}. \tag{13}\]  
In Figure 3, the optimal warping path is marked with a red line. The Dynamic Time Warping (DTW) method is widely used in various fields, particularly in situations where it is necessary to compare signals of varying lengths that may contain the shifting, stretching, or shortening of individual fragments. A particularly relevant topic is the recognition of patterns or motifs in signals [12]. The first instance in which the DTW algorithm was used was for the recognition of human speech [13; 14; 15; 16]. Speech recognition requires finding patterns of individual words in a sound record, which can be uttered at different speeds by different people, which the DTW method is resistant to. This topic is still being developed, and more and more accurate methods using DTW in combination with other techniques are being developed. DTW  
Figure 3: An example of visualizing the result of the DTW algorithm for A and B signals marked with blue curves. The red curve is the optimal warping path. has been combined with Mel-Frequency Cepstral Coefficients (MFCC) in several studies, including [17; 18], to effectively recognize patterns in human speech signals. In [19], a solution is proposed that combines DTW with a Support Vector Machine, while in [20; 21], DTW is combined with a Hidden Markov Model. In addition to recognizing human speech, it is also possible to apply DTW to recognize environmental sounds [22], such as bird calls [23]. Some other applications of DTW for pattern recognition include the recognition of gestures from inertial data [24; 25; 26], sign language [27], human movement from movies [28; 29; 30], as well as applications in medicine, such as the classification of heart sounds [31; 32] or ECG arrhythmias [33; 34]. In the case of machines, DTW can be used in the context of diagnostics of, for example, motor drives [35] or location from inertial data [36], as well as data reduction generated in autonomous driving systems [37]. The DTW method can also be extended to more dimensions. Two methods, dependent and independent ones, are used for this, which give different results, and the choice is not obvious [38].