# Initial Experimentation of a Real-Time 5G mmWave Downlink Positioning Testbed +
## 3 Beam-Based Angle-of-Arrival Algorithm  
The AoA estimation is here performed with a beam-based AoA algorithm. First, the the mmWave front end at the receiver scans a certain angle estimation range by sweeping the pre-selected analog beams from the beambook. Then, the AoA is estimated by weighting the received power measurements of each scanned analog beam.  
A polynomial fitted to the RSRP measurements of the PRS allows us to interpolate the signal strength between the receive beams and estimate the AoA of the signal with accuracy exceeding the beam separation. Let us assume that the UE receives the PRS signal via \(M\) receive beams, with beam directions in the azimuth angle domain \(\mathbf{\phi}\in\mathbb{R}^{M}\) spanning the desired AoA estimation range that includes the (unknown) AoA of the LoS path, \(\phi_{AoA}\). Let us also assume that the signal received via each receive beam is in a form of raw I/Q samples, with I and Q signals' output recorded simultaneously through the separate output ports to obtain the baseband real part and imaginary part of the received signal, respectively. Assuming appropriate signal synchronization and cyclic prefix (CP) removal, the output of these two ports can be combined into a vector of complex samples as \(\mathbf{S}_{\text{RX}}\in\mathbb{C}^{N}\), where \(N\) is the number of OFDM symbol samples. Each beam-based RSRP measurement, therefore, can be obtained as  
\[P_{\text{b}}=10\cdot\log_{10}\left(\frac{\sum_{i\in\Omega}|\mathbf{X}_{\text{RX},i}|^{2}}{K}\right)\ \in\ \mathbb{R}, \tag{6}\]  
where \(\mathbf{X}_{\text{RX},i}\) denotes the discrete Fourier transform of \(\mathbf{S}_{\text{RX}}\), and \(\Omega\) denotes the set of PRS active subcarrier indices of cardinality \(K\). The RSRP measurements for all RX beams can be represented as a function of the beam azimuth angle \(\mathbf{P}_{b}(\mathbf{\phi})\in\mathbb{R}^{M}\), corresponding to the horizontal RSRP profile of the received signal.  
The proposed AoA estimation algorithm is then built upon a polynomial fitting of the RSRP profile using the weighted least squares (WLS) method. In particular, the vector \(\mathbf{P}_{b}\) is approximated with the second-degree polynomial (parabola) \(\widetilde{\mathbf{P}}_{b}=c_{0}+c_{1}\phi+c_{2}\phi^{2}\) subject to a Gaussian weighting function \(w(\phi)=e^{-\frac{1}{2}(\frac{\phi-\mathrm{max}}{\phi})^{2}}\), which is centered around the beam azimuth with the largest power \(\phi_{\mathrm{max}}\ =\mathrm{argmax}(\mathbf{P}_{b})\) and standard deviation \(\sigma\), being a user-defined parameter. The AoA estimate can be calculated in closed form as a function of the polynomial coefficients:  
\[\hat{\phi}_{\mathrm{AoA}}=-c_{1}/(2c_{2}). \tag{7}\]  
In case the RSRP measurements suffer from errors due to very low SNR or interference, or in case the amount of receive beams is not enough to define the maximum of \(\mathbf{P}_{b}\), the parabola may be inverted or degenerated, which does not allow to estimate \(\phi_{AoA}\). A condition \(c_{2}<0\) ensures that this does not happen, and AoA can be estimated using Equation (7). Note that in case this condition does not hold and parabolic approximation does not exist, AoA can be estimated as a direction of the beam with highest RSRP measurement, i.e., \(\hat{\phi}_{\mathrm{AoA}}=\phi_{\mathrm{max}}\).  
An example result of the AoA beam-based algorithm is shown in Figure 2.  
Note that the above beam-based AoA algorithm is presented for the azimuth beamforming at the UE. However, in case of elevation beamforming, the same principle can be applied to the elevation or zenith angle \(\theta_{\mathrm{AoA}}\) using the vertical RSRP profile or extended to fitting a parabolic surface in case of tridimensional (3D) beams.