Study of Activity Tracking through Bluetooth Low Energy-Based Network

This paper proposes a proof-of-concept, low-cost, and easily deployable Bluetooth low energy-(BLE-) based localization system which actively scans and localizes BLE beacons attached to mobile subjects in a room. Using the received signal strength (RSS) of a BLE signal and the uniqueness of BLE hardware addresses, mobile subjects can be identi ﬁ ed and localized within the hospital room. The RSS measurement of the BLE signal from a wearable BLE beacon varies with distance to the wall-anchored BLE scanner. In order to understand and demonstrate the practicality of the relationship between RSS of a BLE beacon and the distance of a beacon from a scanner, the ﬁ rst part of the paper presents the analysis of the experiments conducted in a low-noise and nonre ﬂ ective environment. Based on the analysis conducted in an ideal environment, the second half of the paper proposes a data-driven localization process for pinpointing the movements of the subject within the experimental room. In order to ensure higher accuracy like ﬁ ngerprinting techniques and handle the increased number of BLE-anchored scanners like geometric techniques, the proposed algorithm was designed to combine the best aspects of these two techniques for better localization. The paper evaluates the e ﬀ ects of the number of BLE wall-mounted scanners and the number of packets on the performance of the proposed algorithm. The proposed algorithm locates the patient within the room with error less than 1.8m. It also performs better than other classical approaches used in localization.


Introduction
Understanding of patients is highly dependent on the communication skills and interaction between health care workers and patients. Unfortunately, health care professionals often struggle to evaluate patient needs and physical capacity. This is especially true for cases when patients have difficulty evaluating their physical activity and underestimate their limitations [1,2]. Hence, the addition of objective mobility sensor data has the potential to enhance the patient-clinician interaction. Estimating a patient's mobility and exercise capacity is an important part of any preoperative clinical evaluation [3,4].
To objectively evaluate the mobility of patients, this paper presents a low-cost and easily deployable indoor localization system to locate and record the activity of patients. With the help of Bluetooth low energy (BLE) signal strength and the uniqueness of the BLE-based hardware addresses, the patient can be uniquely identified and located for tracking in home or any care giving settings.
The first step in the localization process is to implement a BLE-based communication system in which critical information of patients such body stats and signal strength from a wearable beacon are collected by scanners and gateways anchored on walls of the rooms. In the deployed system, the paper provides two main contributions for localization.
The first part of the paper ascertains the performance and limitations of signal strength-(RSS-) based localization in both nearly noise-free and realistic environments. Here, the paper studies the practicality of the BLE RSS-distance relationship between beacon and scanner on the performance of the localization. Based on experimental studies, the second part of the paper proposes a localization algorithm which was developed, implemented, and evaluated accordingly. The algorithm combines and uses the best parts of classic techniques such as geometric technique and fingerprinting for improved accuracy of localization within a small area such as a hospital room.
The remainder of this paper is divided as follows. Section 2 gives a background overview of indoor localization systems whereas Section 3 discusses various available techniques used in wireless-based indoor positioning systems. Section 4 describes the architecture of a communication system along with the hardware components used for localization. Section 5 examines the relationship between the strength of the BLE signal and the distance of the beacon from the scanner in a noise-free environment. Based on this evaluation, the localization process is proposed which is detailed in Section 6. Section 7 presents the evaluations of the proposed localization algorithm in terms of number of BLE scanners and number of BLE packets. In addition, comparative performance evaluations against other available techniques have been conducted as shown in Section 7. Furthermore, Section 8 discusses the performances of the proposed algorithm and other available techniques. Finally, Section 9 concludes the paper and mentions further improvements to be made in future works.

Background
In outdoor settings, global navigation satellite systems (GNSS) are usually employed in estimating the position of a target. However, there is an absence of such global standard in case of positioning in indoor spaces. For this reason, several research efforts have been made in deploying reliable indoor positioning systems (IPS). Localization of a device or subject in indoor spaces is one of the most important information required in several applications. Due to the widespread deployment of sensors, there has been an increased interest in acquiring and analyzing such large information.
The evolution of IPS techniques has been described and updated in several surveys [5][6][7]. These surveys examine various IPS techniques in terms of strengths and weaknesses depending on specific applications. Reference [7] makes a distinction between "technologies" and "techniques" where technologies in IPS are specific ways in using various types of signals such as ultrasound, magnetic fields, light, and radiofrequency (RF). On the other hand, "technique" refers to basic conceptual tools which, in principle, can be applied in most of the technologies.
For indoor localization, several technologies such as ultrasound and vision are being studied and developed to estimate the position of the people [8,9]. However, RF-based localization systems [10,11] have become very popular and suitable indoors, as they make use of the availability of the infrastructure of wireless communication. The amount of data that needs to be processed for wireless signal-based localization is computationally less expensive than that produced by more accurate sensors like RGB-D cameras or laser rangefinders. Location can be from various parameters of wireless signals, such as time of flight (ToF), angle of arrival (AoA), time difference of arrival (TDoA), or received signal strength (RSS). Nevertheless, the latter parameter is feasible in most commercial wireless technologies without hardware or software modifications. As RSS information can easily be measured with off-the-shelf equipment, it has become the basis for the most popular techniques for inferring the relative positions of nodes in the wireless network. A significant feature of radio transmission is that the signal strength decreases as the distance increases.
Despite its wide popularity, RSS could yield unpredictable received power values, particularly in indoor environments where random factors such as interference, attenuation, reflectance, and fading affect the radio signal propagation, which makes RSS-based ranging quite challenging especially in small spaces [12]. Hence, this paper attempts to analyze one of the main factors, i.e., fading in a nonreflective and noise-free environment, in order to mitigate this effect and improve the relationship between signal strength and distance.

