Kalman filters explained: Removing noise from RSSI signals
Table of contents
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 general1, 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 model2:
In this model, describes the distance between the transceiver and recipient, the signal propagation exponent and a referenced RSSI value at . Usually is taken to be 1 such that becomes the signal strength measured at a distance of 1 meter of the device.
can usually be retrieved from the device itself as it is often part of the broadcast message. Alternatively, you can approximate by collecting data and averaging the signal strength measurements. The signal propagation exponent is a constant that differs from environment to environment. For indoor applications, is often set to .
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 regular3 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:
The current state is defined as a combination of the previous state (given some transformation matrix ), a control input (this could be a movement command in a robot) and noise . 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 and set to an identity matrix. These two changes result in a very simple model:
The second part of implementing the Kalman filter is defining the observation model: how does a particular state result in a measurement ? The general model is as follows:
Here is the transformation matrix and 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:
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:
Note the difference between and : describes our prediction and the true value of the state. The bar above the denotes that we yet have to incorporate information from the measurement. 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 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:
Update 2021: The Kalman gain equation was missing a + sign as spotted by Ala and Bojan. This has been corrected in the post. The implementation in KalmanJS was not affected and has not been changed.
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 ). 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. is large) we should trust the measurement more. Likewise, if the measurement noise is low (i.e. is low) it is also wise to use those measurements. In these cases the Kalman gain will be high. Likewise, if we are very certain about our prediction of the system and/or the measurement noise is high the Kalman gain will be low (e.g., we don’t trust the measurement). This translates directly to the update step:
In the update step we compute the final prediction of the system (, without the bar) and the certainty . 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 below.
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 Online publication
References & Notes
Footnotes
-
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. ↩
Comments (109)
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.
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:
//Given -62dBm as reference value
Math.pow(10,(-62 + 62)/ (-10 * 2)) = 1.0m
Math.pow(10,(-63 + 62)/ (-10 * 2)) = 1.122m
//Given -59dBm as reference value
Math.pow(10,(-62 + 59)/ (-10 * 2)) = 1.41m
Math.pow(10,(-63 + 59)/ (-10 * 2)) = 1.58m
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.
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?
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.
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
.
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).
Thanks for your response. All the best with the paper and would be looking forward to reading it once its out.
Thanks, good luck with your application :)
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...
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.
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?
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.
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.
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.
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?
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:
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.
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!
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?
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.
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."
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":
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 ?
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.
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
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!
Interesting stuff! Will have a look and see if I can figure out a solution. Thanks! :)
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.
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.
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?
Hi, you can find a Java version of the filter library here: https://github.com/wouterbu...
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
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).
---
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?
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?
I am using Android Studio and you have sent me the Java Code
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);
}
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.
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...
How do I use it client side (in a browser)?
How do I use it client side (in browser)?
Please take a look at the releases: https://github.com/wouterbu...
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?
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.
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?
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.
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.
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).
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.
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.
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?
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
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...
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.
thanks I could implement Kalman Filter in SqlServer.. I am working on asset tracking and noise was major headache in trilateration calculations
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.
Hi Kareem, the equations are in the article above. If you prefer to have a code version, please see https://www.wouterbulten.nl...
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.
Hi,
What value for A, B, C, Q and R did you choose while doing the tests for BLE Rssi??
In my experimental setup I used R: 0.008, Q: 4. A, B and C are determined by your way of modelling motion.
I still don't understand what is A, B, and C
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.
If it's not moving, do we still need A,B, and C?
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.
Okay, thank's for your response, i'll try it.
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
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.
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?
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.
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
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.
Hello, a great article, it was very useful to me. However, I have one question, can your algorithm include the time between successive measurements?
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?
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?
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?
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.
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!
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?
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.
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.
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!
In your opinion would there be any benefits to an extended kalman filter in this use case?
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.
Adding new comments is no longer possible. If you have a question or remark, please reach out via the contact page.