# Spoofing Detection Algorithm Based on Pseudorange Differences
## 2 Spoofing Detection Algorithm
### Theoretical Analysis  
First, we define the distance between \(\mathbf{X}^{i}\) and \(\mathbf{X}_{p}\) as:  
\[R\left(\mathbf{X}^{i},\mathbf{X}_{p}\right)=\sqrt{\left(x^{i}-x_{p}\right)^{2} +\left(y^{i}-y_{p}\right)^{2}+\left(z^{i}-z_{p}\right)^{2}} \tag{1}\]  
where \(\mathbf{X}^{i}=\left(x^{i},y^{i},z^{i}\right)\) represents the satellite position in the Earth-centered Earth-fixed (ECEF) coordinates and \(\mathbf{X}_{p}=\left(x_{p},y_{p},z_{p}\right)\) represents the vehicle position in the ECEF coordinates. Suppose the pseudorange of the \(i\)th satellite at \(t_{k}\) is \(p_{k}^{i}\) and at \(t_{k+1}\) is \(p_{k+1}^{i}\). We have:  
\[\rho_{k}^{i}=R\left(\mathbf{X}_{k}^{i},\mathbf{X}_{p,k}\right)+\left(\delta t _{r,k}-\delta t_{s,k}^{i}\right)\times c+\left(\delta t_{ion,k}^{i}+\delta t_{ trop,k}^{i}\right)\times c+\varepsilon_{k}^{i} \tag{2}\]  
\[\rho_{k+1}^{i}=R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{p,k+1}\right)+\left( \delta t_{r,k+1}-\delta t_{s,k+1}^{i}\right)\times c+\left(\delta t_{ion,k+1}^ {i}+\delta t_{ trop,k+1}^{i}\right)\times c+\varepsilon_{k+1}^{i} \tag{3}\]  
where \(\delta t_{r,m}\) is the receiver clock offset at \(t_{m}\), \(\delta t_{in,m}^{i}\) is the \(i\)th satellite clock offset at \(t_{m}\), \(\delta t_{in,m}^{i}\) is the \(i\)th satellite ionosphere delay at \(t_{m}\), \(\delta t_{ trop,m}^{i}\) is the \(i\)th satellite troposphere delay at \(t_{m}\), \(c\) is the speed of light and \(\varepsilon_{m}^{i}\) is the \(i\)th satellite non-model errors, such as the measurement noise at \(t_{m}\). We use the ionosphere delay correction, the troposphere delay correction and the satellite clock offset correction to correct the pseudorange. Then, the pseudorange single difference of Equations (2) and (3) is:  
\[\Delta\rho_{k+1,k}^{i}=\rho_{k+1}^{i}-\rho_{k}^{i}=R\left(\mathbf{X}_{k+1}^{i },\mathbf{X}_{p,k+1}\right)-R\left(\mathbf{X}_{k}^{i},\mathbf{X}_{p,k}\right) +\left(\delta t_{r,k+1}-\delta t_{r,k}\right)\times c+\left(\varepsilon c_{k+ 1}^{i}-\varepsilon c_{k}^{i}\right) \tag{4}\]  
where \(\varepsilon c_{m}^{i}\) represents the \(i\)th satellite's non-model errors, such as the measurement noise and the ionosphere delay, the troposphere delay and the satellite clock offset correction residuals at \(t_{m}\). Similarly, for the \(j\)th satellite, we have:  
\[\Delta\rho_{k+1,k}^{j}=\rho_{k+1}^{j}-\rho_{k}^{j}=R\left(\mathbf{X}_{k+1}^{j },\mathbf{X}_{p,k+1}\right)-R\left(\mathbf{X}_{k}^{j},\mathbf{X}_{p,k}\right) +\left(\delta t_{r,k+1}-\delta t_{r,k}\right)\times c+\left(\varepsilon c_{k+ 1}^{j}-\varepsilon c_{k}^{j}\right) \tag{5}\]  
The pseudorange double difference is calculated between Equations (4) and (5). Equation (6) is the pseudorange double-difference model. \[ \begin{split}\Delta\rho_{k+1,k}^{ij}&=\Delta\rho_{k +1,k}^{i}-\Delta\rho_{k+1,k}^{j}\\ &=\left[R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{p,k+1}\right)-R \left(\mathbf{X}_{k}^{i},\mathbf{X}_{p,k}\right)\right]-\left[R\left(\mathbf{ X}_{k+1}^{j},\mathbf{X}_{p,k+1}\right)-R\left(\mathbf{X}_{k}^{j},\mathbf{X}_{p,k} \right)\right]+\left(\varepsilon c_{k+1}^{i}-\varepsilon c_{k}^{i}\right)- \left(\varepsilon c_{k+1}^{j}-\varepsilon c_{k}^{i}\right)\end{split}  \tag{6}\]  
In Equation (6), the distances \(R\left(\mathbf{X}_{k}^{i},\mathbf{X}_{p,k}\right)\) and \(R\left(\mathbf{X}_{k}^{j},\mathbf{X}_{p,k}\right)\) are known when we detect the authenticity of the signal at \(t_{k+1}\), so Taylor expansion is only needed for \(R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{p,k+1}\right)\) and \(R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{p,k+1}\right)\). Taylor expansion of \(R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{p,k+1}\right)\) is done at \(\left(x_{k},y_{k},z_{k}\right)\). We have:  
\[R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{p,k+1}\right)\approx R\left(\mathbf\[u_{z,k+1,k}^{i} =-\left(z_{k+1}^{i}-z_{k}\right)/R\left(\mathbf{X}_{k+1}^{i},\mathbf{ X}_{k}\right)\] \[\left\{ \begin{array}{l}x_{k+1,SDA}=x_{k}+\Delta x\\ y_{k+1,SDA}=y_{k}+\Delta y\\ z_{k+1,SDA}=z_{k}+\Delta z\end{array} \right.\]  
where \(\mathbf{u}_{k+1,k}^{i}=\left[