# Application of Dynamic Time Warping (DTW) in Comparing MRT Signals of Steel Ropes
## 2 Materials and Methods
### Algorithm DTW
DTW is a semi-metric that has the basic properties of metrics:  
* \(\forall x,x^{{}^{\prime}},DTW_{q}\Big{(}x,x^{{}^{\prime}}\Big{)}\geq 0\);
* \(\forall x,DTW_{q}\Big{(}x,x^{{}^{\prime}}\Big{)}=0\). DTW, however, does not satisfy the triangular inequality and identities of the indistinguishable, but is invariant for time changes and time shifts regardless of their time span. During the time-series analysis, additional constraints can be imposed on the set of allowable paths in order to obtain invariance for only local deformations in a given analysis window and to limit the analyzed set of time deformations, which speeds up the calculation. Such restrictions, e.g., in the form of the Sakoe-Chiba band or the Itakura parallelogram, translate into the enforcement of non-zero entries in the \(A_{\pi}\) to stay close to the diagonal [53; 54]. Time series comparison via DTW involves several key steps:  
Figure 11: Comparison of clustering results using different distance measures: (**a**) clustering based on Dynamic Time Warping (DTW) k-means, which accounts for nonlinear time distortions in the alignment of time series; (**b**) clustering using Euclidean k-means, which performs rigid, point-to-point comparisons. Each subfigure shows time series grouped into a cluster and their centroid (in orange) [66]. Figure 10: Comparison between Euclidean distance and Dynamic Time Warping (DTW) [66]. * Detrending and z-score normalization of the time series--a preprocessing step that addresses DTW's sensitivity to trend differences. Detrending removes any increasing or decreasing trends in the time series, while z-score normalization scales the values to a mean of zero and a standard deviation of one. * Computation of the distance matrix between all pairs of samples--the matrix contains pairwise distances between all combinations of samples in the two time series. Although Euclidean distance works well in many cases, other metrics may be more appropriate, depending on the data. * Computation of a cost matrix from the distance matrix--the cost matrix is derived from the distance matrix by recursively accumulating distances from neighbor to neighbor, starting from the initial corner (bottom left) to the final corner (top right). Different neighborhood rules define how these costs are propagated, e.g.,
* Orthogonal only: accumulation occurs in x and y directions only, ignoring diagonals. * Orthogonal and diagonal moves: diagonal movements are also considered, typically weighted by a factor of \(\sqrt{2}\) (1.414) to balance with orthogonal steps. The value of each cell in the matrix represents the slope or effort required to pass through it. * Finding the least-cost path within the cost matrix is the step where time warping occurs. The least-cost path minimizes the total cost from start to end of the cost matrix, optimally aligning the two time series. * Computation of a similarity metric based on the least-cost path--the simplest approach is to sum the distances of all points along the path. When comparing time series of different lengths, additional normalization is performed. Typical options include the following: (a) Sum of lengths: normalize by the combined length of both time series; (b) automatic distance summation: normalize by the sum of distances between neighboring samples in each series. Normalized metrics enable comparisons across datasets with varying characteristics.