# Using Fuzzy Logic to Improve BLE Indoor Positioning System

Sérgio Onofre, Bernardo Caseiro, João Paulo Pimentão, Pedro Sousa

► To cite this version:

Sérgio Onofre, Bernardo Caseiro, João Paulo Pimentão, Pedro Sousa. Using Fuzzy Logic to Improve BLE Indoor Positioning System. 7th Doctoral Conference on Computing, Electrical and Industrial Systems (DoCEIS), Apr 2016, Costa de Caparica, Portugal. pp.169-177, 10.1007/978-3-319-31165-4_18. hal-01438241

HAL Id: hal-01438241

https://inria.hal.science/hal-01438241

Submitted on 17 Jan 2017

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Using Fuzzy Logic to Improve BLE Indoor Positioning System

Sérgio Onofre<fnref n="1" />, Bernardo Caseiro<fnref n="2" />, João Paulo Pimentão<fnref n="2" /> and Pedro Sousa<fnref n="2" />,

**Abstract.** Accuracy and precision are key parameters in the definition of indoor positioning systems. We want to provide a mobile robot with the capacity to autonomously determining its location inside buildings, to allow it to autonomously navigate. The solution developed is based on spreading emitter beacons of Bluetooth Low Energy in the building and use location finding techniques to determine the robot's location. The main challenge is the capacity to obtain accurate readings of signal strength and the low repeatability of readings even under unchanged conditions. To improve the signal strength measurements it is necessary to deal with this imprecision. Our approach is based on the use of Fuzzy Logic to deal with the accuracy problem. Once better signal strength readings are achieved, using this method, approximate distances are calculated based on signal strength and the trilateration method is implemented to provide the location of the mobile robot.

**Keywords:** Fuzzy Logic, indoor location techniques, Bluetooth low energy, trilateration.

## 1 Introduction

Indoor location is an emerging market that can be used for commercial purposes, public safety, and military. Commercially it can be applied to track children, people with special needs, help navigate blind people, locate equipment, mobile robots, etc. For military and public safety it will be useful to track prisoners, help policeman, soldiers and firemen navigate inside buildings [1].

Location and outdoors navigation was solved long ago with GPS. The problem occurs when you need accuracy or indoors location. GPS nowadays have an error of about 10 meters, radio signals coming from distant satellites don't work well with obstructed paths and the high-frequency waves bounce around when they hit metal and walls. This technology is therefore not usable on indoor location issues [2].

Actually there are some companies searching and testing solutions using different technologies to find a solution for indoors location. In general, the most important components of the system are location sensor devices that produce metrics of the relative position of a mobile terminal (MT) and a known reference point (RP). Most

<footnote n="1">¹ Holos SA, Caparica, Portugal, onofre@holos.pt</footnote>

<footnote n="2">² Faculty of Sciences and Technology NOVA University of Lisbon,
Monte de Caparica, Almada 2829-516 Portugal</footnote>

<footnote>b.caseiro@campus.fct.unl.pt, {pim, pas} @fct.unl.pt</footnote>

<footnote n="1">¹ http://servrobot.holos.pt</footnote>
conventional positioning methods are Angle of arrival (AOA) to estimate direction;
received signal strength indicator (RSSI), Time difference of arrival (TDOA) and
Time of arrival (TOA) are used to estimate distance [1].

Our goal is to provide a mobile robot (ServRobot¹) with a tool to know its location
using Bluetooth Low Energy beacons signals.

## 2 Cyber Physical Systems

The cyber-physical systems (CPS) consider computational components and physical
units to cooperate with humans using different technologies. CPS are intelligent, real-
time, distributed, networked (wired/wireless) control systems and likely linked in a
loop. They can be useful in several fields. CPS design consists of a network of
cooperating elements with physical inputs and outputs. It connects computational and
physical rudiments to obtain better effectiveness, functionality, security and flexibility
[3].

