# Stream: Spatial Trajectory Enhanced Attention Mechanism for Abnormal UAV Trajectory Detection
## 3 System Design
### Data Visualization  
In the proposed system, the UWB technology plays an important role in recognizing the trajectory by accurately determining the location of the UAV. The 2D localization system, which utilizes UWB sensors, comprises at least three anchors and one tag. Anchors are fixed in known locations, and tags are attached to UAVs. The localization process initiates with the TWR (Two-Way Ranging) protocol, marked by the exchange of signals between the anchor and the tag. The TWR protocol consists of multi-message exchange, starting with the sending of a poll message from the tag to the anchor. After that, a response message is transmitted from the anchor, and, finally, a final message is transmitted from the tag to the anchor. The time interval between the transmission and reception of these messages is accurately measured, and it is used with the speed of light to accurately measure the distance between the tag and the anchor. This process is depicted in Figure 2. The following is an equation for calculating the distance between one anchor and one tag using Time of Flight (ToF) and the speed of light. \[ \begin{split}& T_{\text{tof}}=\frac{t_{\text{round1}}\times t_{ \text{round2}}-t_{\text{reply1}}\times t_{\text{reply2}}}{t_{\text{round1}}+t_{ \text{round2}}+t_{\text{reply1}}+t_{\text{reply2}}},\\ & d=c\times T_{\text{tof}}.\end{split}  \tag{1}\]  
In the provided formula, the calculation of distance \(d\) between two devices uses Time of Flight (ToF), denoted as \(T_{\text{tof}}\). ToF represents the time taken by a signal to travel from the sender to the receiver and back. This time is crucial for determining the distance between devices using the speed of light \(c\). The formula involves four key time measurements:  
* \(t_{\text{round1}}\): Time for the signal to travel from tag to anchor and back to tag. Figure 1: This is the proposed interpolation scheme using DNN. The product and sum of these times are used in the formula to calculate the ToF, which is then multiplied by the speed of light \(c\) to find the distance \(d\) between the devices. In the system described, each anchor transmits distance data to the server using the TWR protocol. The server then estimates the exact location of the tag by employing a trilateration formula. The formula is as follows:  
\[ \begin{split}(x-x_{a})^{2}+(y-y_{a})^{2}&=d_{a}^{2},\\ (x-x_{b})^{2}+(y-y_{b})^{2}&=d_{b}^{2},\\ (x-x_{c})^{2}+(y-y_{c})^{2}&=d_{c}^{2},\end{split}  \tag{2}\]  
where \(x\) and \(y\) represent the target position coordinates. The coordinates of the three anchors are denoted as \((x_{a},y_{a})\), \((x_{b},y_{b})\), and \((x_{c},y_{c})\), and \(d_{a}\), \(d_{b}\), and \(d_{c}\) are the distances from each respective anchor to the target. By combining these expressions, we derive the following equations:  
\[ \begin{split} A&=-2x_{a}+2x_{b},\quad B=-2y_{a}+2 y_{b},\quad C=d_{a}^{2}-d_{b}^{2},\\ D&=-2x_{b}+2x_{c},\quad E=-2y_{b}+2y_{c},\quad F=d_ {b}^{2}-d_{c}^{2},\\ Ax+By=C,\quad Dx+By=F.\end{split}  \tag{3}\]  
Solving these equations for \(x\) and \(y\) yields  
\[x=\frac{CE-BF}{AE-BD},y=\frac{AF-CD}{AE-BD}. \tag{4}\]  
Therefore, with known anchor coordinates and distances, the unknown coordinates \(x\) and \(y\) can be accurately determined. The location data of the UAV obtained from the UWB sensors is essential in constructing the UAV trajectory. However, since the data are time series data, additional processing is required to effectively track the trajectory. In the proposed system, location data are smoothed through a Kalman filter to reduce noise and improve the quality of the data. After that, the data are converted into an image and processed so that the trajectory can be effectively checked. Widely used to minimize uncertainty, a Kalman filter analyzes data by recursively estimating the current state of the system based on measurement data mixed with noise. Therefore, by applying the Kalman filter to the location data estimated from the previous process, the effect of smoothing the data is obtained by reducing the noise of the data.