## 3 Localization Algorithm
### BLE Based Algorithm  
The first localization method used in the proposed system is an Extended Kalman Filter (EKF)-based algorithm [38] utilizing solely BLE power measurement results. The main advantage of the EKF over traditional geometry-based methods such as trilateration is that the result of the EKF if a combination of the result calculated using performed measurements and the prognosed location based on the previous user position. It allows to mitigate abrupt changes of signal level, which often occur in the multipath environments. Additionally, the number of the results that can be used for localization is not limited. In EKF it is also possible to take into consideration higher variance of the results obtained by the anchors, which are far away from the tag. In the algorithm, the localized user is treated as a dynamic system and the state at the current moment \(k\) is described by a vector:  
\[x_{k}= \begin{bmatrix}x&v_{x}&y&v_{y}\end{bmatrix}  \tag{1}\]  
containing the user's current coordinates: \(x\), \(y\) and velocity components: \(v_{x}\), \(v_{y}\). The vector does not include information on the \(z\) coordinate (height, at which the localized tag is worn) and corresponding velocity. All of the algorithms presented in the paper are intended for 2D localization and \(z\) value is one of the algorithm parameters. The EKF is an iterative algorithm consisting of two phases: time-update phase and measurement-update phase. In the time-update phase, the localization of the user at the current moment \(k\) is predicted based on the location calculated for the previous moment (\(k-1\)) and the assumed movement model. The equations comprising this phase are:  
\[\hat{x}_{k(-)}=F\hat{x}_{k-1(+)} \tag{2}\]  
\[P_{k(-)}=FP_{k-1(+)}F^{T}+Q \tag{3}\]  
where:  
* \(\hat{x}_{k(-)}\) is the predicted state vector value,
* \(\hat{x}_{k-1(+)}\) is the state vector value obtained in the previous EKF iteration,
* \(P_{k(-)}\) and \(P_{k-1(+)}\) are the state covariance matrices of the above vectors,
* \(F\) is the state transition matrix containing the movement model,
* \(Q\) is the process noise covariance matrix. The movement model used in the algorithm is the Discrete White Noise Acceleration (DWNA) [39] model, in which the movement between the analyzed moments is uniform and linear and acceleration is treated as process noise. For the DWNA, matrices \(F\) and \(Q\) have the following form:  
\[F= \begin{bmatrix}1&\Delta t&0&0\\ 0&1&0&0\\ 0&0&1&\Delta t\\ 0&0&0&1\end{bmatrix} \qquad Q= \begin{bmatrix}\Delta t^{2}&\frac{1}{2}\Delta t^{3 }&0&0\\ \frac{1}{2}\Delta t^{3}&\frac{1}{4}\Delta t^{4}&0&0\\ 0&0&\Delta t^{2}&\frac{1}{2}\Delta t^{3}\\ 0&0&\frac{1}{2}\Delta t^{3}&\frac{1}{4}\Delta t^{4}\end{bmatrix} \sigma_{a}^{2} \tag{4}\]  
where \(\Delta t\) is algorithm update rate and \(\sigma_{a}^{2}\) is acceleration variance, which is usually assumed to be in the range of 0.5-1 of a moving man's maximum acceleration. The obtained predicted localization \(\hat{x}_{(-)}\) is updated with measurement results in the measurement-update phase. This phase consists of estimating measurement results, which would be obtained for the predicted localization based on assumed sensor model (BLE anchor model). The predicted measurement results are then compared with the actual values measured by the infrastructure.