## 3 Materials and Methods
### Fusion of Perception Data Based on Ship ST-TF
#### 3.4.3 Asynchronous Nonlinear Ship Trajectory Association and Storage Based on the DTW Algorithm  
The core of data fusion is the matching association between visual and GPS trajectories. This section addresses the limitation of using cosine distance, which focuses solely on the directional information of vectors without accounting for positional differences between trajectory points. Therefore, Euclidean distance is employed as the similarity measure to globally assess vector similarity. The data sources used for matching in this study consist of two parts: First, high-frequency dynamic and static information uploaded to the server by the edge computing device of the experimental ship, referred to as the enhanced AIS (E-AIS). This information is collected through multi-sensors (e.g., GPS, IMU) with a high update frequency, making it suitable for the experimental environment. Second, visual positioning data of the target ship is computed in real time by the edge computing device onboard the ship. It is important to note that there are significant differences between E-AISs and traditional onboard AIS systems. While traditional AIS devices provide both static and dynamic information about the ship, their transmission frequency is irregular, and data loss may occur during communication, leading to delays or missing updates. Furthermore, visual positioning may be affected by ship occlusion in certain scenarios, resulting in trajectory loss and exhibiting nonlinear characteristics. To address these challenges, this study employs a Euclidean distance-based DTW algorithm for matching and aligning GPS data from the E-AIS or traditional AIS with the visual positioning data of the target ship, thereby achieving precise alignment and integration of trajectory points. The DTW algorithm is a method for measuring trajectory similarity. It can be employed to compare the similarity between two nonlinear time series of varying lengths and to achieve optimal alignment between them [49]. Let the coordinate sequence of visual estimates be denoted as \(n(n=1,\ldots,N)\), while the edge computing device retrieves the  
Figure 8: Synchronization process of different sensor frequencies. historical GPS trajectory sequence \(m(m=1,\dots,M)\) of surrounding ships by querying the ship information database. In practical applications, in order to reduce the computational burden, the edge computing device only retrieves the trajectory information of ships within the monitoring area of the host ship for the past 5 min. When Euclidean distance is used to measure similarity, a smaller distance indicates a higher similarity between two sequences. The formula for calculating similarity is as follows:  
\[\left\{ \begin{array}{l}DTW(n,m)=d(n,m)\,n=1\&m=1\\ DTW(n,m)=d(n,m)+\min\{DTW(n-1,m),DTW(n,m-1),DTW(n-1,m-1)\},n=1,2,\cdot\cdot\cdot,N \&m=1,2,\cdot\cdot\cdot,M\\ \end{array} \right. \tag{18}\]  
\(DTW(n,m)\) is calculated as the sum of the Euclidean distance \(d(n,m)\) between current elements and the cumulative distance to the nearest element that can be reached. \(DTW(N,M)\) serves as the result of the similarity measurement between two sequences. When the similarity measurement result between two trajectories falls below a preset similarity threshold, the visual-based ship trajectory and the GPS-based ship trajectory are directly associated, and data points are aligned. Figure 9 illustrates the asynchronous nonlinear ship trajectory sequence association using the DTW algorithm. Referring to the fusion data storage design in [13], we have redefined the method for storing correlated data based on our experimental approach. Specifically, after applying the DTW algorithm, the associated results are used to retrieve the target ship's static information (IMO, Name, Length, Breadth--note that the IMO number is a virtual number, as the experimental ship is a self-developed small MASS without an official IMO number, used solely for experimental purposes) and dynamic information (Time, SOG, COG, HDG) from the E-AIS database.