# Optimizing the Use of RTKLIB for Smartphone-Based GNSS Measurements
## 2 Strategies
### Kinematic Solution Algorithm  
The navigation engine of RTKLIB is based on extended Kalman filter (EKF) and double differencing with respect to a nearby base station. Although the different modes and algorithms implemented for the RTKLIB are available in the user manual [18], a summary of the relevant algorithms utilized for GSDC is provided below. Moreover, although the manual explains the algorithms for estimating the position and velocity states of the receiver, the latest RTKLIB also includes the added acceleration states as well, so the equations below address this update. The EKF is used to compute the estimated state vector \(\hat{x}_{k}\), and its covariance matrix \(P_{k}\), for epoch \(t_{k}\), using a measurement vector \(\boldsymbol{y}_{k}\). \[\hat{x}_{k}^{+}=\hat{x}_{k}^{-}+K_{k}(\boldsymbol{y}_{k}-\boldsymbol{h}(\hat{ x}_{k}^{-}) \tag{1}\]  
\[P_{k}^{+}=\big{(}I-K_{k}\boldsymbol{H}(\hat{x}_{k}^{-})\big{)}P_{k}^{-} \tag{2}\]  
\[P_{k}^{+}=\big{(}I-K_{k}\boldsymbol{H}(\hat{x}_{k}^{-})\big{)}P_{k}^{-} \tag{3}\]  
\[\hat{x}_{k+1}^{-}=F_{k}^{k+1}\hat{x}_{k}^{+} \tag{4}\]  
\[P_{k+1}^{-}=F_{k}^{k+1}P_{k}^{+}F_{k+1}^{+1}+P_{k}^{+1}+P_{k}^{+1} \tag{5}\]where the \(+/-\) signs indicate whether it is before or after the measurement update. \(\mathbf{F}\) and \(\mathbf{Q}\) are the state transition matrix and the system noise covariance matrix, respectively, and \(m\) is the number of satellites observed and used in the computation. For a given receiver \(r\), stationary base station \(b\), and satellites \(j\) and \(k\), we can take the double difference of the pseudorange \(P\), and carrier phase measurements \(\mathbf{\phi}\). \[p_{rb,i}^{jk}=\rho_{rb}^{jk}+\epsilon_{P} \tag{6}\]  
\[\Phi_{rb,i}^{jk}=\rho_{rb}^{jk}+\lambda\Big{(}B_{rb,i}^{j}-B_{rb,i}^{k}\Big{)} +\epsilon_{\mathbf{\phi}} \tag{7}\]  
where \(\rho\) is the geometric range, \(e\) is the noise, \(\lambda\) and \(i\) are the wavelength and corresponding index of the GNSS signal which is, in this case, L1 and L5, and \(\mathbf{B}\) is the single differenced integer ambiguity. The double difference effectively removes the atmospheric error effects from the measurements. The state vector \(\mathbf{x}\) we are solving for would include the position \(\mathbf{r_{r}}\), velocity \(\mathbf{v_{r}}\), and acceleration \(\mathbf{a_{r}}\) of the receiver. \[\mathbf{x}=\left[ \begin{array}{c}\mathbf{r_{r}}\\ \mathbf{v_{r}}\\ \mathbf{a_{r}}\\ \mathbf{B_{1}}\\ \mathbf{B_{5}}\end{array} \right]\mathbf{B_{i}}=\left[ \begin{array}{c}\mathbf{B_{rb,i}^{ \mathbf{1}}}\\ \mathbf{B_{rb,i}^{\mathbf{2}}}\\ \ldots\\ \mathbf{B_{rb,i}^{\mathbf{m}}}\end{array} \right] \tag{8}\]  
The measurement vector \(\mathbf{y}\) is defined with respect to a single satellite with the highest elevation indexed as 1. Although this is effective for a high elevation satellite in open-sky conditions, it is important to note that if this satellite has anomalies, this could negatively affect the quality of the final solution. \[\mathbf{y}=\left[ \begin{array}{c}\mathbf{\phi_{1}}\\ \mathbf{\phi_{5}}\\ \mathbf{P_{1}}\\ \mathbf{P_{5}}\end{array} \right]\mathbf{\phi_{i}}=\left[ \begin{array}{c}\phi_{rb,i} ^{12}\\ \phi_{rb,i}^{13}\\ \ldots\\ \phi_{rb,i}^{1m}\end{array} \right]\mathbf{P_{i}}=\left[ \begin{array}{c}P_{rb,i} ^{12}\\ P_{rb,i}^{13}\\ \ldots\\ P_{rb,i}^{1m}\end{array} \right] \tag{9}\]  
For the measurement update, we write the measurement model vector \(\mathbf{h}(\mathbf{x})\), the matrix of partial derivatives \(\mathbf{H}(\mathbf{x})\), and the covariance matrix of measurement errors \(\mathbf{R}\), as follows:  
\[\mathbf{h}(\mathbf{x})=\left[ \begin{array}{c}\mathbf{h_{\phi,1}}\\ \mathbf{h_{\phi,5}}\\ \mathbf{h_{\rho,1}}\\ \mathbf{h_{\rho,5}}\end{array} \right]\mathbf{H}(\mathbf{x})=\left[ \begin{array}{ccc}- \mathbf{D}\mathbf{E}\ \ \ 0\ \ \ \ \lambda_{1}\mathbf{D}\ \ \ 0\\ -\mathbf{D}\mathbf{E}\ \ \ 0\ \ \ \ \ \ \ \ \ \ \lambda_{5}\mathbf{D}\\ -\mathbf{D}\mathbf{E}\ \ \ 0\ \ \ \ \ \ \ \ 0\\ -\mathbf{D}\mathbf{E}\ \ \ 0\ \ \ \ \ 0\end{array}