Related Works
Several works depending on wireless signal strength for indoor localization can be broadly classified based on geometric and fingerprinting techniques. Geometry techniques locate the position of the target through simple geometry and known positions of anchored devices. Given at least three anchored devices, if distance to these anchored devices can be inferred from new RSS measurements, the location of the target can be easily calculated using simple geometry techniques such as hyperbolic and circular approaches. The hyperbolic approach converts the geometric problem in linear form and solves it through a closed form of the least square method [13,14]. On the other hand, the circular approach iteratively solves the optimization problem [15,16] through a gradient step.
Since most of the approaches assume a priori RSS-channel modelling based on estimated parameters of the channel model, the estimated model is usually a poor representation of the real RSS channel due to a limited number of measurements taken. Consequently, this challenge can be overcome either by modelling the environment adaptively or by using a more robust positioning technique against any model inaccuracies. Few previous techniques have been developed to calculate the channel model along with periodic updates during the localization process in order to minimize the errors caused by the poorly estimated propagation model [17,18]. Although these models describe the real propagation behavior with better accuracy, they are updated from a limited set of noisy measurements which still make the estimated model imperfect. Also, the cost required for updating the channel models is very high. Hence, techniques such as weighting are used to compensate for inaccuracies in distance estimation [16,19]. The proposed algorithm uses the weights which are inversely proportional to increasing distance estimation inaccuracies caused by the estimated RSS-distance model.
The fingerprinting approach refers to techniques which first collect samples of the measurements at known locations in the environment during the training phase. In the online phase, this collected dataset is then used to predict the location of new measurements. Compared to geometric approaches, fingerprinting techniques have demonstrated higher accuracies in practice [17,20,21]. However, most of the techniques are used for Wi-Fi-based devices where deployment is much less, thereby the fingerprint size is small. However, due to the bureaucracy involved in using the existing Wi-Fi, devices are not easily deployable in hospitals. On the other hand, with large deployment of BLE devices, the fingerprint size would be very large at each location and the cost for matching the new fingerprint with the database would very high. Plus, the database needs to be updated over time to curb the growing errors due to a changing environment.
Also, several works have focused on tracking devices which scan for signals coming from wall-mounted beacons. However, these works mainly focus on navigating the users carrying the scanning device for signals coming from a passive kind of infrastructure in indoor areas [7]. In this paper, our focus is to actively scan and locate the subjects wearing the BLE beacon which emits the signals to anchored BLE scanners. Such infrastructure is of active kind [7].
Unlike other works, this paper conducts a study on the feasibility aspect on the RSS-distance relationship which is highly used in RF-based IPS. After identifying the limitations, the paper introduces an improved localization system which can be used to localize subjects within small spaces. In the proposed technique, the accuracy of localization is further improved by selecting and combining the desirable elements from both geometric and fingerprinting approaches. In most available techniques, data from the BLE beacon are usually processed in given time intervals. Such localization process is driven by time. However, there are cases when critical information from the BLE beacon may not reach the scanner within a specified window frame. Lack of such information may affect the accuracy of the localization of target. Hence, the online part of the proposed localization algorithm is driven by events depending on the amount of received data itself. The following sections of the paper will explain how the proposed technique is developed, implemented, and evaluated.

Communication Architecture of the BLE Localization System
Due to the real-time characteristics and low-power consumption in active mode, the number of Bluetooth devices has dramatically expanded in the last seven years, especially after the introduction of a newly developed energy-efficient short-range wireless communication protocol known as BLE [22]. BLE was first introduced in 2010 as a part of the Bluetooth Core specification version 4.0, with a main goal in which all the applications require low current consumption and low implementation complexity [23]. From this, several products were being introduced like iBeacon and Estimate. All these products are easily deployable and are being used in indoor localization processes [24]. In this work, a 3rd party sensor device was used which not only emits BLE packets but also includes body stats sensor data such as accelerometer in the BLE packets which is very useful in gathering critical information of patients in hospitals. Figure 1 illustrates the overview of communication architecture of the proposed BLE localization system. The communication system has been designed to send data from a beacon worn by a patient or mounted on a walking aid to the central monitoring and cloud computing system via BLE fixed scanners (FS) and gateways (GW). The FS and gateway devices are anchored on the wall. The details of communication architecture can be divided into four parts as follows.
4.1. Data Advertisement. The primary function of BLE in mobile beacons is to advertise information about the current state of the device for diagnostic purposes, as well as its RSS value that can be processed to provide location information.

