If you have heard about *iBeacons* or indoor localization before, then you have probably also heard about *RSSI*: the **Received Signal Strength Indicator**. The RSSI value resembles the power of a received radio signal (measured in *dBm*). The higher the RSSI value, the higher the signal strength. The rationale behind using RSSI values is that almost all wireless systems report and use this value natively; i.e. no additional sensors are required to measure RSSI values. It can therefore be considered as a free input to a system.

Small Mac OS tip: Try clicking on your WiFi icon in the navbar while holding alt (or option in Mac OS terms). You will see the current RSSI of your connection (only when you are connected to a network!).

**So what can we do with RSSI?** Well, there is a relation between RSSI and distance (see also Figure 1). As you can probably imagine: the larger the distance between you and the sender of a signal, the lower the signal strength will be. While many researchers question the usability of RSSI measurements in general^{1}, I’ve used them extensively (and with success) for indoor localization purposes. In this article I will show you how to use RSSI measurements and, maybe even more important, to remove noise from the raw data using Kalman filters.

Figure 1:RSSI measurements over time. The received signal strength of a device is clearly influenced by distance but the amount of noise is substantial. For this plot, a bluetooth device was set up as a iBeacon to continuously broadcast its unique identifier. Another bluetooth device was placed at various distances from the beacon and acted as a recording device. With a 1Hz sample rate RSSI values were sampled. For the ‘room’ case, the beacon was placed in an adjacent room to show the effect of walls.

## From RSSI to meters

RSSI is measured in *dBm* but is in its raw form not really useful in an application (apart from being a diagnostic measurement). The nice thing about RSSI is that we can translate the measurements to distance estimates in meters. More precise, we can describe the relation between RSSI and distance using a model, the *Log-Distance pathloss model*^{2}:

\begin{equation} \text{RSSI} = -10n \log _ {10}(\frac{d}{d _ {0}}) + A_{0} \end{equation}

In this model, $d$ describes the distance between the transceiver and recipient, $n$ the signal propagation exponent and $A _ {0}$ a referenced RSSI value at $d _ {0}$. Usually $d _ {0}$ is taken to be 1 such that $A _ {0}$ becomes the signal strength measured at a distance of 1 meter of the device.

$A _ 0$ can usually be retrieved from the device itself as it is often part of the broadcast message. Alternatively, you can approximate $A _ 0$ by collecting data and averaging the signal strength measurements. The signal propagation exponent $n$ is a constant that differs from environment to environment. For indoor applications, $n$ is often set to $2$.

Figure 2:RSSI converted to distance in meters using the Log-distance pathloss model. Source of the data is the same as in Figure 1. Note that the distance estimations are roughly correct but contains a lot of noise.

## Fighting noise

Okay, we can translate RSSI to distance, but our estimates are still not very good. As shown in Figure 2, at some point in time (roughly around t=29) our RSSI-based estimate states that the device should be 16 meters away, when in fact it is at a 1 meter distance.

Where does this discrepancy come from? Following our model, in an ideal world, the RSSI value is only dependent on the distance between the two devices. In reality, however, RSSI values are heavily influenced by the environment and have, consequently, high levels of noise. This noise is, for example, caused by multi-path reflections: signals bounce against objects in the environment such as walls and furniture.

So, **we need to fight the noise**. Here *Kalman filters* come in to play.

The Kalman filter is a state estimator that makes an estimate of some unobserved variable based on noisy measurements. It is a recursive algorithm as it takes the history of measurements into account. In our case we want to know the true RSSI based on our measurements. The regular^{3} Kalman filter assumes linear models. That is, the step from the current state to the next state, and the translation from state to measurement should be linear transformations.

The general form of the transition model is as follows:

\begin{equation} x _ {t} = A _ {t}x_{t-1} + B _ {t}u _ {t} + \epsilon _ {t} \end{equation}

The current state $x _ t$ is defined as a combination of the previous state $x _ {t-1}$ (given some transformation matrix $A$), a control input $u$ (this could be a movement command in a robot) and noise $\epsilon$. THe noise is called the *process noise*: noise caused by the system itself. *Don’t worry if this looks daunting, we will simplify this formula shortly. Hold on!*

For our RSSI filtering application we assume that a device doesn’t move. Moreover, we assume that in the time frame of our measurement our own position is also static. In other words: over time we expect a constant RSSI signal, everything else is noise. To apply this to our model we completely ignore $u$ and set $A$ to an identity matrix. These two changes result in a very simple model:

\begin{equation} x _ {t} = A _ {t}x _ {t-1} + B _ {t}u _ {t} + \epsilon _ {t} \approx x _ {t-1} + \epsilon _ {t} \end{equation}

The second part of implementing the Kalman filter is defining the observation model: how does a particular state $x$ result in a measurement $z$? The general model is as follows:

\begin{equation} z _ {t} = C _ {t}x _ {t} + \delta _ {t} \end{equation}

Here $C$ is the transformation matrix and $\delta$ measurement noise (noise caused by faulty measurements). We model RSSI directly; i.e. our state and measurements are equal. This results in the following reduced measurement model:

\begin{equation} z _ {t} = C _ {t}x _ {t} + \delta _ {t} \approx x _ {t} + \delta _ t \end{equation}

## Updating the filter

With our two transitions defined we can define the prediction step of the Kalman filter. This step describes what we expect our state to be without using any measurements. As we assume a static system our prediction step is straightforward:

\begin{equation} \bar\mu _ t = \mu _ {t-1} \end{equation}

\begin{equation} \bar\Sigma _ t = \Sigma _ {t-1} + R _ t \end{equation}

Note the difference between $x$ and $\mu$: $\mu$ describes our prediction and $x$ the true value of the state. The bar above the $\mu$ denotes that we yet have to incorporate information from the measurement. $\Sigma$ defines the certainty of our prediction. We base this on the previous certainty (if we were unsure about the previous measurement, the next one will be unsure too) and the process noise $R$ which describes noise caused by the system itself. For the RSSI example we use a low value for the process noise (e.g. 0.008); we assume that most of the noise is caused by the measurements.

Using our prediction estimate we compute the Kalman gain. For our static system we have a simplified version of the normal Kalman gain:

\begin{equation} K_t = \bar\Sigma_t (\bar\Sigma_t Q_t)^{-1} \end{equation}

The gain is used as a weighting function between the certainty of our estimate and the certainty of the measurement (influenced by the measurement noise $Q$). $Q$ is set to a value that relates to the noise in the actual measurements (e.g. the variance of the RSSI signal).

When we are very uncertain about our prediction of the system (i.e. $\Sigma$ is large) we should trust the measurement more. Likewise, if the measurement noise is low (i.e. $Q$ is low) it is also wise to use those measurements. In these cases the Kalman gain will be high. At the other side, if we are very certain about our prediction of the system and/or the measurement noise is low the Kalman gain will be low. This translates directly to the update step:

\begin{equation} \mu_t = \bar\mu_t + K_t(z_t - \bar\mu_t) \end{equation} \begin{equation} \Sigma_t = \bar\Sigma_t - (K_t \bar\Sigma_t) \end{equation}

In the update step we compute the final prediction of the system ($\mu$, without the bar) and the certainty $\Sigma$. The larger the Kalman gain the more we integrate the measurement into our state estimate. If the Kalman gain is low we trust our prediction more and only use little information of the measurement.

Try to imagine how this characteristic results in a filter: On every step, the Kalman filter decides how much of the measurement it takes in to account based on the certainty of the measurements and our state.

## Putting the filter into practice

We defined our model, we defined the filter. Now it is time to put the filter to a test. Does our Kalman fitler remove the noise from the raw RSSI signal?

I applied a simple Kalman filter to the “1m” data of the RSSI example dataset. I am using my KalmanJS library which you can find on GitHub or read more about in a separate post on this blog. The results are shown in the figure below:

Figure 3:The effect of a Kalman filter on raw RSSI data sampled from a static device (i.e. no movement at both the receiver and transmitter end). The Kalman filter removes a large part of the noise from the signal.

By using a Kalman filter we are able to remove noise from a very noisy signal. As the update functions are easy to compute the time complexity of the filter is very low; this results in a high performing system. The only drawback is that we lose a bit of responsiveness, but get a clearer signal in return!

Any questions or comments? Please see the comments section.

## Reference

This project/post was part of my research on indoor localization. Please see my paper or this presentation for more information. You can use the following reference if you want to cite my paper:

W. Bulten, A. C. V. Rossum and W. F. G. Haselager, “Human SLAM, Indoor Localisation of Devices and Users,”

2016 IEEE First International Conference on Internet-of-Things Design and Implementation (IoTDI), Berlin, 2016, pp. 211-222. doi: 10.1109/IoTDI.2015.19 URL

Or, if you prefer in BibTeX format:

```
@INPROCEEDINGS{7471364,
author={W. Bulten and A. C. V. Rossum and W. F. G. Haselager},
booktitle={2016 IEEE First International Conference on Internet-of-Things Design and Implementation (IoTDI)},
title={Human SLAM, Indoor Localisation of Devices and Users},
year={2016},
pages={211-222},
keywords={RSSI;data privacy;indoor environment;ubiquitous computing;FastSLAM;RSSI update;SLAC algorithm;device RSSI;device indoor localisation;device location;device position;environment noise;human SLAM;nontrivial environment;received signal strength indicator;simultaneous localisation and configuration;smart space;user indoor localisation;user motion data;user privacy;Estimation;Performance evaluation;Privacy;Simultaneous localization and mapping;Privacy;Simultaneous localization and mapping;Smart Homes;Ubiquitous computing;Wireless sensor networks},
doi={10.1109/IoTDI.2015.19},
month={April},}
```

# References & Notes

Many researchers question whether RSSI values contains any value at all. For example:

Dong, Q., & Dargie, W. (2012).*Evaluation of the reliability of RSSI for indoor localization*. In*2012 International Conference on Wireless Communications in Underground and Confined Areas, ICWCUCA 2012*. doi:10.1109/ICWCUCA.2012.6402492 ↩Oguejiofor, O., Okorogu, V., Abe, A., & BO, O. (2013).

*Outdoor Localization System Using RSSI Measurement of Wireless Sensor Network. International Journal of Innovative Technology and Exploring Engineering (IJITEE)*, 2(2), 1–6. ↩There is also a extended version of the Kalman filter that works with non-linear models. ↩

## 103 comments

## Fahim Zafari on

