## 4 Location Algorithm Based on Ranging
### Linear Model and Kalman Filter  
There are many ways to eliminate DME. The linear model equation used in this paper is as follows:  
\[y=(1-\xi)(k_{los}\cdot x+b_{los})+\xi(k_{nlos}\cdot x+b_{nlos}) \tag{7}\]  
where \(y\) is the real distance between the tag and the anchor, \(x\) is the distance value calculated by the anchor based on TOF, \(\xi\) is the state quantity of NLOS, and \(k_{los}\), \(b_{los}\), \(k_{nlos}\), and \(b_{nlos}\) are parameters corresponding to LOS and NLOS, respectively. The value of \(\xi\) is based on the corresponding line-of-sight conditions during data collection, 1 for NLOS, and 0 for LOS.  
Kalman filter is an algorithm that uses a series of data observed over time, which contains noise and other inaccuracies, to estimate unknown variables with more accuracy [27]. For ranging, the positioning system is a linear system. A discrete Kalman filter can be used to filter the ranging value. According to Equation (6), there are multiple errors in the DME. \(\epsilon_{A}\) error includes clock drift error, and \(\epsilon_{T}\) approximately obey normal distribution. Kalman filter can eliminate the errors caused by both and makes the data more stable.  
We define the system state variable as \(X_{k}\in R^{n}\), the system control input as \(U_{k}\), and the system process excitation noise as \(W_{k}\).Then the state equation of the system is:  
\[X_{k}=AX_{k-1}+BU_{k}+W_{k} \tag{8}\]  
The observed variable is \(Z_{k}\in R^{m}\), and the observed noise is \(V_{k}\). Thus, the measurement equation can be obtained as follows:  
\[Z_{k}=HX_{k}+V_{k} \tag{9}\]  
where \(H\) is the observation model matrix, which maps the real state space to the observation space. Assuming that \(W_{k}\) and \(V_{k}\) are mutually independent and normally distributed white noise, the process excitation noise covariance matrix is \(Q\), and the observation noise covariance matrix is \(R\), that is:  
\[W_{k} \sim N(0,Q) \tag{10}\] \[V_{k} \sim N(0,R) \tag{11}\]  
The discrete Kalman filter includes the prediction process and update process. Prediction equations can be expressed as follows:  
\[\tilde{X}_{k}^{-}=A\tilde{X}_{k-1}+B\tilde{U}_{k-1} \tag{12}\]  
Figure 8: Schematic diagram of NLOS condition and how the multipath error is generated. The black dashed arrow path represents the NLOS condition, and the black solid arrow path represents the multipath transmission.  
\[P_{k}^{-}=AP_{k-1}A^{T}+Q \tag{13}\]  
Update equations are expressed as follows:  
\[K_{k}=P_{k}^{-}H^{T}(HP_{k}^{-}H^{T}+R)^{-1} \tag{14}\]  
\[\widehat{X}_{k-1}=\widehat{X}_{k}^{-}+K_{k}(Z_{k}-H\widehat{X}_{k}^{-}) \tag{15}\]  
\[P_{k}=(I-K_{k}H)P_{k}^{-} \tag{16}\]  
where \(K_{k}\), \(\widehat{X}_{k}\), \(P_{k}\), \(I\) is the Kalman gain matrix, the optimum filter value, the filter deviation matrix, and the unit matrix, respectively.  
The prediction process mainly uses the prediction equation to establish a priori estimation of the current state, and predicts the current state variable and the value of the error covariance estimate forward in time, so as to construct a priori estimate for the next time state; the more trust process is responsible for feedback, and using the prediction equation establishes an improved posterior estimate of the current state based on a priori estimates of the prediction process and current measured variables.