Journal of Sensors
For this kind of application, a tiny square-shaped IoT module called Sensor Tile (shown in Figure 2) is used which packs powerful processing capabilities leveraging an 80 MHz STM32L476JGY microcontroller and Bluetooth low-energy connectivity based on a BlueNRG-MS network processor as well as a wide spectrum of motion and environmental MEMS sensors, including a digital microphone [25]. The BlueNRG-MS component of that IoT module is a very low-power Bluetooth low energy (BLE) single-mode network processor, compliant with Bluetooth specification v4.1.
The beacon advertises "BLE AD pkt" packets in a user-specified advertising period at a user-specified transmission power. The broadcast packets follow the specifications designed by the company. The advertising period can be set in such a way that the battery life of the beacon can be extended, and the packets are consistently collected by FS devices. Each advertisement packet "BLE AD pkt" will contain a Universal Unique Identifier (UUID) of the beacon. In order to enable time synchronization on the beacon, the beacon will advertise as connectable. When a fixed scanner (FS) scans and infers from "BLE AD pkt," that beacon is advertising as connectable, and it will connect and update a correct time to the beacon's current time characteristic.

Data
Reception and Measurement. The IoT hardware used for beaconing functionality (Figure 2(b)) can also be configured to function as FS device which are anchored on walls. After timestamping the received "BLE AD pkt" packet, FS measures the signal strength of the received packet from the beacon and adds that information in the "BLE Info pkt" packet along with its own UUID and the timestamp of reception. To correctly timestamp the received packet from the beacon, both mobile beacon and FS devices receive time sync packets from the gateway which in turn updates its own real-time clock (RTC) from the network time protocol (NTP) server over Wi-Fi.

Data Transfer.
On the other side of the communication system, information collected by FS is then transmitted to a central cloud computing system through gateways. In this system, Raspberry Pi 3 Model B (shown in Figure 3) is chosen to function as a GW device which is the third-generation Raspberry Pi containing both IEEE 802.11n Wi-Fi and Bluetooth BLE v 4.0 [26]. The GW device communicates with FS devices through Bluetooth and can either measure received signal directly from the beacon or receive the information of that beacon via FS. Once received, the GW device either stores the data offline or sends data to a cloud computing system through Wi-Fi. After receiving the "BLE Info pkt" packet from the FS device, the GW device also timestamps received packets, adds its ID and timestamp to the "BLE Info pkt" packet, and relays as "Wi-Fi Info pkt" packet from FS to cloud service.

Cloud Computing.
To send the "Wi-Fi Info pkt" data packet to the Amazon Web Services (AWS) Cloud database, the GW device uses Message Queuing Telemetry Transport (MQTT) protocol which is a publish-subscribe-based messaging protocol. It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited [27]. The data packet is stored in a database at AWS cloud from which the localization algorithm can retrieve and process the data and determine the location of the beacon. All the known IDs and locations of the FS devices and GW devices will also be stored in the database.
Along with data storage, cloud computing enables the proposed localization system in analyzing and estimating the positions of beacons based on the data retrieved from the database. Finally, the estimated position of the targeted beacon will be mapped on a web interface with the help of information containing known positions of scanners placed in rooms.