Hi Wouter! I personally am working on ibeacons and have used kalman filters as well. But the strange problem that I am facing is this. When I am at distance of 1m from the beacon I get an RSSI value of something like -59dbm , -63 at 2m and then when I move away the rssi value might be higher than -63 such as -62. Now Kalman can filter out the fluctuation and stabilize the measurements what about the non fluctuation problems such as getting -62 db at 3 meters and -63 or lower at 2meters.

## Wouter Bulten on

Hi Fahim! First of all, make sure that you've done the calibration correctly (using an average RSSI signal you measure at a 1m distance). In my case the the RSSI value at 1m was roughly -62dBm. A change in signal of one dBm, at that level, will only result in a small change in distance:

Based on these values you can notice two things:

(1) In both cases there is a difference of around 10-15cm. In my experience, 10cm is far smaller than the precision you can achieve using RSSI only. In other words, you can expect these kind of fluctuations as the difference in distance is just to small and the effect of random noise and noise caused by external sources (people moving around, etc) is high.

(2) The distance predictions differ from your own measurements (-62 at 3m, -63 at 2) which make it a bit harder for me to reproduce the 'problem'. This is most likely caused by a difference in signal propagation constant that we use (I use 2).

tl;dr: There is a lot of noise, differences in distances at these levels are small. Changes of 1dBm can be expected.

## Fahim Zafari on

Thanks a lot for your response. Yeah I have calibrated it fine. I took multiple values at 1m and averaged them out so i got -59 dBm. I think the problem at I am having is because of the noise in the environment. I initially used n=2 however the results were pretty erroneous. I personally am right now working on using signal processing techniques to filter out the noise and then use the RSSI. I did try with Kalman Filter as well but based on what I read online and my personal experience, Kalman is acting as a predictor or smoothening mechanism rather than filtering out the noise. Can you tell me the matrices you are using for your kalman filter? R, Q, H, F?

## Wouter Bulten on

The Kalman filter filters the noise based on a weighted average between the prediction and measurement, yes.

As this is a 1D example there are no matrices, only scalars. The values for R and Q are in the text (0.008 and signal variance) but really depend on your environment. I'm not sure which matrices you mean with H and F?

In general, I tend to use the Kalman filter as a first step in a larger processing pipeline.

## Fahim Zafari on

I am personally moving around with the phone so I am going with the rssi and the rate of change of rssi as my state variables. Therefore I use matrices. F (A in your notation) is the transition matrix while H is the C in your notation. I am just trying to do the same thing to find out what else I need to add into my processing to sort out the problem of RSSI

.

## Wouter Bulten on

In this case, for beacons, there is no control (i.e. they are static) so you can ignore u and therefore B. Furthermore, I assume that within the timeframe of the measurements the distance between the receiver and sender is constant so A is set to an identity matrix. Technically this is, of course, not the case when you are moving, but in my experience this is a simplification you can/must make: often you do not know anything about the movement.

As I use RSSI as my observation and state, x = z. So, C is, again, an identity matrix.

To give some context: These assumptions and choices are made as part of a larger project on indoor localisation of devices. This Kalman filter approach is a first step in that algorithm. A paper on this is currently under review so I can't refer you to it (yet).

## Fahim Zafari on

Thanks for your response. All the best with the paper and would be looking forward to reading it once its out.

## Wouter Bulten on

Thanks, good luck with your application :)

## Fahim Zafari on

By the way our paper on ibeacon based localization has been accepted for Globecom 2015. Would be glad to get your feedback http://people.engr.ncsu.edu...

## Fahim Zafari on

Wouter! I wanted toask if you know of any non-linear observation and measurement model for RSSI. I am trying to apply EKF to the RSSI values and would greatly appreciate if there is any widely used model.

## Wouter Bulten on

Depends on your application I guess. For example, I use multiple EKF's for the indoor localisation of devices as the transition from x,y position to distance is non-linear.

What kind of non-linear model are you considering?

## Fahim Zafari on

I am not clear about the non-linear model and that is where I am stuck. Can you tell me some specific models that I can use for iBeacon RSSI? I tried to dig up some papers but they are mostly using EKF for positioning rather than using it for just RSSI.

## Wouter Bulten on

Okay. The difference between a KF and the EKF is the linearity. The regular kalman filter assumes that observations are linear functions of the state. Moreover, it also assumes that the next state is a linear function of the previous one. This is the case in the example of this post. I assume that a RSSI signal is constant within the time frame (which is of course a linear transition) and that the observation is equal to the state.

However, most of the time this assumption does not hold. In a few weeks I will give a talk at IoTDI 2016 (http://conferences.computer... where I also address this. In my research I used 1D rssi measurements to perform indoor localisation. The transition from a coordinate (x,y) of a device to a distance estimate is non-linear so I required an EKF for that.

In your case, you will first need to define the following:

- What is your state? How do you represent it?

- What is your observation?

- How can you map a state to an observation?

- How can you map a state to a new state?

If any of these mappings are non-linear you should use an EKF.

## Fahim Zafari on

Thanks a lot for such detailed response. My state consists of the RSSI value and the rate of change of RSSI. My observations are just the RSSI. So I map the state and observation in a linear way. The new state is linearly linked to the previous state. Therefore I believe I should stick to Kalman since the problem is suited for Kalman. But I really appreciate your help and comments.

## Studentsåklart on

Hi Wouter!

Me and my friend are currently working on our Master's Thesis and are exploring the uses for indoor localization within mobile applications for public transport. We found your library very useful and translated it into java as we are building for Android. My question regards tweaking the filter in order to use for a non-stationary use case. Currently I've implemented a walking detector which returns a binary signal, which in turn determines the process noise of the filter in order to account for the increase in measurement variation. Would you say that this is a fair approach?

## Wouter Bulten on

Hi! Thanks :)

