# 5G Positioning: An Analysis of Early Datasets
## 3 Methods
### Least Squares Algorithm  
In the single-epoch solution, the unknowns are the horizontal coordinates of the receiver \([x_{R},y_{R}]\), while the height is kept constant. Since the least squares method is applicable only to a set of linear equations, the processing involves the linearization of the observation equations with respect to the receiver's coordinates. The starting point of the process is the general formula for the distance between \(BS\) and \(R\):  
\[\rho_{R}^{BS}=\tilde{\rho}_{R}^{BS}+\tilde{\mathbf{e}}_{R}^{BS}\cdot\mathbf{ dx}_{R} \tag{5}\]  
where \(\tilde{\rho}_{R}^{BS}\) and \(\tilde{\mathbf{e}}_{R}^{BS}\) are, respectively, the approximated distance and the unitary vector from \(BS\) to \(R\); \(\mathbf{dx}_{R}\) is the difference between the true and the approximated coordinates of \(R\). Considering two base stations (\(BS1\) and \(BS2\)), and remembering that the \(TDoA\) will be the input of the algorithm, the difference in the distances can be written as  
\[\rho_{R}^{BS1,BS2}=\tilde{\rho}_{R}^{BS1,BS2}+\Delta\mathbf{e}_{R}^{BS1,BS2} \cdot\mathbf{dx}_{R} \tag{6}\]  
where \(\rho_{R}^{BS1,BS2}\) is the difference in the two distances, from the two \(BS\) to \(R\). \(\Delta\mathbf{e}_{R}^{BS1,BS2}\) is the difference of the two unitary vectors, from \(BS1\) and \(BS2\) to \(R\). Given all the available \(n\)\(ToA\) in one epoch, \(n-1\)\(TDoA\) can be derived. A system can be written introducing the classical notation of the least squares method:  
\[\mathbf{y}=\mathbf{A}\cdot\mathbf{dx}_{R}+\mathbf{b} \tag{7}\]  
where \(\mathbf{y}\) is the vector of the observables, \(\mathbf{b}\) is the vector containing the known terms, and \(\mathbf{A}\) is the design matrix, whose \(n-1\) rows are simply the transpose of \(\Delta\mathbf{e}_{R}^{BSi,BSj}\). The final LS solution is given by  
\[\hat{\mathbf{dx}}_{R}=\mathbf{N}^{-1}\mathbf{A}^{T}\mathbf{Q}^{-1}(\mathbf{y }_{0}-\mathbf{b}) \tag{8}\]  
where \(\mathbf{Q}\) is the cofactor matrix of \(TDoA\), \(\mathbf{y}_{0}\) are the available observations, and \(\mathbf{N}=\mathbf{A}^{T}\mathbf{Q}^{-1}\mathbf{A}\). In addition to the unknowns, their covariance matrix can be estimated:  
\[\mathbf{C}_{xx}=\delta^{2}\mathbf{N}^{-1} \tag{9}\]where \(\hat{\sigma}^{2}\) is the a posteriori variance. Even the observations' residuals and normalized residuals can be computed according to [23]. **Q** is obtained as follows, given the cofactor matrix **C** of the undifferenced _ToA_:  
\[\textbf{Q}=\Delta\textbf{C}\Delta^{\text{T}} \tag{10}\]  
where \(\Delta\) is the matrix of the linear transformation from _ToA_ to _TDoA_. In our specific case, arranging the stations in order to have the reference one in the first position:  
\[\Delta= \begin{bmatrix}1&-1&0&\dots&0\\ 1&0&-1&\dots&0\\ \dots&\dots&\dots&\dots&\dots\\ 1&0&0&\dots&-1\end{bmatrix} , \tag{11}\]  
We assume that the available _ToA_s are not correlated: therefore, when weights are applied, **C** is defined as  
\[\textbf{C}= \begin{bmatrix}\eta^{BS1}&0&0&\dots&0\\ 0&\eta^{BS2}&0&\dots&0\\ \dots&\dots&\dots&\dots&\dots\\ 0&0&0&\dots&\eta^{BSn}\end{bmatrix}  \tag{12}\]  
where the weights can be, for example, given by  
\[\eta^{BSi}=\frac{1}{SNR_{i}^{2}}. \tag{13}\]  
In case weights are not applied, each \(\eta=1\). The weighting of the _ToA_ will be discussed in the following sections. Figure 5 (right) shows the LS processing scheme. Linearized least squares requires iterations: in our application, the initial approximate coordinates are set in the barycenter of the base stations, at each following iteration the estimated values at the previous iteration are used. The algorithm iterates up to a maximum number of 20 iterations, unless the convergence (set to one millimeter) is reached.