# Primary User Emulation Attacks: A Detection Technique Based on Kalman Filter
## 2 Methodology  
The proposed approach is based on the Kalman filter framework for tracking the primary user location and deciding if the incumbent signal is emitted by a legitimate primary user or from an attacker. Figure 1 shows the flowchart of the proposed approach. In this approach, the primary user position is tracked using the Kalman filter [28], then the distance, \(d_{kfi}\) between a node \(i\) and the legitimate primary user is estimated. Next, the received power of the transmitter is used to calculate the distance, \(d_{pi}\) between the node \(i\) and that transmitter using the Free Space Path Loss Equation. If the difference between \(d_{kfi}\) and \(d_{pi}\) is greater or equal to a predefined threshold \(\tau\), then the transmitter is an attacker. Otherwise, it is a legitimate primary user. In this work, we assume that the primary user is moving in a two-dimensional field and its state is described by its position and its velocity. In addition, we assume that the initial position of the primary user is known to the secondary users. The state of the primary user is represented as  
\[x_{k}=\left[x(k)\ y(k)\ v_{x}(k)\ v_{y}(k)\right]^{T} \tag{1}\]  
where \((x(k),\ y(k))\) are the coordinates of the primary user position at the time \(t_{k}\) and \((v_{x}(k),\ v_{y}(k))\) are the velocities of the primary user in \(x\) and \(y\)-directions at time \(t_{k}\), respectively. In addition, we assume that the movement of the primary user is locally linear within the sampling interval time. Thus, its motion can be modeled as  
\[x_{k+1}=A_{k}x_{k}+B_{k}u_{k}+\ w_{k} \tag{2}\]  
where \(A\) and \(B\) represent the transition matrix and the control matrix, respectively. \(u_{k}\) is the acceleration of the primary user and \(w_{k}\) is a white Gaussian noise with zero mean and covariance matrix \(Q\), which is given by  
\[Q=\left[ \begin{array}{cc}\sigma^{2}{}_{ux}&0\\ 0&\sigma^{2}{}_{vy}\end{array} \right] \tag{3}\]where \(\sigma^{2}{}_{wx}\) and \(\sigma^{2}{}_{wy}\) are the covariances of \(wx\) and \(wy\) which correspond to the acceleration noise of the primary user along the X-axis and Y-axis, respectively. The transition and the control matrix are given by  
\[A_{k}=\left[ \begin{array}{cccc}1&0&\Delta t_{k}&0\\ 0&1&0&\Delta t_{k}\\ 0&0&1&0\\ 0&0&0&1\end{array} \right],B_{k}=\left[ \begin{array}{c}\frac{\Delta tk^{2}}{2 }\\ \frac{\Delta tk^{2}}{2}\\ \Delta t_{k}\\ \Delta t_{k}\end{array} \right] \tag{4}\]  
where \(\Delta t_{k}=t_{k+1}-t_{k}\) is the sampling interval time between two successive measurements at \(t_{k+1}\) and \(t_{k}\). The measurement model \(z_{k}\) adopted is given by  
\[z_{k}=Cx_{k}+v_{k} \tag{5}\]  
where \(C\) is the measurement matrix and \(v_{k}\) is the measurement noise which is a white Gaussian noise with zero mean and covariance matrix \(R\). \(C\) is given by  
Figure 1: Flowchart of the proposed approach. \[C=\left[ \begin{array}{cccc}1&0&0&0\\ 0&1&0&0\end{array} \right] \tag{6}\]  
During the first process of Kalman filter, the state of the primary user \(\hat{x}_{k+1}\) and its associated covariance error matrix \(P_{k+1}\) at time \(t_{k+1}\) are predicted using the following equations  
\[\hat{x}_{k+1}=A_{k}\hat{x}_{k}+B_{k}u_{k} \tag{7}\]  
\[P_{k+1}=A_{k}P_{k}A_{k}^{T}+Q_{k} \tag{8}\]  
where \(\hat{x}_{k}\) is the primary user state at time \(k\), \(P_{k}\) is the covariance error matrix at time \(k\), and \(A_{k}^{T}\) is the transpose of transition matrix \(A\) at time \(k\).