This work is related to cyber-physical systems, by combining physical entities: Bluetooth Low Energy (BLE) beacons, with computational elements that through a BLE signal receptor connected to a computer, allows to process the input values and implement algorithms to build the desired system. The final goal is to locate an autonomous mobile robot in a wireless network in real time that could be adapted in the future to locate other objects like phones or even people. It consists on build a system in real-time with feedback loops where physical processes, in this case the received signal strength indicator from the BLE beacon affect computations and have influence on the robot next moves and upgrade others functionalities by knowing the robot location, it can improve the efficiency, safety, reliability and functionality of the mobile robot.

This project could help the research on efficient and functional indoor location
systems contributing for the cyber physical systems development too.

## 3 State of the Art

### 3.1 Conventional Positioning Methods

In the next sections, several conventional positioning methods are presented.

**RSSI** – It is a process used to estimate the distance between the receiver and a beacon. It matches the probability distribution with the strength of the received signals, and estimates the distance using a statistical method. To start a sample of the signal strength is read in different locations, but the environment changes modify the path loss models that enables to repeat the same strength of the received signal. It is necessary an environment precise path loss model to use the location estimate system [4].
**AOA**- This method is used to measure the direction in a system and it can do it reading the direction of the received signal using two or more antennas on different positions [4].

**TOA** – It is a time-based positioning technique that measures the signal travel time between nodes [5].

**TDOA** – This method estimates the time difference of arrival between two signals moving between two reference nodes and the given node [5].

Table 1 compares the accuracy degradation of an indoor location system due to multipath fading and increase of the distance between devices for each positioning method.

<table><caption>**Table 1.** Comparison of position methods [5]</caption><thead><tr><th rowspan="2">Method</th><th colspan="2">Accuracy Degradation</th></tr><tr><th>Multipath</th><th>Distance</th></tr></thead><tbody><tr><td>TOA/TDOA</td><td>Slightly</td><td>None</td></tr><tr><td>AOA</td><td>Slightly</td><td>Slightly</td></tr><tr><td>RSSI</td><td>Severely</td><td>Slightly</td></tr></tbody></table>

## 3.2 Indoor Location Systems

There are different location determination systems and processes for indoor environments: ultrasound, infrared, electromagnetic, visual location, physical contact and radio frequency systems. We will focus on radio frequency systems.

**Bluetooth based systems** - Radio hardware (beacons) with Bluetooth low energy protocol. Beacons are spread over surface and the signals that they send can enable devices to determine their location. Some systems use beacons signal to incorporate on fingerprints database, others determine absolute or relative location by measuring distances, trilateration. Furniture and walls hinder signal propagation. Using three beacons is enough but a fourth one will decrease localization errors [6]. Indoor location is challenging because of the reflections and absorptions. Besides Bluetooth Low Energy there are Wi-Fi, RFID, ZigBee and Ultra-Wideband based systems. More details in [7, 8, 9]. Some developers combine multiple technologies like fusing data based on Wi-Fi and Bluetooth. Fusing helps to obtain more accurate results.

<table><caption>**Table 2.** Radio frequency based systems [10]</caption><thead><tr><th></th><th>Frequency band</th><th>Power consumption</th><th>Cost</th><th>Accuracy (meters)</th></tr></thead><tbody><tr><td>Wi-Fi 802.11</td><td>2.4 GHz</td><td>high</td><td>high</td><td>5 to 10</td></tr><tr><td>RFID</td><td>Multiple</td><td>low</td><td>very low</td><td>2 to 10</td></tr><tr><td>Bluetooth 4.0</td><td>2.4 GHz</td><td>low</td><td>low</td><td>1 to 2</td></tr><tr><td>ZigBee</td><td>Multiple</td><td>low</td><td>low</td><td>3 to 5</td></tr><tr><td>UltraWideBand</td><td>3.1 to 10.6 GHz</td><td>low</td><td>low</td><td>&lt; 2</td></tr></tbody></table>
## 3.3 Location Techniques in Indoor RF-based Systems

There are two types of techniques to calculate the location using RF-based systems, geometric (traditional) and pattern recognition.

**Geometric techniques** - calculate positions based on distances between mobile transmitter-receiver and fixed receiver-transmitter. *Trilateration* - Provides an estimate of the device's location by using the received signal strength from different transmitters (non-linear). The distance estimation from the transmitters to the receiver is calculated using the relation between distance and signal strength:

$$ Pr = Pt + 20 \log \left( \frac{\lambda}{4\pi} \right) + 10n \log \left( \frac{1}{d} \right) \quad (1) $$

Pt is the transmitters power (in dBm), Pr is the power at the receiver, λ is the wavelength, n is the path loss exponent (n=2 is free space), d is the distance transmitter/receiver. The distance estimation generates a circle centered on each transmitter, the device will be located where circles coincide. The technique is called trilateration [11]. *Triangulation* - Uses geometric properties of triangles to estimate the target's location. More details in [11].

**Pattern Recognition techniques** - It consists in buildin a signal strength model. To estimate the mobile device's location is necessary to calculate the match with the signal strength model. It requires two phases: the offline phase, where a map is built after collecting the RF signals from defined location points. And the online phase, where an algorithm is used to find the match between the read signals and the previously collected signals to estimate the device location [5].

Traditional methods are K-Nearest Neighbors, Neural Networks and Probabilistic. More details in [12].

## 3.4 Fuzzy Logic

Fuzzy Logic is bets fit on under uncertainty, it deals automatically with tolerance for imprecise values. The variables are represented by membership functions, instead of the absolute true or false values. It reproduces the human mind capacity to employ approximate reasoning. In classic logic the decision is binary, true or false, whereas in Fuzzy Logic variables have a range between 0 and 1, of degree of membership towards a fuzzy set [13]. Imprecise inputs can be considered and used as “linguistic variables” denoting values such as big and small, low/medium/high are used in the model. Common membership functions used in Fuzzy sets are triangular, Gaussian, trapezoidal, etc, although triangular (see fig.2) is more widely used.

<figure><img src="image_2.png" /><figcaption>**Figure 2.** Triangular Fuzzy membership function [13]</figcaption></figure>

<figure><img src="image_3.png" /><figcaption>**Figure 3.** Fuzzy Logic Block diagram[13]</figcaption></figure>
Figure 3 shows the block diagram of fuzzy logic mechanism. Fuzzification is a procedure that classifies numerical values into fuzzy sets, the rule base contains the IF-THEN rules that represent the linguistic variables. The evaluation relates the IF-THEN rules to the fuzzy sets to get a fuzzy output. The Fuzzification changes crisp data into linguistic values using linguistic variables, membership functions map every element of the input variables onto a membership rate from 0 to 1. The evaluation makes approximate reasoning [13].

The defuzzification procedure alters the fuzzy output back to the classical output with the control goal. There are three defuzzification techniques normally used, the most widely used is the Center of Gravity method (COG) is identical to the physical calculation of center of gravity in objects, the weighted average of the membership function of the center of the gravity of the area limited by the membership function curve is computed to be the crispest value of the fuzzy values. Besides COG there are Mean of Maximum and Height Methods [13].

# 4 Development

Our system development starts with the interaction between a BLE transmitter (beacon) and the BLE receptor (sniffer).

## Bluetooth low energy sniffer and beacon

To receive the received signal strength indicator (RSSI) from the beacons a Bluetooth low energy sniffer (Adafruit bluefruit LE Sniffer nRF51822) is used. This device is a USB-to-BLE board that allows the computer to communicate with a BLE enabled device. The Gimbal U-Series 5 proximity beacon is a small, USB powered device that transmits a Bluetooth Low Energy signal that can be detected by other devices, in this case by the Bluetooth Low Energy sniffer. This signal enables the identification of the beacon by the MAC Address. The sniffer captures the RSSI value and with it it's possible to calculate the distance estimation between the devices.

## Obtaining distance from RSSI values

The code used by the device Adafruit bluefruit LE Sniffer nRF51822 is written in python and allows to retrieve the RSSI and MAC address of nearby BLE beacons, this project uses that code as start point. To obtain the distance in meters from the received signal strength indicator (RSSI) it was necessary to measure a bunch of RSSI measurements at known distances, then we did a best fit curve to match the data points, this algorithm was developed by David Young in Java. In this work the code was adapted to python language [14].

