## 2 Dynamic Time Warping  
Signal similarity measurement assesses the degree of similarity between two time series. Low similarity indicates a significant difference between the two time series; conversely, high similarity suggests a minimal difference. The degree of similarity between two time series can be determined by measuring the distance between them. Time series similarity metrics can be categorized into lock steps and elasticity. The Euclidean distance in lock step metrics is a commonly used and relatively simple method of measuring similarity. In an N-dimensional space, the distance between two time series is calculated as follows:  
\[D\ =\ \sqrt{\sum_{i\ =\ 1}^{N}{(x_{1i}-x_{2i})^{2}}} \tag{1}\]  
The Euclidean distance is highly sensitive to noise, and the distance calculations can be significantly affected in scenarios with much noise. Furthermore, the Euclidean distance is only suitable for the comparison of two sequences of equal length. When dealing with sequences of unequal length or misaligned time steps, the similarity results obtained using the Euclidean distance often fail to accurately reflect the actual situation and lack scalability. Therefore, it is essential to consider these issues and identify appropriate methods of measuring similarity. As one of the elasticity metrics, the DTW algorithm effectively addresses these challenges. The DTW algorithm exhibits high adaptability to challenges, such as environmental interference and incomplete time series data. It overcomes the limitations of the Euclidean distance, which arise from comparing time series of unequal lengths or with misaligned time steps, and can find the optimal matching path for time series of arbitrary lengths, thereby allowing for asynchronous matching and demonstrating strong robustness [16]. The DTW algorithm has widespread application in speech recognition, motion analysis, bioinformatics, and image recognition. Unlike the Euclidean distance, which allows for \"one-to-one\" alignment between two time series points, the DTW algorithm enables the accurate matching of peaks and valleys through \"one-to-many\" alignment (Figure 1). The DTW algorithm employs the concept of dynamic programming, ultimately aiming to identify the path to which each data point in the two time series corresponds with the minimum accumulated distance. The similarity is then defined as the average sum of the distances between corresponding grid points along the best matching path. The two time series segments are denoted as \(a\ =\ \{a_{1},a_{2},\ldots a_{n}\}\), \(b\ =\ \{b_{1},b_{2},\ldots b_{m}\}\). To align the two time series, a matrix \(\mathbf{M}\) of size \(m\times n\) is constructed, and the distance between the corresponding points \(a_{i}\) and \(b_{j}\) of the two time series is denoted by the element at the \((i,j)\) position of the matrix \(\mathbf{M}\), defined as  
\[Dist(i,j)\ =\ \big{|}a_{i}-b_{j}\big{|} \tag{2}\]  
This method can be visualized as finding a path through grid points on a grid diagram (Figure 2), with the aligned points representing those visited on this path. We define this path as a warping path denoted by \(\mathbf{W}\), and the regularized path \(\mathbf{W}\) can be considered as a collection of index sequences [16]:  
\[W\ =\ w_{1},w_{2},\ldots,w_{k},\ldots,w_{K} \tag{3}\]  
where \(\max(m,n)\leq K\leq m+n+1\). This path must adhere to the following constraints [16]: (1) boundary constraint: \(w_{1}\ =\ (1,1)\) and \(w_{K}\ =\ (m,n)\); (2) continuity constraint: if \(w_{k-1}\ =\ (a^{\prime},b^{\prime})\), then \(w_{k}\ =\ (a,b)\) should satisfy \(a-a^{\prime}\leq 1\) and \(b-b^{\prime}\leq 1\); and (3) monotonicity constraint: if \(w_{k-1}\ =\ (a^{\prime},b^{\prime})\), then \(w_{k}\ =\ (a,b)\) should fulfill \(a-a^{\prime}\geq 0\) and \(b-b^{\prime}\geq 0\). Figure 1: Two different alignments: (**a**) one-to-one alignment (Euclidean distance) and (**b**) one-to-many alignment (DTW algorithm). Figure 2: DTW path. Multiple paths satisfy the aforementioned conditions.