*6.1. Angle Estimation*

Because of the geometrical structures of the indoor environment, the movement of people indoors usually tends to be in the same direction at least for a few seconds, e.g., in the case of a corridor, a user can walk in two directions. As the usual direction of a chest-mounted wearable device is the same as the movement direction of a user, this behaviour, along with the concept of landmark graph, RNs location information, and indoor environmental geometrical constrain, can be exploited to calculate the angle between the chest-mounted wearable tag and the RNs. To calculate the angle between a user and an RN, the two-argument arctangent function (atan2) is used, which can estimate the angle in the Euclidean plane between the positive x-axis and a line connecting to a point, as shown in Figure 8a.

**Figure 8.** Angle estimation between a wearable device and an RN: (**a**) concept of atan2; (**b**) adaptation of atan2 for estimating the angle between the moving direction and the RN.

In this study, the path segmen<sup>t</sup> where the user is walking during the angle estimation is considered as the line corresponding to the x-axis. Thus, the angle is calculated between the moving path and the line connecting the current location of the user and the location of the RN (Figure 8b), as follows:

$$
\theta\_{\rm rad} = \operatorname{atan2}(\mathbf{Y}\_{\rm RN} - \mathbf{Y}\_{\rm T}, \mathbf{X}\_{\rm RN} - \mathbf{X}\_{\rm T}) \in \left( -\pi\_{\prime}, \pi \right) \text{ and } \left( \mathbf{X}\_{\rm RN}, \mathbf{Y}\_{\rm RN} \right) \neq \left( 0, 0 \right) \tag{7}
$$

$$
\theta\_{d\text{cg}} = \frac{180^{\circ}}{\pi} \theta\_{rad} \tag{8}
$$

$$\theta\_B = \begin{cases} \theta\_{d\text{cg}}, & \text{when } \theta\_{d\text{cg}} \ge 0 \\ 2\pi + \theta\_{d\text{cg}}, & \text{when } \theta\_{d\text{cg}} < 0 \end{cases} \tag{9}$$

where (*XT*, *YT*) and (*XRN*, *YRN*) are the coordinates of the current locations of the user and the RN, and *θB* is the bearing angle between the user and an RN in degrees. In this study, a coarse location of the unknown target is estimated first as the current location (*XT*, *YT*) to estimate the bearing angle between the target and an RN. This coarse location is computed based on its immediate previous location, and the step length and moving direction. Here, the step length and step direction are obtained by leveraging the landmark graph. At the start, the step length for a target is initialised to a constant value. As the target progresses and passes two adjacent landmarks, the step length is updated. Let a target pass two adjacent landmarks denoted by *L*1 and *L*2. Then, the step length of that target can be obtained as follows:

$$l\_{\rm s} = \frac{\sqrt{\left(\mathbf{x}\_{L\_1} - \mathbf{x}\_{L\_2}\right)^2 + \left(y\_{L\_1} - y\_{L\_2}\right)^2}}{N\_S} \tag{10}$$

where *xL*1 , *yL*1 and *xL*2 , *yL*2 are the coordinates of the landmarks *L*1 and *L*2, respectively, and *NS* is the total number of previous location points in between the landmarks *L*1 and *L*2 that are estimated when the target passes the landmarks. Here, the step length will only be updated if the trajectory between the adjacent landmarks is a straight line. Otherwise, the system will retain the step length that estimated last. The estimation of step direction exploits the geometrical structures of indoor environment and infers the moving direction as the direction of the current trajectory relative to the considered x-axis. Thus, when the step length *ls* and heading *θs* are known, the estimation of the next location can be obtained by using the elementary pedestrian dead reckoning (PDR) technique as follows:

$$\mathbf{x}\_{s+1} = \mathbf{x}\_s + l\_s \sin(\theta\_s) \tag{11}$$

$$y\_{s+1} = y\_s + l\_s \cos(\theta\_s) \tag{12}$$

where (*xs*, *ys*) and (*xs*+1, *ys*+<sup>1</sup>) are the positions of a subject at step *s* and *s* + 1, respectively, and *θs* and *ls* are the heading and displacement at step *s*. Therefore, (*xs*+1, *ys*+<sup>1</sup>) are considered as the current location (*XT*, *YT*) to calculate the angle between an RN and the current coarse position of the target, considering the target is moving exactly the same direction as the trajectory's direction. However, a target can rotate his/her body while walking towards a trajectory's direction, which will eventually affect the measured *θB* in the perspective of RSSI correction. Let *θR* be the rotation angle obtained from the gyroscope. Then, the orientation angle *θO* of the target relative to an RN can be calculated as follows:

$$
\theta\_O = \theta\_B \pm \theta\_R \pm \theta\_{L\_1 L\_2} \tag{13}
$$

where *<sup>θ</sup>L*1*L*2 is the angle difference of the path segmen<sup>t</sup> connecting the landmarks *L*1 and *L*2 relative to the x-axis in anticlockwise direction, which can be obtained from the landmark graph.
