# Spoofing Detection Algorithm Based on Pseudorange Differences
## 2 Spoofing Detection Algorithm
### Theoretical Analysis
\begin{array}{cc}u_{x,k+1,k}^{i}&u_{y,k+1,k}^{ i}&u_{z,k+1,k}^{i}\end{array} \right]\) is the line-of-sight unit vector of the \(i\)th satellite. The subscripts \(k\) and \(k+1\) represent the time point \(t_{k}\) and \(t_{k+1}\), respectively. \((x_{k+1,SDA},y_{k+1,SDA},z_{k+1,SDA})\) is the position vector at \(t_{k+1}\), and it is the quantity we need to calculate by the algorithm proposed in this paper. Similarly, Taylor expansion of \(R\left(\mathbf{X}_{k+1}^{j},\mathbf{X}_{p,k+1}\right)\) is done at \((x_{k},y_{k},z_{k})\). The two expansion equations are substituted into Equation (6), then we have:  
\[ \begin{array}{l}R\left(\mathbf{X}_{k+1}^{i},\mathbf{X}_{k}\right)-R\left( \mathbf{X}_{k+1}^{j},\mathbf{X}_{k}\right)+u_{x,k+1,k}^{i}\left(x_{k+1,SDA}-x_ {k}\right)+u_{y,k+1,k}^{i}\left(y_{k+1,SDA}-y_{k}\right)+u_{z,k+1,k}^{i}\left( z_{k+1,SDA}-z_{k}\right)\\ -u_{x,k+1,k}^{j}\left(x_{k+1,SDA}-x_{k}\right)-u_{y,k+1,k}^{j}\left(y_{k+1,SDA }-y_{k}\right)-u_{z,k+1,k}^{j}\left(z_{k+1,SDA}-z_{k}\right)\\ =\Delta\rho_{k+1,k}^{i}-\Delta\rho_{k+1,k}^{j}+\left[R\left(\mathbf{X}_{k}^{i },\mathbf{X}_{p,k}\right)-R\left(\mathbf{X}_{k}^{i},\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}^{j}\right)\end{array}  \tag{8}\]  
If there are \(n\) satellites with the same PRN number at \(t_{k}\) and \(t_{k+1}\), the pseudorange double difference is calculated between the first satellite and the other \((n-1)\) satellites, respectively. Therefore, \((n-1)\) equations are obtained. Taylor expansion is applied to these equations and written in the matrix form. \[\mathbf{M}\left[ \begin{array}{l}x_{k+1,SDA}-x_{k}\\ y_{k+1,SDA}-y_{k}\\ z_{k+1,SDA}-z_{k}\end{array} \right]=\mathbf{L} \tag{9}\]  
where,  
\[\mathbf{M} =\mathbf{M}_{1}-\mathbf{M}_{2}\] \[=\left[ \begin{array}{cccc}u_{x,k+1,k}^{1}&u_{y,k+1,k}^{1}&u_{z,k +1,k}^{1}\\ u_{x,k+1,k}^{1}&u_{y,k+1,k}^{1}&u_{z,k+1,k}^{1}\\ \vdots&\vdots&\vdots\\ u_{x,k+1,k}^{1}&u_{y,k+1,k}^{n}&u_{z,k+1,k}^{n}\end{array} \right]\]  
\[\mathbf{L} =\mathbf{L}_{1}-\mathbf{L}_{2}\] \[=\left[ \begin{array}{cccc}\Delta\rho_{k+1,k}^{1}+R\left( \mathbf{X}_{k}^{1},\mathbf{X}_{p,k}\right)-R\left(\mathbf{X}_{k+1}^{1}, \mathbf{X}_{k}\right)-\left(\varepsilon c_{k+1}^{1}-\varepsilon c_{k}^{1} \right)\\ \Delta\rho_{k+1,k}^{1}+R\left(\mathbf{X}_{k}^{1},\mathbf{X}_{p,k}\right)-R \left(\mathbf{X}_{k+1}^{1},\mathbf{X}_{k}\right)-\left(\varepsilon c_{k+1}^{1} -\varepsilon c_{k}^{1}\right)\\ \vdots\\ \Delta\rho_{k+1,k}^{1}+R\left(\mathbf{X}_{k}^{1},\mathbf{X}_{p,k}\right)-R \left(\mathbf{X}_{k+1}^{1},\mathbf{X}_{k}\right)-\left(\varepsilon c_{k+1}^{1} -\varepsilon c_{k}^{1}\right)\end{array} \right]\] \[-\left[ \begin{array}{cccc}\Delta\rho_{k+1,k}^{2}+R\left( \mathbf{X}_{k}^{2},\mathbf{X}_{p,k}\right)-R\left(\mathbf{X}_{k+1}^{2},\mathbf{X }_{k}\right)-\left(\varepsilon c_{k+1}^{2}-\varepsilon c_{k}^{2}\right)\\ \Delta\rho_{k+1,k}^{3}+R\left(\mathbf{X}_{k}^{3},\mathbf{X}_{p,k}\right)-R \left(\mathbf{X}_{k+1}^{3},\mathbf{X}_{k}\right)-\left(\varepsilon c_{k+1}^{3} -\varepsilon c_{k}^{3}\right)\\ \vdots\\ \Delta\rho_{k+1,k}^{n}+R\left(\mathbf{X}_{k}^{n},\mathbf{X}_{p,k}\right)-R \left(\mathbf{X}_{k+1}^{n},\mathbf{X}_{k}\right)-\left(\varepsilon c_{k+1}^{n} -\varepsilon c_{k}^{n}\right)\end{array} \right]\]  
The size of \(\mathbf{M}\) is \((n-1)\times 3\), and the size of \(\mathbf{L}\) is \((n-1)\times 1\). To compare the differences between the position vector of the spoofing detection algorithm proposed in this paper and the position vector of the traditional least squares method in the analytic expression, we add a row to the matrix \(\mathbf{M}\) and \(\mathbf{L}\), respectively. Equation (9) can then be rewritten as:  
\[\left\{\left[ \begin{array}{c}\mathbf{0}_{1\times 3}^{\mathbf{M}}\\ \mathbf{M}_{1}\end{array} \right]-\left[ \begin{array}{c}\mathbf{0}_{1\times 3 }^{\mathbf{M}}\\ \mathbf{M}_{2}\end{array} \right]\right\}\left[ \begin{array}{c}x_{k+1,SDA}-x_ {k}\\ y_{k+1,SDA}-y_{k}\\ z_{k+1,SDA}-z_{k}\end{array}