# Application of Dynamic Time Warping (DTW) in Comparing MRT Signals of Steel Ropes
## 2 Materials and Methods
### Algorithm DTW
Theoretical foundations along with a mathematical description of DTW and sample codes are included in blogs [66; 67]. The DTW algorithm relies on the time alignment of the series to assess their similarity. All objects in the time series \(x=(x_{0},\ x_{1},\ldots,x_{n})\) are in the same space \(\mathbb{R}^{p}\). Two time series will be analyzed for the MRT study, \(x=LF_{ref}(k)\) and \(x^{{}^{\prime}}=LF_{b}(k)\), of appropriate lengths \(n\) and \(m\), which are a subset of the recorded measurement data from the rope test. It is assumed that all elements of the time series \(x\) and \(x^{{}^{\prime}}\) lie in the same p-dimensional space, while the exact timestamps in which the observations occur are ignored--only their order matters. The optimization problem is described by the formula in Equation (25). \[DTW_{q}\Big{(}x,x^{{}^{\prime}}\Big{)}=\min_{\pi\in A(x,x^{{}^{\prime}})} \left(\sum_{(i,j\in\pi)}d\Big{(}x_{i},x^{{}^{\prime}}_{j}\Big{)}^{q}\right)^ {1/q} \tag{25}\]  
where  
* \(\pi\) is an alignment path of length \(K\), which is a sequence of pairs of indices \(K((i_{0},j_{0}),\ldots,(i_{K-1},j_{K-1}))\);
* \(A\Big{(}x,x^{{}^{\prime}}\Big{)}\) is the set of all acceptable paths. For a route to be considered acceptable, it should meet the following conditions. The beginning (or end) of the time series is matched to each other:
* \(\pi_{0}=(0,0)\);
* \(\pi_{K-1}=(n-1,m-1)\). The sequence monotonically builds up in both \(i\) as well as \(j\), and all time-series indexes should appear at least once, which can be saved as follows:  
* \(i_{k-1}\leq i_{k}\leq i_{k-1}+1\);
* \(j_{k-1}\leq j_{k}\leq j_{k-1}+1\). DTW paths can be represented by a binary matrix whose non-zero entries correspond to the fit between the time series elements. Such a representation is related to the representation of the sequence of indices used above by Equation (25) and illustrated in Figure 9--non-zero entries in the binary matrix are represented as dots, and an equivalent sequence of matches is created on the right side:  
\[\left(A_{\pi}\right)_{i,j}=\left\{ \begin{array}{ll}1&if\ \left(i,j\right)\in\pi\\ 0&otherwise\end{array} \right. \tag{26}\]  
Using matrix notation, dynamic time curvature can be written as minimizing the dot product between matrices:  
\[DTW_{q}\Big{(}x,x^{{}^{\prime}}\Big{)}=\min_{\pi\in A\left(x,x^{{}^{\prime}} \right)}\left\langle A_{\pi},D_{q}\Big{(}x,x^{{}^{\prime}}\Big{)}\right\rangle ^{1/q} \tag{27}\]  
where \(D_{q}\Big{(}x,x^{{}^{\prime}}\Big{)}\) stores the distance \(d\Big{(}x,x^{{}^{\prime}}\Big{)}\) under \(q\). Dynamic time warping seeks a time alignment that minimizes the Euclidean distance between aligned series. To do this, it adjusts the timing of the data points to minimize the difference between the two datasets. DTW can be used to compare sequences of unequal length and unsynchronized sequences, which is an advantage of this algorithm over simple methods, i.e., Euclidean distance, which is effective only if the sequences are of equal length and perfectly aligned. A comparison of the fitting of the series using the Euclidean distance method and DTW is illustrated in Figure 10.  
In addition to time-series synchronization, DTW provides more reliable automatic identification of signal characteristics including noisy signals. This is because the aligned time series are very similar, which is a known invariant of Dynamic Time Warping. The shape of the signature of a given signal feature obtained from averaging several time series is not deformed (Figure 11). Figure 9: Dynamic time warping path represented as a binary matrix: On the left, each dot on the path indicates a non-zero entry in matrix A\({}_{\text{P}}\) corresponding to a match between an element of the time series x and an element of the series x\({}^{\prime}\). On the right, a single element of series x may correspond to multiple elements of series x\({}^{\prime}\), and vice versa; several elements of x may be matched to a single element of x\({}^{\prime}\)[66].