Study of the Distance-RSS Relationship in an
Ideal Environment   Journal of Sensors arbitrary transmitter-receiver (T-R) separation is expressed as a function of distance as follows [28]: where η is the path loss exponent which indicates the rate at which path loss increases with distance d in a particular environment. The value for η depends on the specific propagation environment, i.e., type of construction material, architecture, and location within the building. The lower the value of η, the lower the signal loss. The values of η range from 1.2 (waveguide effect) to 6. In free space, η is equal to 2. Table 1 shows the path loss exponents for different environments. For realistic indoor localization of patients, η should vary from 1.6 to 4.3. d 0 is the reference distance to the transmitter, say 1 m for indoors (1 km for outdoors). χ σ is a normal random variable with zero mean, reflecting the attenuation caused by flat fading. In case of no fading, this variable is 0. In case of only shadow fading or slow fading, this random variable may have Gaussian distribution with σ standard deviation in dB, resulting in log-normal distribution of the received power in watts. For this work, we consider the log-normal path loss model. Usually, PL (d 0 ) is the calibrated and constant parameter PL 1 at 1 m. Hence, Equation (2) can be modified and be simplified to Path loss PL (dB) is defined [25] in the following equation: Equation (3) would result as If x = +10 log 10 d, m = n, b = PL 1 , and y = PL dB . Equation (5) = >y = mx + b in a log-log scale graph. From the experimental RSSI values of BLE packets at varying distances, a simple polynomial curve fitting model with 1 degree can be used to derive the values for PL 1 and η in a power-log distance scale graph. From that graph, these parameters can be used to determine the distance in the equation which is derived from Equation (5).
Experimental Analysis in an Anechoic Chamber. One of the main reasons for causing huge fluctuations in RSS values of transmitted signal from the beacon over time is the multipath propagation and interference of signals. In order to study the baseline relationship between the received signal strength (RSS) of the beacon and distance under an ideal transmission environment in which no reflections or any other additional noises of signals occur, data collection was conducted in an anechoic chamber as shown in Figure 4. In Figure 4(b), the beacon transmits the BLE signal at varying transmission powers across the room to the scanner which in turn stores the measured RSS values for the analysis. Bother beacon and scanner are maintained at the same height of 1.5 m. The distance between transmitter and receiver is varied between 0.6 m and 2.07 m (due to the limited size of the room) and are controlled by the chamber system's motors and software. At each distance and each transmission power of beacon, more than 2 minutes of samples were collected.
Also, the orientation of the beacon is rotated to six orthogonal orientations w.r.t the direction of the scanner in order to understand the effects of polarity difference in RSS values. For the latter part of the work, this study of RSS-distance can be used as reference for estimating the distance of the beacon by a scanner with better accuracy in any given environment. In this environment, the range of RSS is kept between the distances of the beacon and scanner at 0~2.07 m. For instance, Figure 5 displays the characteristics of RSS and more than 150 samples were recorded at each distance of 1 m and 2.07 m.
In Figure 5, RSS measurements presented obvious nonstationary characteristics over passage of time. Also, as the distance between beacon and scanner increases, the RSSI tends to fluctuate less frequently. In Sections 5.2.1-5.2.3, the paper will first examine the effects of orientation on distribution of RSS values at each distance. Based on the results from the distribution, RSS values are recorded according to the study of the overall relationship between RSS values of the signal from the BLE beacon and the varying distances between BLE beacon and scanner. The accuracy of the estimated model of RSS-distance of BLE devices will be evaluated against the actual distance. The data collection process for these three parts of Section 5.2 can be summarized into three configurations as presented in Table 2.

Distribution of RSS over Varying Orientations.
In this section, the dataset was collected according to experimental configuration 1 from Table 2. Figure 6 illustrates this dataset in the form of distribution of RSS values over varying orientations at each distance. At each distance, the scanner appears to record higher RSS values caused by certain orientations of the BLE beacon. In Figure 6, "side 1 and side 2" orientations of the beacon appear at higher RSS values at each 5 Journal of Sensors distance whereas other orientations are spread at the lower RSS values. This measurement shift in each orientation is due to the difference in polarity between transmitter and receiver antennas. This could be useful in incorporating the effects of the direction of the BLE beacon during formation of the RSS-distance model.
However, the current hardware in the BLE device for this paper does not have configuration to detect the orientation shift. Also, in real scenarios, the beacons worn by subjects will be constantly varying its orientations. Hence, it is important to constantly and randomly change the orientation of the mobile beacon for the purpose of studying the RSS-distance relationship in the current configuration of the BLE device.

Study of the Distance-RSS Relation over All Random
Orientations. For this study, experimental configuration 2 from Table 2 was implemented with each dataset containing a large sample size. On examining this dataset, the relationship between RSS-distance can be expressed as a path loss-log distance relationship by combining and reconfiguring Equations (4) and (5) as demonstrated in Section 5.1. Figure 7 shows the distribution of RSS values at each distance using Tx power as 2 dBm. RSS values are expressed as    Figure 7(a) shows the probability density (PD) over 1 dBm of path loss value and 1 log (m) of log distance. In that figure, higher probabilities of path loss (yellow values) appear to go linearly in log distance. At each log distance, the PD of path loss values appears to follow Gaussian distribution [28] as shown in Figure 7(b). Figure 7(c) demonstrates the shifts of fitted normal curves along the log distance. As the distance increases, the normal curve shifts towards larger path loss values. The peaks of the varying PD curves are represented by the mean of the distributions at varying distances. From the relationship between the peak of PD curves and log distances, the parameters for the RSS-distance model such as η and PL 1 can be derived by fitting the peaks with a polynomial of 1 degree as shown in Figure 7(d). η is found to be 1 9 ≈ 2 for a nonreflective ideal environment (anechoic chamber).
These derived parameters are then plugged into Equation (5) Figure 8(c), the estimation error is below 0.7 m at nearly 90% probability for lower distances. On the other hand, the estimation error for an actual distance of 2.07 m is below 1.5 m at 80% probability. Hence, it can be concluded that distance estimation error-based RSS values increase with increase in distance. This error can be used to compensate the estimated distances during localization in the real environment.