It depends on what you would like to measure with your walking detector. This blog post was part of my research on indoor localisation of devices and users. I used a pedometer to predict movement which gave me a step count. Maybe that could also be useful for you? My pedometer uses this Kalman filter to filter the accelerometer data.

An implementation is available through: https://github.com/wouterbu...

My full indoor localisation project is available at:

https://github.com/wouterbu...

If you are more interested in the research part, I will present a paper in April at IoTDI on this subject:

http://conferences.computer...

## Studentsåklart on

Okay thanks for the links, your paper seems very relevant at the moment :)

To clarify, we use the Kalman filter to smooth the reported distance. And seeing as our use cases involve a user that is stationary at some times and moving on other, we need to alter the parameters of the filter to allow less noise from the process when stationary and substantially more when on the move. This is where we put in our signal from the walk detection.

We decided against step detection as this would only provide an advantage over our current solution given that we also have the direction relative to the beacons, which would allow a more detailed prediction step, however, this is currently out of our scope for our thesis.

## Wouter Bulten on

Instead of changing the noise levels, maybe you could also integrate your movement into the model. Take a look at Equation 3, the motion model. The motion model already contains a way to implement expected movement. You probably still want to set A to an identity matrix (as a user's position does not drift) but use your movement detection to change the value of u. This way you will probably get more accurate results.

You can also take a look at a presentation I gave about this subject: https://wouterbulten.nl/sla...

Good luck!

## kami on

Hello Wouter,

Thanks for your great article about how to apply Kalman filter to RSSI .

But in my scenario, an user holding phone is moving around in an indoor environment.so my question is that possible to apply the method mentioned in this blog ,which expects a constant RSSI from time to time,to my case?if not , could you give me some hint?

## Wouter Bulten on

Hi Kami,

Did you already see my other post https://wouterbulten.nl/blo... ? This could be of assistance to you. In the presentation I explain how I applied Kalman filters and SLAM to indoor localisation of users inside buildings (while holding a phone).

With regards to your question: Yes, you can use this technique. As long as you update frequently the Kalman filter will (slowly) adjust to the moving of the user. This is however a tradeoff between use-of-use (and simplicity) versus accuracy. If you want to go for optimal accuracy you will have to take movement in to account.

## RK on

How I will found the value of R and Q or all constant (R, Q, A, B) according to my system? Is there any way to find the exact (perfect match value for my system) value of these constants?

"In my scenario I've a beacon and multiple readers. Now I want to calculate the coordinate of the beacon on the basic of the reader position. But I've found unexpected variation in the RSSI value, so the distance calculated between reader and beacon is also varying. So I want to apply this Kalman filter as a solution but I'm confuse with these constants."

## Wouter Bulten on

Hi!

These values depend on your system. For RSSI I usually assume that most of the noise comes from the measurements. Quoting from my other post:

"R models the process noise and describes how noisy our system internally is. Or, in other words, how much noise can we expect from the system itself? As our system is constant we can set this to a (very) low value. Q resembles the measurement noise; how much noise is caused by our measurements? As we expect that our measurements will contain most of the noise, it makes sense to set this parameter to a high number (especially in comparison to the process noise)."

So I would start with a low value for R and a estimate Q based on the standard deviation of the RSSI signal. (i.e. measure RSSI at a constant distance for a minute or so and use the sd for Q).

A and B are a bit more complex. As your beacons (probably) won't move you could start with setting A to an identity matrix. In this post I assume static beacons within my measurement time frames and, for convenience, ignore the effect of B. If you want to incorporate movement into the system, take a look at my post on "human slam":

https://wouterbulten.nl/blo...

## Kevin Dekemele on

Hello Wouter,

I have a background in dynamic systems so I understand the theory of Kalman filters. However, I still have a question on choosing the measurement noise Q.

A Q can obviously be chosen as the variance of a measurement. However, how sure are you that this Q is constant for different distances/RSSI ?If it is not, how can one deal with this changing Q ?

## Wouter Bulten on

Good question! The variance of the measurements will vary a lot based on the environment (e.g. walls). I tend to use one value that roughly captures the average variance within my target location. In practice that worked out fine. However, this is not ideal and you probably could come up with more intelligent ways to set (or continuously update) Q. You could for example track the latest measurements and if you detect a larger variance increase Q accordingly.

## aman agarwal on

Hi Wouter,

Thanks for the article! We are trying to model an indoor location tracking system with BLE (around 20 wall mounted receivers and transmitter cards with people walking around the installation). I am trying to wrap my head around filtering the stream of data that I will be receiving. For one card and one receiver this works quite well. But in my setup one card will ping multiple receivers and having multiple cards around means I have a bit of a complicated data stream. Can you suggest how to apply the Kalman filter and reduce the noise in this kind of a setup

## Wouter Bulten on

The most simple setup would be to use one filter per device. I did something similar in my SLACjs project: users walk around with multiple BLE beacons in the room.

You can read more about it in my paper that focuses on this project ( http://ieeexplore.ieee.org/... ) or if you prefer something a bit more simple (less math) you can also read this blog post: https://www.wouterbulten.nl... Last, I also have some working demo's shown here: https://www.wouterbulten.nl... (this includes multiple kalman filters)

Let me know if you have more questions!

## aman agarwal on

Interesting stuff! Will have a look and see if I can figure out a solution. Thanks! :)

## EA on

Hi Wouter,

Thank you for the post!

What I don't understand is why Kalman filtering is used on RSSI values for a "stationary" problem. You consider that the receiver and the beacon are not moving, so in a perfect world you will always measure the same value. I don't see why Kalman filtering should be chosen over simpler models for noise removal in this case.

To calculate an accurate distance from different measurements I need exactly one accurate RSSI value. Which one do you use? The last kalman prediction from the time series? The average from the corrected time series? I found in my experiments that the average of kalman filtered rssi values is very close to the average of the raw data.

## Wouter Bulten on

Hi,

In my application, I simplify the problem by making a assumption that both are static in the motion model. However, in reality the user is moving. Given the high update rate the filter is then (in my experiences) able to pick up changes due to movement. Of course, if you have a reliable way of modelling the motion than I would incorporate that.

If you have a static set of measurements there could be better alternatives. Like you said, averaging could already work. The Kalman filter is a nice online filter that does not need the whole set of measurements and targets other use cases.

## kareem elshaer on

HI Wouter,

I want to apply this library in Android Project using Android Studio to reduce noise

my application is indoor localization using Estimote beacons.

How Can I Do that?

## Wouter Bulten on

Hi, you can find a Java version of the filter library here: https://github.com/wouterbu...

## kareem elshaer on

Wouter, sorry for inconvenience, but how can I apply this library you sent me in my app

my application is a restaurant that has a beacon on every table. When a customer with a mobile device set on a table and order some sandwiches, it sends me his table number with his order.

so, how can I improve this with your library

I want your help Wouter to finalize this project so I suggest contacting you

thanks in advance

## Wouter Bulten on

Hi Kareem, Unfortunately I cannot help you with an implementation for your direct use case. You should be able to use the Java version in your android app. It is a simple class, you could also use the formula directly.

I'm not sure what kind of data you would like to filter for your restaurant app. Maybe you can give some more info?

Regarding your other questions. Some of these were already answered in other comments:

---

"R models the process noise and describes how noisy our system internally is. Or, in other words, how much noise can we expect from the system itself? As our system is constant we can set this to a (very) low value. Q resembles the measurement noise; how much noise is caused by our measurements? As we expect that our measurements will contain most of the noise, it makes sense to set this parameter to a high number (especially in comparison to the process noise)."

So I would start with a low value for R and a estimate Q based on the standard deviation of the RSSI signal. (i.e. measure RSSI at a constant distance for a minute or so and use the sd for Q).

---

## kareem elshaer on

Dear Wolter,

I have implemented your code in my app and tested. results gives the same values for RSSI and the filtered RSSI by your implementation!

Can you advise please as my whole project is depending on this point?

## Wouter Bulten on

Hi Kareem, as I understand your filter is not filtering the values properly? It is hard to debug without any code or output samples. Are you using the JS library or a custom (java) implementation?

## kareem elshaer on

I am using Android Studio and you have sent me the Java Code

## kareem elshaer on

https://uploads.disquscdn.c...

## Wouter Bulten on

Hi Kareem, just to make sure: You need to use the same instance of the filter for each call. So make the object (JKalman in your case) once and then call filter() for each new value. The first filtered value will always be the same as the original as it is the first observation. So in pseudo-code:

JKalman kalman = new JKalman(...)

setRangingListener() {

rssi = ...

filteredRssi = kalman.filter(rssi);

}

## kareem elshaer on

https://uploads.disquscdn.c...

## kareem elshaer on

It worked dear Wouter.

Many thanks for your cooperation with me.

Android forced me to set JKalman as

final. Is that right or will it affect something?Can you please send me the equations used to implement JKalman Class and some theory used to develop it?

I have to use all of this in my thesis.

Thank you very very much for helping me.

## Wouter Bulten on

Hi Kareem, good to hear that it works now. I don't think the final keyword makes any difference for your use-case as you will use a single filter anyway. I do not know all the details of your project so make sure to confirm.

I would recommend this article https://ieeexplore.ieee.org... for your thesis. This blog post was based on that publication and Section IV has more information on RSSI filtering and the formula's.

If you (or your university) does not have a subscription please contact me on ResearchGate so I can send you a private copy: https://www.researchgate.ne...

## Tejaswi Gowda on

How do I use it client side (in a browser)?

## Tejaswi Gowda on

How do I use it client side (in browser)?

## Wouter Bulten on

Please take a look at the releases: https://github.com/wouterbu...

## Sneha Sajjan on

Hi Wouter!

We are trying to model an indoor positioning system using WiFi trilateration. I did find your Java library for a Kalman filter, however I am confused about one thing. The WiFi access points will be fixed, however the user will be moving. What should be my approach to using the library? Will it work for a non-stationary user?

## Wouter Bulten on

Hi Sneha,

I have worked on the same topic using Bluetooth Beacons. Maybe these resources can help:

My approach for indoor positioning with fixed Bluetooth beacons: https://www.wouterbulten.nl...

Paper on this subject: https://ieeexplore.ieee.org...

If you are only interested in the filtering part: The Kalman filter can be used to filter your distance measure to each Wifi access point.

## Martin Dörflinger on

If I understand this correctly, the Kalman filter on RSSI only works if I have multiple measurements at the same distance, right? What happens if the client device moves? Then it is unfortunately not possible to determine whether the RSSI was affected by a stronger noise or whether the distance has changed, right?

## Wouter Bulten on

Yes and no. You are right that to filter the RSSI you will need more than 1 measurement. Usually -- at least in my experience -- the frequency of the RSSI measurements is pretty high in comparison to the motion of the user. E.g. you could measure the RSSI ten times a second and any movement of the user within that second is usually not that large to have a significant effect on the estimated distance. So to make single distance estimate it is usually sufficient to do a set of measurements within a small time frame.

## Victor Danney Garcia Plaza on

I am currently doing tests with Beacons to validate the presence of a student in a classroom, and for this, I am using 3 beacons (Trilateration) in a classroom to know if the student is in the classroom or not, but I do not know how initialize the ProcessNoise and MeasureNoise of Kalman Filter. Thanks for your help.

## Wouter Bulten on

Hi Victor,

Quoting from another comment:

"R models the process noise and describes how noisy our system internally is. Or, in other words, how much noise can we expect from the system itself? As our system is constant we can set this to a (very) low value. Q resembles the measurement noise; how much noise is caused by our measurements? As we expect that our measurements will contain most of the noise, it makes sense to set this parameter to a high number (especially in comparison to the process noise)."

So I would start with a low value for R and an estimate for Q based on the standard deviation of the RSSI signal. (i.e. measure RSSI at a constant distance for a minute or so and use the sd for Q).

## Jorge Chang on

There are a lot of papers in which Kalman filters are implemented to estimate RSSI values. As said above, this filter is used for linear systems, and the common way to model RSSI is with something like P(d)= -10η log(d/d0 )+A+Xσ. How is it possible to implement the Kalman filter and predict values with such a good performance even if the input data doesn´t behave as a linear system? Please, correct me if I'm wrong. I really want to understand the intuition of the Kalman filter.

## Wouter Bulten on

Hi Jorge, I think it boils down to a matter of simplicity. They way I used the kalman filter in my projects is by assuming that there is no movement (within the time frame of the measurements). The filtered RSSI was then passed to a (more complex) system based on particle filters that also took movement information and RSSI measurements of multiple devices in to account. The linear kalman filter was primarily used to remove the largest part of the noise.

Because of this assumption I can use the linear Kalman filter, as I assume that the signal between two time points should be the same and differences are caused by noise. Of course, in real life objects move and this assumption is not 100% valid. However, I found that this assumption works fairly well and that the filter wil catch up with the movement.

## Niels on

Hi Wouter,

I read an article that proposes to collect the ten recent Rssi values of a beacon, calculate mean and standard deviation and use an equation based on the mean and standard deviation to remove outliers. Next calculate a moving average of the remaining values and feed that value to the kalman filter.

Since the kalman filter works on data with "random error", do you this method will produce "better" results? Or is it even a suitable method?

## SIMON CLEMENTE on

https://uploads.disquscdn.c... Hi wouter,

My system.

I want to filter RSSI measurements, to do that i want to apply kalman filter so, i simplified the kalman process.

Kalman Process

tr=transpose

x(t)=F*x(t-1)+B*u

P(t)=F*P(t-1)*F(tr)+Q

K=P(t)*H(tr)/(H*P(t)*h(tr)+R

x(t)=x(t-1)+K*(measurements(t)-H*x(t))

P(t)=(I-K*H)*P(t)

those are my asumptions.

F=1

B=0

H=1

I=1

Q= 1e-8 (only to intialize)

R=7.5 (results of variance calculated from 50 values)

My equations simplified.

P= p +Q

K= P/(P+R)

p=(1-k)*P

Xp=Xe

Zp=Xp

Xe=K*(RSSI measurements-Zp)+Xp

This above is my actual code.

My system process is like this:

Phone-->Server-->DataBase-->Web graph

I use the phone application to obtain the RSSI measurements, and send to a server web.

I store data trhough server into DataBase.

I graph data before and after kalman.

I only use kalman in one dimmension. i Don't use kalman to obtain position neither velocity, I just want to get better estimated RSSI values.

My questions.

1. I did it wrong with my asumptions?

2. Is there something missing in the equations?

You explanation is so nice, and i want to ask you if i should change mi code to a library like yours, or fix mine.?

I apreciate so much if you help me, i don't know what is missing

## Wouter Bulten on

It's often fine to assume a static user. Did you read my post on the implementation: https://www.wouterbulten.nl... ? You can compare your own code with my implementation if you want, the relevant function can be found here: https://github.com/wouterbu...

## SIMON CLEMENTE on

Hi Wouter, thanks for answer...

Yes, I already saw it. i'll compare both, and after i'm going to tell you how it works.

I appreciate your work, it is really great.

## arun on

thanks I could implement Kalman Filter in SqlServer.. I am working on asset tracking and noise was major headache in trilateration calculations

## Kareem on

Hello Sir Wouter,

I would like to know the equations used to get the filtered values.

for example: if we have RSSI at t=0 equals 70 , RSSI at t=1 equals 65 and RSSI at t=3 equals 60.

how can we get from the equations values of filtered RSSI at t=1,2? .. filtered RSSI at t=0 will be 70 for sure.

## Wouter Bulten on

Hi Kareem, the equations are in the article above. If you prefer to have a code version, please see https://www.wouterbulten.nl...

## kareem elshaer on

Hello Wouter,

Very very urgent as I will discuss the equations with examples in my master's defense.

I want to know how to use the equations above to get filtered values for multiple times.

for example: if we have RSSI at t=0 equals -70 , RSSI at t=1 equals -65 and RSSI at t=3 equals -60.

how can we get from the equations above values of filtered RSSI at t=1,2,3? .. .

please sed me deriviation to get the filtered values using the equations assuming R=0.008 and Q=0.1.

If you have another example values please provide it urgently.

## Sarthak on

Hi,

What value for A, B, C, Q and R did you choose while doing the tests for BLE Rssi??

## Wouter Bulten on

In my experimental setup I used R: 0.008, Q: 4. A, B and C are determined by your way of modelling motion.

## Nurroy Sapto Anggoro on

I still don't understand what is A, B, and C

## Wouter Bulten on

A models what happens to your system regardless of any input. Like a helicoptor will go down if there is no upward movement. B models what happens given a specific input. C maps the state of the system to a measurement.

## Nurroy Sapto Anggoro on

If it's not moving, do we still need A,B, and C?

## Wouter Bulten on

In that case, A can be set to 1 and B to 0 (if the domain is one-dimensional). This is also shown in Equation (3) of the post (see above).

C depends on what you are modelling. In the most simple case, you can set this to 1.

Maybe also take a look at this post https://www.wouterbulten.nl... which is more application-focused.

## Nurroy Sapto Anggoro on

Okay, thank's for your response, i'll try it.

## Nurroy Sapto Anggoro on

Q is standard deviation right? why i get more than one result when i try to calculate it? Is value u're using can be used for any access point? Is Q=4 is enough? because when i try to calculate standard deviation the result is more than 100. also i use phone as the access point

## Wouter Bulten on

It all depends on what you are modelling and how much noise there is in the environment. I'm not sure how you end up with multiple values for your standard deviation. You can always try to find a value instead of measuring it. The lower Q, the faster the system responds to changes (as it trusts the measurement more) but the more noisy it is.

## Nurroy Sapto Anggoro on

based on your comment in another question, Q is standard deviation, so to get it, we must calculate it from rssi value? and what about R? what's range from R? do we get it from trial and error?

## Wouter Bulten on

R can be found by tuning, for RSSI its usually very low as most of the noise comes from the measurement. You can base Q on measurements, in my experiences that gives the best estimate of the noise in your environment.

## Uday Kumar Chaduvula on

Hi Wouter Bulten! Can you explain how to implement the Extend Kalman Filter to the beacons to get the exact position of a beacon if possible please provide the code also

## Wouter Bulten on

Hi! This post is focused only on the 1D variant. You can check out this post https://www.wouterbulten.nl... where I use the extended filter for beacon localisation.

## Max Yotos on

Hello, a great article, it was very useful to me. However, I have one question, can your algorithm include the time between successive measurements?

## Wouter Bulten on

Hi Max, you mean that you have a varying amount of time between measurements? What's your motion model? Do you assume a static system?

## Max Yotos on

My motion model is move from 0 to 20 meter. In addition, it does not get readings every second, and on average every 2/3 sec. I did multiplier for Q and R, but results have not changed much. And I'm not sure is that a good idea?

## Wouter Bulten on

If the time between measurements is roughly constant it should be fine. Then your "t" is just 2 or 3 seconds. It only matters if there is a large difference, because with a larger step you can expect a larger deviation in the measured signal. What is the general problem you are having?

## Max Yotos on

I just wanted to know how do that. After i wrote this i find something what directed me to multiplie Q and R. So it is good solution I dont have more questions. Thanks for fast reply.

## Wouter Bulten on

No problem! Increasing Q makes sense, because with that you say that you expect that there is more noise in the system. The more time between measurements, the more off your predictions will be (at least that is what I assume in your system). Good luck!

## Alex on

Hey Wouter,

Thank you for posting this! Your research and JS library have been a great help to me. I was wondering if you might suggest some values to model a human moving at a brisk walking pace linearly through uncontrolled environments. For my project I am just trying to smooth the signal so I can see if it is getting stronger or weaker with minimal delay and noise. Should I also set z and u variables?

## Wouter Bulten on

Hi Alex, thanks! I've used R: 0.008 and Q: 4 for tracking a walking user through RSSI signals. You could start with that and update accordingly to your own findings. You can use u to include a motion model, if you know which direction the user is moving. In my setup, I didn't use a motion model because I mainly used the filter to smooth the signal before further processing.

## Alex on

Hi Wouter! Thank you for your recommendations. Right now I am having good results with u=0 (since I do not know which direction the user is moving) C=1 r=.0008 Q=1 A=1 and B=1. I am going to keep experimenting with lower Q values until its as responsive as possible.

Also I am very impressed at your response speed and attentiveness to your blog! Thank you for your contributions to the community.

## Wouter Bulten on

There is always a trade-off between responsiveness and smoothness. Without the filter you have optimal responsiveness but a lot of noise, with a strong filter its to slow but really smooth. You could also calibrate your filter by standing still, taking measurements, and looking at the variance of the data.

Thanks for the compliments!

## Alex on

In your opinion would there be any benefits to an extended kalman filter in this use case?

## Wouter Bulten on

Hi Alex, with an extended kalman filter you can model non-linear systems. If your goal is just to smooth the signal, I would always start with the easy approach and build from that if needed.

## Albert on

Hi Wouter, your blog is very informative! Do you mind to share the link where kalman filter can be used in rssi from moving mac id for python?

## Wouter Bulten on

There is a Python implementation in the repository on Github. Regards, Wouter

## Erwin on

Thanks for the article, very clear. Would you recommend this filter for tracking a moving router? (I’m trying to track a drone thru gates and I don’t see the benefit of a kalman filter vs moving mean)

## Wouter Bulten on

Hi Erwin, with a Kalman filter you have a bit more control. If your system is very simple you can of course also use a running average. However, with a kalman filter you can give more weight to recent observations; which could result in better estimations if your system is not moving in a constant matter.

In your case of the drone, I expect you want to measure a x,y position. In that case you could use a kalman filter to remove noise from the rssi signal, and then use that filtered signal in a more elaborate model to estimate the exact position. I’ve done something similar in the past (but with humans instead of drones). I have a post on that on my blog.

## boris Becker on

I don’t know if you saw and understood the python version of your function, but I would like to know? what input does your function take and the data structur too? and the meaning of these two values KalmanFilter (0.008, 0.1) thanks

## Wouter Bulten on

Hi Boris,

The python version is not made by me. Still, the workings are the same as the js version.

The two values represent the process noise (R) and measurement noise (Q). You can see some more examples in my post on the js library.

## Sandeep Suresh on

Dear Wouter, Great article for iBeacons and noise filtering. Have to worked on RFID technology with readers and Tags that are deployed in a closed metallic environment? The challenge is how to detect reflection, multipath propagation signals and filter them so that the actual backscattered signal (basically the distance between Tag_1 to Reader)can be filtered? Any real life testing on RFID systems done with algorithms and software that is available to experiment and test? Please let me know. BR Ssuresh

## Wouter Bulten on

Hi Sandeep,

Unfortunately, I don’t have experience with your use case. I can imagine these distances are quite small? I’m not sure if RSSI measurements will be precise enough. That’s something you will need to test. In my experiments for indoor localization I ignored reflections and such, and depended on doing many measurements combined with estimating the positions using the Kalman Filter/SLAM. In your case, given that it is a small environment, this is possibly more critical. I’m sorry that I can’t help you further. Good luck with your project!

Regards, Wouter

## Ryan Han on

dear wouter from the bluetooth signal RSSI data with each distance of 1 meter to 10 meters. In the Kalman formula, what variables do we know from the data and what variables should be set? thank you

## Wouter Bulten on

Hi Ryan,

I would use the raw RSSI as input, then filter it and use the filtered output to convert it to a distance estimate. Most importantly is to set R and Q, which are based on your application and environment.

In this post I have some more practical examples.

Regards, Wouter

## Ryan Han on

does the variance signal from the RSSI with different distances have different ‘Q’ as well or does it average signal variance?

as in Figure 2, there are rssi from 3 different distances, is there a different Q?

## Wouter Bulten on

In Figure 2, they all use the same settings.

Of course, you can expect to have different noise characteristics. It’s depending on your application whether you want to keep this constant, or do an estimation on-the-fly. I usually kept it constant, just to keep the filter simple. I also used the output of the Kalman Filter as input to a more advanced filter for the exact localization. I would suggest to do some tests for your use case to decide what would be most beneficial.

## Ryan Han on

Dear wouter After getting the approximate distance, what formula do you use to determine the position of the beacon?

## Wouter Bulten on

Hi Ryan, I use the filtered RSSI value as input to a SLAM system. You can find a write-up of this in another blogpost: Human SLAM, Indoor localization using particle filters The source code is available in the SLACjs project.

## Ryan Han on

dear wouter

for distance with euclidean, i have 4 scanner with coordianat x y height (int) meter 5.6 5.8 2.6 0.2 5.8 2.6 0.2 0.2 2.6 5.6 0.2 2.6 and coordinat beacon x y height (int) 3.93, 2.03, 0.0

for distance formula 𝑑 = √(𝑥 − 𝑥′) + (𝑦 − 𝑦′)+(height - height’)

or

𝑑 = √(𝑥 − 𝑥′) + (𝑦 − 𝑦′) ?

## Wouter Bulten on

Hi Ryan, I never bothered with the height difference when the beacons were on the same floor as the person walking. The error due to noise is probably a lot higher than the difference the height will make. Of course, you can try to compensate for it. Note that the distance you get from the log-distance path loss model is the absolute distance.

I’m not sure what you want to calculate in your example. Do you want to calculate the true distance to compare with the values from the filter? If so, then you can indeed account for the difference in height. Experimention should show whether it adds anything given that its only 20 centimeters.

## Ala Agrebi on

Hey Wouter, Thank you for posting this! Your research and JS library have been a great help to me, just a question. In paper, we have Kt=Σ¯t * (1/(Σ¯tQt)) (Kalman Gain) but when i read the python code, i find Kt=Σ¯t * (1/(Σ¯t + Qt)). where is the error, please ?

## Wouter Bulten on

Hi Ala,

Thank you for the comment, and great find regarding this inconsistency! It’s been a long time that I have worked on this, but I believe that the code is correct, it should be an addition not a multiplication. I think the plus sign is missing in the manuscript but I will need to double check that later.