$$ distance = \begin{cases} \frac{(RSSI)}{txPower} & \text{for } \frac{(RSSI)}{txPower} < 1 \\ 0.09976 \times \frac{(RSSI)}{txPower} & + 0.111 \text{ for } \frac{(RSSI)}{txPower} \ge 1 \end{cases} \quad (2) $$

The variable txPower is the RSSI value at 1 meter of distance, it was calibrated and the obtained value was -87 db. The values 0.89976, 7.7095 and 0.111 are the three constants calculated when solving for a best fit curve to the measured data points. Each 0.95 seconds a distance reading is received, the main challenge is the capacity to
obtain accurate readings of signal strength (and consequent approximate distance in meters) given the low repeatability of readings even under unchanged conditions. The direct signal strength measured by the Bluetooth signal receiver vary in each reading because of physical disturbing factors such as wall reflections and other devices transmitting the same frequency. To improve the measures, two normalizing techniques: "median and average filters" and "Fuzzy Logic" were implemented.

## Median and Average Filters

After some tests comparing the real distance measured with a scale and the distance obtained at the program by the sniffer it was detected that the accuracy is bad and has low repeatability of readings. To try to improve the accuracy and the repeatability, a way to discard the absurd values on was developed. First a vector accumulates ten measurements and after that the values are sorted, the extremes are excluded and the four middle values are used to calculate the average. However, as the results were still far from good, since they were imprecise we decided to use another approach. Using Fuzzy Logic to deal with imprecision.

## Fuzzy Logic implementation

To deal with imprecise values we decided to use Fuzzy Logic. This could be a good way to improve the results. The tool used was an open source java library called jFuzzyLogic. This library imports a Fuzzy control language file with the input and output variables and the linguistic terms configured, then checks the rules to return an output variable based on inputs. We take the results of the median process and in the end it will return only one output variable with the final value. For each of the four inputs there are twelve linguistic terms possibilities to do the fuzzification ranging from "less 0.5m" to "more 5m". Then the system will check the rules block with 23 rules and makes the decision (Fuzzy inference). To finish the defuzzification is done and a real value is obtained as output. Considering ten direct distance measures read by the sniffer at 1 meter away from the beacon (real distance), the four middle values are selected as inputs for the FCL file and each of them is fuzzified. Then the system checks the rules block, makes the decision and does the defuzzification to obtain a real value as output. In our test the final distance output is 1.02 m, close to the real distance 1 m. The defuzzification technique, Center of Gravity method was used.

## Distance readings results

Three different ways to obtain the distance between the BLE beacon and BLE sniffer were tested in an office room without objects between the devices. The first method uses direct distance readings each 0.95 seconds, the second method applying median and average filters after ten direct readings and third method implements a fuzzy logic inference system after ten direct readings. The BLE beacon was fixed on a power supply and the BLE sniffer connected to a computer was positioned at different distances measured by a scale at 0.5m, 1m, 1.5m, 2m, 2.5m and 3m. The test values were obtained ten seconds after fixating the BLE sniffer position to guarantee receiving a stabilized signal. The following graphics compare the measurements obtained by the three methods:
<figure><img src="image_4.png" /><figcaption>Figure 4. Distance Estimations at 0.5 meters</figcaption></figure>

<figure><img src="image_5.png" /><figcaption>Figure 5. Distance Estimations at 2.5 meters</figcaption></figure>

<table><caption>Table 3. Average error for each method at different distances</caption><thead><tr><th></th><th>0.5m</th><th>1m</th><th>1.5m</th><th>2m</th><th>2.5m</th><th>3m</th></tr></thead><tbody><tr><th>Direct Readings</th><td>0.101</td><td>0.148</td><td>0.096</td><td>0.449</td><td>0.285</td><td>0.194</td></tr><tr><th>Median</th><td>0.082</td><td>0.235</td><td>0.252</td><td>0.300</td><td>0.306</td><td>0.243</td></tr><tr><th>Fuzzy Logic</th><td>0.028</td><td>0.115</td><td>0.136</td><td>0.050</td><td>0.118</td><td>0.193</td></tr></tbody></table>