Study of the Distance-RSS Relation over Varying
Transmission Powers. The battery consumption of the BLE beacon is highly proportional to the Tx power. The higher the Tx power, the higher the battery energy the BLE beacon will consume. Hence, it is important to find the trade-off between distance estimation accuracy and transmission power. In the current BLE hardware, the maximum and minimum Tx power is 8 dBM and −18 dBm, Here, experimental configuration 3 from Table 2 was performed to generate 16 different datasets for this study. In Figure 9, the RSS-distance relationships are compared with respect to increasing Tx powers. RSS-distance curves tend to shift towards lower RSS values as Tx power decreases.
From those curves, the distances are estimated and its RMSE errors are compared in Figure 10. As concluded in Section 5.2.2, RMSE increases with increase in distance regardless of Tx power. In both Figures 10 and 11, the RSS-distance model w.r.t higher transmission power 8 dBm performs better. However, the power consumption of the BLE beacon will be very high at that Tx power level and the battery would last just a few hours. In order to reduce the cost of replacing/recharging batteries and maintain continuous tracking of BLE beacons, it is best to choose a lower Tx power level in such a way that the RSS-distance model still gives low overall RMS distance error estimation. Hence, −8 dBm Tx level is chosen for localization as its overall RSME error is 0.56 m.
In summary, it is important to maintain random orientations of the BLE beacon while estimating the RSS-distance model during initial scene profiling for the localization system. At lower distances below 2 m from the fixed scanner, the estimation error of the mobile beacon's distance is quite low. Hence, for rooms larger than 2 m in size, more than one fixed scanner is required to estimate the mobile beacon. Also, the Tx power level is to be fixed in such a way to maintain the trade-off between lower-energy consumption and higher-distance estimation accuracy.

Proposed Localization Algorithm
Here, we propose a localization algorithm which consists of two phases: (a) initial scene analysis and (b) online The RSS-distance model is estimated calculated w.r.t the given environment. The first phase of the algorithm is similar to the initial phase of the fingerprinting technique giving a better initial estimate during the online phase. Those specific grid locations in the room are clustered together w.r.t a single FS for the next phase. During the online phase, the algorithm collects RSS measurements from available FS devices till a maximum number of BLE packet threshold has been reached. After collection, the beacon's location is estimated by grid locations associated with the highest average RSS measured by the corresponding FS device. This estimate will then be fed to a least square (LS) optimizer with weights depending on the accuracy of the estimated distances from FS devices. LS optimization from geometric techniques refines the initial estimate of the beacon's position.
6.1. Experimental Setup. As part of development, implementation, and evaluation of the localization system, a testing room of size 6.87 m × 7.60 m was chosen for conducting experiments as shown in Figure 12. Here, the BLE signals are affected by signal reflections and additional noises caused by objects cluttered in the testing room. Four fixed scanners were placed on sides of the testing room at a height of 1 m from the ground. All 30 reference grid points are placed 1 m apart to ensure the exact position of the beacon while conducting the analysis. The distances of all reference points to four FS were measured precisely for comparison ranging from 0.2 to 6.8 m.
For the initial phase of the proposed localization, the beacon is placed on a cylindrical stand of height 1 m thereby maintaining the same elevation as fixed scanners. Another reason for measurements being collected at the height of 1 m is that it seems to be a natural position for wearables and walkers while being used by humans.  Journal of Sensors At each reference grid position where the beacon is placed, four scanners measure the RSS values from the beacon in different random orientations for two minutes in order to ensure statistical repeatability. The transmission power Tx of the beacon was set to be −8 dBm to maintain the trade-off between accuracy and energy consumption as summarized in Section 5. The dataset collection for the initial scene analysis of the proposed algorithm can be summarized in Table 3.
During the online phase, a subject holding the BLE beacon is made to stand at each specified grid while conducting performance evaluation which is detailed in Section 7. While standing at those positions, the subject is asked to continuously flip or swing the beacon to ensure random orientations for statistical repeatability.

Initial Scene Analysis.
After data collection at all 30 reference grid points, the RSS measurements collected from each reference point were sorted into four sets w.r.t fixed scanners and the RSS data was extracted for each set  Figure 13. In Figure 13, RSS mean values of beacon (Tx = −8 dBm) were mapped w.r.t the known reference grid location. On observation of this figure, the RSS mean values w.r.t each FS i are higher and hotter when the reference grid points are closer to that FS i Based on the radio map, the reference points, which show higher RSS values and are closer to fixed scanner, can be clustered and associated with the fixed scanner, respectively, as shown in Table 4. Hence, in the given room map, we can cluster the reference points into four regions. This section is quite useful for the initial stage of online localization when the beacon can be classified based on the set of RSS values.
In order to further pinpoint the position of the beacon within the cluster, it is important to model the distance estimation model based on RSS values. Since the devices involved in the RSS-distance model are the same, the mean of RSS data at each reference w.r.t each FS is plotted and fitted in a power-log distance graph as shown in Figure 14. In Figure 14, the parameters for Equation (5) were extracted from the graph and found to be = 1 26 PL 1 = 66 54.
These parameters are then plugged into Equation (5) as shown in Figure 15.
Based on the estimated RSS-distance model, the distance error estimation was calculated w.r.t each fixed scanner as shown in Figure 16. In future, the parameters of the RSS-distance model can be updated continuously by measuring RSS values from known FS devices by the GW device and    Figure 16, the distance estimation accuracy appears to decrease as the distance from the respective fixed scanner increases. These perturbations in distance values are caused by slow fading as shown in Equation (2). Based on Equation (2), the distance is modelled as log-normal random variable d. d~d ⋅ 10 N 0,σ = e N ln d,σ/10η 7 The parameters of log-normal random variable d are μ d = ln d and σ d = σ/10η. The k th moment of a lognormal random variable is given by E d k = exp k ⋅ μ d + k 2 σ 2 /2 [16]. Therefore, the variance of d is expressed as From Equation (8), the confidence of estimating the distance can be calculated and applied in the localization. Since distance estimation does not vary with σ 2 d , i.e., σ 2 d is constant, the factor exp 2σ 2 d − exp σ 2 d can be taken out and Equation (8) can be modified as Var d = exp 2μ d = exp 2 ln d = d 2 9 To further illustrate this point, Figure 17 shows how the estimated distances by four FS devices can be fitted with a curve from Equation (9). This variance graph can be used to calculate the weight for adjusting the accuracy of distance estimation while improving localization accuracy. By giving more weight to those measurements which have a greater accuracy, i.e., the measurements corresponding to short distances, a greater accuracy in localization result is expected.

Online Localization.
In most of techniques in the literature, events for localization are usually time-driven. However, there are chances that relevant information recorded by fixed scanners FS may not reach gateway GW within a specified window frame. Lack of such information may affect localization of the beacon at a critical time. Hence, the proposed online localization is data-driven based on the number of RSS values recorded and sent by any of the FS devices to the GW device. Once the number of packets sent by any FS devices reaches the set threshold MAX_NUM, the algorithm will then estimate the position of the beacon depending on the number of FS devices recorded during that event.
The initial estimate of the position of the beacon can be obtained from the previously estimated position of the beacon within a specified time period Thres_Time (usually set as 1-3 s). If the time difference between the latest packet received and the latest position of the beacon exceeds Thres_Time, the initial position of the beacon can be estimated by the position of the closest point from the cluster region corresponding to the nearest FS. The FS device with the highest measured mean RSS power is chosen as the scanner to which the beacon is closest. The corresponding Table 2  Table 1  Table 4    Next, within the cluster region, the distance of the beacon from the chosen FS device is estimated from the fitted model Equation (6). The estimated distance is then compared to the distances between the reference points of the region and the corresponding FS which are stored in the database. The position of a reference point from the cluster whose distance is closest to the estimated distance is chosen as the closest location estimate of the beacon within the selected cluster.
If the number of FS devices recorded is two or less, this estimate will be considered as the final position of the beacon. Else, this estimate can act as initial estimation to the following optimization problem.
The objective of the algorithm is to find position x, y of the beacon which minimizes the sum of weighted squared errors in the set of distance estimations d i from the position (x i , y i ) of the fixed scanner FS i i = 1, 2 … N . That is, error Equation (10) is to be minimized.   The position x, y of the beacon can then be calculated iteratively using any optimization algorithm. The algorithm uses limited-memory Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) which is popular for parameter estimation in machine learning.
The final estimated position of the beacon is then compared to previous estimated positions of the beacon. If the distance between the current estimate and the previous estimate is greater than Thres_distance (usually 3 m) within Thres_Time, the current estimate is most likely to be in error and it is best to consider the previous beacon position estimate as the current estimate. The proposed localization algorithm is summarized in Algorithm 1.

Experimental Analysis of Proposed Localization
To analyze the localization system, it is important to first acquire RSS measurements at known true positions. Generally, a good localization system should allocate high probabilities of estimates to areas surrounding the true location and as low as possible to farther locations given the sensor information. In this analysis section, the accuracy of the proposed localization algorithm is examined against the effects of number of sensors and the MAX_NUM threshold for the number of BLE packets captured by any FS device. The total number of packets recorded in each event is highly proportional to MAX_NUM. During data collection for evaluation (summarized in Table 5), the subject carrying the BLE beacon is made to stand at six selected locations in the testing room as highlighted in Figure 18. Only one subject was used; this section only evaluates the performance of the localization algorithm. The testing of the communication system is out of scope of this paper. These six locations represent the pathways through which the subject would walk. At each specified location, 8 minutes of the beacon's RSS data were recorded by all four FS devices while the subject randomly orients the beacon on the same spot to ensure more diversity in the dataset. This length dataset would be quite sufficient in evaluating the performance of the proposed localization algorithm.
Each RSS measurement from the beacon is also timestamped by measuring the FS device as mentioned in Section 4.2. These timestamps would be quite useful in enabling the same datasets for state-of-art comparisons.