## 5 Conclusions and Future Work

After doing these tests with the three methods some behaviors of the receiving signal were detected. The signal takes some time to stabilize after changing the distance between the beacon and the sniffer. It is necessary to wait some seconds until the values get closer to the real distance. Once the signal stabilizes the repeatability increases. In general as the distance between the beacon and the sniffer increases, the average error of distance estimations increases. That is an expected behavior because the disturbing factors like signal reflecting rise their negative influence as long as the direct signal wave power (the desired one) gets lower.

Comparing the direct readings average error and the estimations after applying median and average filter average error, the results of applying the filter are not as good as expected. That can be explained because even maintaining the sniffer at same fixed position when the distance estimation gets high or low it tends to still get higher
or lower with time. The normalizing factor by applying median and average filter excludes the estimations that usually are far from real distance, but due to the trend to the estimation to get high or low with time, it doesn't improve the average error. In practice the average error obtained by direct readings method is similar to the average error applying median and average filter. Comparing the direct readings average error with the Fuzzy Logic inference system estimations average error, the implementation of Fuzzy Logic reduces the error between real distance and estimation, improving the accuracy and the repeatability. This normalizing method proved to be more satisfying than Median and Average method. It proved to be useful improving the estimation values and Fuzzy Logic inference system was adopted in this project. The next step will consist in implementing the trilateration algorithm after obtaining the estimated distance between three fixed BLE beacons in known positions at x, y coordinates and the BLE sniffer which is in an unknown position and can move.

## References

1. Pahlavan, K., Li, X.: Indoor Geolocation Science and Technology. 112–118 (2002)

2. New Indoor Navigation Technologies Work Where GPS Can't - IEEE Spectrum. URL (consulted 2014), http://spectrum.ieee.org/telecom/wireless/new-indoor-navigation-technologies-work-where-gps-cant

3. Reddy, Y.: Cyber-Physical Systems: Survey Cloud-based Cyber Physical Systems: Design Challenges and Security Needs. (2015)

4. Park, C., Park, D., Park, J., Lee, Y., An, Y.: Localization Algorithm Design and Implementation to Utilization RSSI and AOA of Zigbee. 5th International Conference Future Information Technology., 1–4 (2010)

5. Roxin, A., Gaber, J., Wack, M., Nait-Sidi-Moh, A.: Survey of Wireless Geolocation Techniques. 2007 IEEE Globecom Work., 1–9 (2007)

6. Akif, M., Mahallesi, E., Ankara, Y.: A Bluetooth Signal Strength Based Indoor Localization Method

7. Kaemarungsi, K., Krishnamurthy, P.: Modeling of Indoor Positioning Systems Based on Location Fingerprinting, (2004)

8. Liu, Y., Du, H., Xu, Y.: The Research and Design of the Indoor Location System Based on RFID. 2011 Fourth Int. Symp. Comput. Intell. Des., 87–90 (2011)

9. Fernández, S., Gualda, D., García, J. C., García, J. J., Ureña, J., Gutiérrez, R.: Indoor Location System based on ZigBee devices and Metric Description Graphs, (2011)

10. Li, H.: Low-Cost 3D Bluetooth Indoor Positioning with Least Square. Wireless Pers. Commun., vol. 78 1331–1344 (2014)

11. Liu, H., Member, S., Darabi, H., Banerjee, P., Liu, J.; Survey of Wireless Indoor Positioning Techniques and Systems, vol. 37 1067–1080 (2007)

12. Lin, T., Lin, P.: Performance Comparison of Indoor Positioning Techniques based on Location Fingerprinting in Wireless Networks, 1–6 (2005)

13. Singh, A. K., Purohit, N., Varma, S.: Fuzzy logic based clustering in wireless sensor networks: a survey. Int. J. Electron., 1–16 (2012)

14. Young, D.: Understanding ibeacon distancing - Stack Overflow. URL consulted (2015), http:// stackoverflow.com/ questions/20416218/understanding-ibeacon-distancing