Effects of the Number of FS Devices.
During the localization experiments for test scenario 1 (from Table 5) at those six selected locations, FS devices are added in the experimental room to examine its effects on the accuracy of the proposed algorithm as shown in Figure 19. For each experimental configuration in Figure 20, the proposed localization algorithm processes the same datasets collected at each selected location. The threshold MAX_NUM was set at 5. Figure 20 presents the performance evaluation of the proposed algorithm for each experimental configuration with results tabulated in Table 6. The proposed localization algorithm processing data from more than three FS devices shows higher probability in estimating the location of the beacon with error less than 2.8 m.
The performance of the algorithm processing two FS devices appears to be low due to placement of FS in the room with respect to the selected locations. Hence, for this large 13 Journal of Sensors experimental room (7.6 × 6.87 m), it is important to have 3 or more FS devices for beacon positioning.

Effect of the BLE Packet
Threshold. In order to study the effect of the total number of BLE packets used for localization, the MAX_NUM threshold in the proposed algorithm is varied during the experimental analysis described in test scenario 2 at Table 5. The MAX_NUM threshold is highly proportional to the total number of packets used in BLE beacon positioning. During the localization experiments at selected locations, the MAX_NUM threshold is increased to examine its effects on the accuracy of the proposed algorithm as shown in Figure 21 and Table 7. The number of FS devices used for this test scenario is four.
When the MAX_NUM threshold is set to 1, it means that the number of BLE packets (coming from any FS devices) processed by the algorithm during position estimation is 1. With this configuration, the accuracy error would be very high which is 4.2 m.

Journal of Sensors
As the MAX_NUM threshold is increased to 3 and 5, there is a slight decrease in localization accuracy error. On the other hand, when the MAX_NUM threshold is set at 7, there is huge improvement in localization performance. It is observed that the localization error is less than 1.80 m in 90% of cases. Furthermore, when the MAX_NUM threshold is set above 7, there is not much further improvement in localization performance.

Comparison of State-of-Art Localization Techniques.
In this section, the accuracy of our proposed algorithm is compared against four classic techniques used in indoor localization. The first technique estimates the position of the beacon based on the nearest FS device which is a proximity technique [29]. The second technique is based on hyperbolic technique described in [16]. The hyperbolic technique converts nonlinear error distance functions to linear form. It requires more than 3 sensors for beacon positioning. This technique is further improved in [18] with weights and then employed as a third technique for this paper.
The fourth technique is based on circular technique with no weights. The circular technique optimizes the multilateration problem through gradient decent. It performs Input: RSSI j,FS i corresponding to FS i (j corresponds to number of RSS values recorded by FS i ) Output: x, y k position of beacon at event k (1) The RSSI value of beacon packet is sorted into set RSSI j,FS i (2) If j of sets corresponding to any n FS devices reach MAX_NUM, Go to step 8 for next Event k = k + 1.
Else, go to step 1   15 Journal of Sensors better than the hyperbolic method as it minimizes directly the distance errors [16]. It requires more than 2 scanners for beacon positioning. Our proposed technique can work with 1 or more scanners depending on the size of the room.
For comparison evaluation, the dataset was collected according to test scenario 3 from Table 5. At each reference grid point, each dataset of BLE packets is scanned by four FS devices. All four FS devices were used in this testing room as most of state-of-art techniques require more than 3 scanners. These datasets can be processed for beacon positioning by all four state-of-art techniques including our proposed algorithm. Such steps would ensure fair evaluation of location performance for the comparison. Figure 22 shows an example of the estimation probability map generated by each approach at one of the testing points of position 4 where the estimation probability of the proposed approach is evidently much better. Usually, darker shades (higher probabilities) are near the true spot (marked in green spot) and light shades (lower probabilities) are the locations farther away from the true spot. In all four classical approaches, probabilities are found to spread over larger areas thereby making the beacon positioning less accurate with high uncertainty. On the other hand, the proposed approach generates higher probability over a very small area around the true position indicating higher accuracy with less uncertainty. In order to verify that the same likelihood occurred for the rest of the other five test positions, the same test was performed for all data points in all datasets available. The results of the evaluations for 90% of beacon position estimates for all 6 test locations are summarized in Table 8. Figure 23 displays the overall performance of the techniques for all test locations. With exception of test location 15, the performance of the proposed localization has consistently maintained the lowest cumulative error at all test locations. To our knowledge, the performance of the proposed algorithm at test location 15 may have gone down due to environmental factors such as user's body/object attenuation of signals.

Discussions
The tests performed in the anechoic chamber were conducted in order to study the factors affecting the baseline relationship between the strength of the BLE beacon's transmitted signal and the distance of the beacon from the scanner without the influence of reflections or additional noises which normally occur in a real environment. In Table 2, the distance of the beacon from the scanner varied up to 2.07 m due to the limited size of the available anechoic chamber. Nonetheless, the motivation of our paper is to localize the position of the subject wearing a beacon within small spaces. Also, on analyzing data from this experiment, three inferences were made which could be applied in a real environment. First, the orientation of the beacon does have significant influence on the RSS-distance relationship due to the difference in polarity between transmitter and receiver as shown in Figure 6. This could be useful in incorporating the effects of the direction of the BLE beacon during formation of the RSS-distance model. However, most of BLE devices including the selected hardware for this paper do not have configuration to detect the orientation shift. Moreover, the beacon worn by subjects will be constantly varying its orientation. Hence, during the initial scene analysis of our proposed algorithm or any real environment experiments on the RSS-distance relationship, it is important that the beacon should be constantly varied to ensure statistical repeatability while developing the RSS-distance model.
The second inference of this anechoic chamber experiment is that the RSS-distance model estimates the distance of the beacon with higher accuracy when the beacon is placed at distances less than 2 m from the scanner (Figure 7). This would be adequate in areas of size lesser than 2 m. However, in spaces with size more than 2 m, it will be quite challenging for the RSS-distance model to reliably estimate the position of the beacon. Thus, it is important that there should be more than 1 scanner placed in such spaces. Finally, the Tx power level of the beacon plays a significant role in estimating the beacon position. At higher Tx levels, the RSS-distance model provides better estimation of the beacon's position as demonstrated in Figure 10. However, the power consumption of the BLE beacon will be very high at high Tx power level thereby incurring higher costs in the maintenance of beacons in the localization system.    Therefore, there should be a trade-off between low energy consumption and high accuracy of distance estimation of the RSS-distance model.
The analysis of data from experiments in an ideal environment can be applied in a real environment as shown in Section 6. Along with tests conducted in an ideal environment, the paper also demonstrated the development of the RSS-distance model from the tests in a real environment as part of the initial scene analysis of the proposed algorithm. Figure 16 illustrates the distance estimation error of the extracted RSS-distance model w.r.t each scanner. As the distance of the beacon from the scanner increases (up to 7 m), the RSS-distance model estimates the position of the beacon with lesser accuracy thereby reinforcing the concluded evaluation from the ideal setup. Results in Figure 17 can be used to determine weights for adjusting the accuracy of distance estimation while improving localization accuracy in the proposed algorithm.
As described in Table 5, three types of test evaluations are conducted to analyze the performance of the proposed algorithm. The first two tests evaluate the performance of the proposed algorithms under the effects of number of FS devices placed in a room and number of BLE beacon packets processed by the algorithm. In Table 6, the accuracy of the  However, this is possible if the subject wearing a beacon is stationary for a long time. For the ambulatory subject, MAX_ NUM should not be set so high so that the position of the beacon can be updated on time. Instead, more FS devices can be added to compensate for lower MAX_NUM. Hence, a trade-off is considered while designing the system so that the accuracy of localization of the beacon is higher while correctly updating the position of the beacon. This trade-off can be referred in Figure 24. For the experimental room, the localization error from the proposed algorithm is low when MAX_NUM threshold = 7 and the number of FS devices anchored in a room is four.
The third type of test evaluation was conducted to compare the performances of the proposed algorithm against other state-of-art localization techniques as illustrated in Table 8.
The nearest scanning device approach [29] helps in identifying the position of the beacon if the beacon is closest to one of the scanners. However, this does not exactly pinpoint the exact location of the beacon, especially in small spaces. Hence, this technique performs poorly as localization error is less than 4 m in 90% of beacon position estimates.
In this comparative analysis, the hyperbolic approach [16] requires more than three FS devices to position a beacon. The reason for low performance of the hyperbolic approach in Table 8 is that the process in optimizing linear equations is highly susceptible to noisy RSS measurements. To compensate for inaccuracies in distance estimation caused by inaccurate models from noisy measurements, weights were introduced in the weighted hyperbolic technique. This led to a slight improvement in the localization of the beacon at all six test positions as shown in Table 8.
On the other hand, the circular technique [16] solves the beacon position problem by directly optimizing the nonlinear distance equation in the form of cost minimization. This optimization solver requires the initial estimate of the beacon which is usually estimated from the proximity approach. This greatly improves the performance as shown in Table 8 and Figure 23. The circular technique appears to perform better with localization error less than 3 m with nearly 90% probability, thereby confirming the superiority of circular technique over hyperbolic technique.
However, it is important that the initial estimate of the beacon position is closer to the true estimate. If the initial estimate is far from the true value, the optimization solver may not estimate the final position correctly. Therefore, in the proposed approach, the initial estimate of the beacon position is computed from the initial scene analysis which is usually employed in fingerprinting methods. The fingerprinting technique usually demonstrates a very high performance as mentioned in Section 3. Using this improved initial estimate, the proposed approach further perfects the beacon's position estimate with the help of weighted squared error optimization.
Also, most of the available state-of-art techniques are usually time-driven; i.e., they depend on the window frame. One of the main disadvantages for the time-driven system is the loss of information required for beacon positioning. To overcome this challenge, the proposed algorithm is designed to be driven by data based on the threshold set for the number of BLE packets received. Finally, on comparison to other evaluated techniques, the proposed approach has performed very well with an overall lowest error less than 1.8 m in all test locations.

Conclusion and Future Work
The analysis of signal strength w.r.t distances between beacon and scanners was studied in both ideal and real