How to calculate distance from Wifi router using Signal Strength?
Asked Answered
S

7

89

I would like to calculate the exact location of a mobile device inside a building ( so no GPS access)

I want to do this using the signal strength(in dBm) of at least 3 fixed wifi signals(3 fixed routers of which I know the position)

Google already does that and I would like to know how they figure out the exact location based on the this data

Check this article for more details : http://www.codeproject.com/Articles/63747/Exploring-GoogleGears-Wi-Fi-Geo-Locator-Secrets

Stour answered 27/6, 2012 at 0:9 Comment(3)
#4072039 Here is link for your reference .Kight
This question appears to be off-topic because it is about electrical engineering. I suggest migrating to electronics.stackexchange.comPrivet
@lhab Hajj, my requirement same as yours. Have to solved this out? Please share your idea so that other can also learn from that. Thank you.Kyat
S
50

FSPL depends on two parameters: First is the frequency of radio signals;Second is the wireless transmission distance. The following formula can reflect the relationship between them.

FSPL (dB) = 20log10(d) + 20log10(f) + K

d = distance
f = frequency
K= constant that depends on the units used for d and f
If d is measured in kilometers, f in MHz, the formula is:

FSPL (dB) = 20log10(d)+ 20log10(f) + 32.44

From the Fade Margin equation, Free Space Path Loss can be computed with the following equation.

Free Space Path Loss=Tx Power-Tx Cable Loss+Tx Antenna Gain+Rx Antenna Gain - Rx Cable Loss - Rx Sensitivity - Fade Margin

With the above two Free Space Path Loss equations, we can find out the Distance in km.

Distance (km) = 10(Free Space Path Loss – 32.44 – 20log10(f))/20

The Fresnel Zone is the area around the visual line-of-sight that radio waves spread out into after they leave the antenna. You want a clear line of sight to maintain strength, especially for 2.4GHz wireless systems. This is because 2.4GHz waves are absorbed by water, like the water found in trees. The rule of thumb is that 60% of Fresnel Zone must be clear of obstacles. Typically, 20% Fresnel Zone blockage introduces little signal loss to the link. Beyond 40% blockage the signal loss will become significant.

FSPLr=17.32*√(d/4f)

d = distance [km]
f = frequency [GHz]
r = radius [m]

Source : http://www.tp-link.com/en/support/calculator/

Stour answered 28/6, 2012 at 16:28 Comment(1)
Good answer, and I have a follow-up question. How accurate are the measurements? In other words can I get accuracies in the inches/centimeters range?Elastin
S
40

To calculate the distance you need signal strength and frequency of the signal. Here is the java code:

public double calculateDistance(double signalLevelInDb, double freqInMHz) {
    double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(signalLevelInDb)) / 20.0;
    return Math.pow(10.0, exp);
}

The formula used is:

distance = 10 ^ ((27.55 - (20 * log10(frequency)) + signalLevel)/20)

Example: frequency = 2412MHz, signalLevel = -57dbm, result = 7.000397427391188m

This formula is transformed form of Free Space Path Loss(FSPL) formula. Here the distance is measured in meters and the frequency - in megahertz. For other measures you have to use different constant (27.55). Read for the constants here.

For more information read here.

Spontaneity answered 21/8, 2013 at 14:5 Comment(10)
Thanks for specifying that it should be the absolute value of signal level, I was searching for some time what I got wrong!Orthman
@YiannisTsimalis beginner question: should it be absolute value or just multiply by negative one? What if the signal level was positive dBm?Rinee
@user12202013 hmm I think it depends on how your access point works. I mean, generally, the dBm system indicates how noisy your signal is. If the value is higher, then the signal is noisier, which means actually, that the signal is weaker. Or at least this is how I understand it..Orthman
@YiannisTsimalis I was thinking more generally but after looking at the formula I think absolute value is correct because distance should be positiveRinee
The example shown in this answer is completely wrong. Signal level should be in dB, not in dBm. These are two completely different units.Tittup
@6franek In the method signature it says "double signalLevelInDb". Maybe the author made a spelling mistake. What I can assure you of, is that I applied this method's logic and it worked perfectly for indoor locating, by using Db values provided by Wireshark.Orthman
@YiannisTsimalis But on which physical law is it based? FSPL doesn't take dbm, but db as an argument. And as I've written before, these two units are completely different.Tittup
@6franek I understand what you write dude, maybe it was a typo and he meant db instead of dbm. I don't know the physics background of the law.Orthman
How do you calculate the constant? The original formula seems to provide 20*log(10, 4*pi/c) which results in somewhere around -147.55. What are the modifiers used for 4pi/c part to determine the other results?Northeaster
I have been investigating this formula for quite a time now, and I concluded that it is completely wrong! FSPL is measured in db, while signalLevel is measured in dbm. It may yield a good estimation, but the results can easily get messed up when distance get quite large.Kellum
U
17
K = 32.44
FSPL = Ptx - CLtx + AGtx + AGrx - CLrx - Prx - FM
d = 10 ^ (( FSPL - K - 20 log10( f )) / 20 )

Here:

  • K - constant (32.44, when f in MHz and d in km, change to -27.55 when f in MHz and d in m)
  • FSPL - Free Space Path Loss
  • Ptx - transmitter power, dBm ( up to 20 dBm (100mW) )
  • CLtx, CLrx - cable loss at transmitter and receiver, dB ( 0, if no cables )
  • AGtx, AGrx - antenna gain at transmitter and receiver, dBi
  • Prx - receiver sensitivity, dBm ( down to -100 dBm (0.1pW) )
  • FM - fade margin, dB ( more than 14 dB (normal) or more than 22 dB (good))
  • f - signal frequency, MHz
  • d - distance, m or km (depends on value of K)

Note: there is an error in formulas from TP-Link support site (mising ^).

Substitute Prx with received signal strength to get a distance from WiFi AP.

Example: Ptx = 16 dBm, AGtx = 2 dBi, AGrx = 0, Prx = -51 dBm (received signal strength), CLtx = 0, CLrx = 0, f = 2442 MHz (7'th 802.11bgn channel), FM = 22. Result: FSPL = 47 dB, d = 2.1865 m

Note: FM (fade margin) seems to be irrelevant here, but I'm leaving it because of the original formula.

You should take into acount walls, table http://www.liveport.com/wifi-signal-attenuation may help.

Example: (previous data) + one wooden wall ( 5 dB, from the table ). Result: FSPL = FSPL - 5 dB = 44 dB, d = 1.548 m

Also please note, that antena gain dosn't add power - it describes the shape of radiation pattern (donut in case of omnidirectional antena, zeppelin in case of directional antenna, etc).

None of this takes into account signal reflections (don't have an idea how to do this). Probably noise is also missing. So this math may be good only for rough distance estimation.

Upsetting answered 1/12, 2014 at 21:59 Comment(0)
M
7

the simple answer to your question would be Triangulation. Which is essentially the concept in all GPS devices, I would give this article a read to learn more about how Google goes about doing this: http://www.computerworld.com/s/article/9127462/FAQ_How_Google_Latitude_locates_you_?taxonomyId=15&pageNumber=2.

From my understanding, they use a service similar to Skyhook, which is a location software that determines your location based on your wifi/cellphone signals. In order to achieve their accuracy, these services have large servers of databases that store location information on these cell towers and wifi access points - they actually survey metropolitan areas to keep it up to date. In order for you to achieve something similar, I would assume you'd have to use a service like Skyhook - you can use their SDK ( http://www.skyhookwireless.com/location-technology/ ).

However, if you want to do something internal (like using your own routers' locations) - then you'd likely have to create an algorithm that mimics Triangulation. You'll have to find a way to get the signal_strength and mac_address of the device and use that information along with the locations of your routers to come up with the location. You can probably get the information about devices hooked up to your routers by doing something similar to this ( http://www.makeuseof.com/tag/check-stealing-wifi/ ).

Mcinnis answered 27/6, 2012 at 16:21 Comment(1)
this is a tricky and challenging task, you've got me keen on learning more about this aspect of location services..please post any new information/insight you get on this problem, i'm interested in knowing how you solve itMcinnis
J
5

Distance (km) = 10^((Free Space Path Loss – 92.45 – 20log10(f))/20)

Judicious answered 28/2, 2013 at 22:10 Comment(0)
R
1

In general, this is a really bad way of doing things due to multipath interference. This is definitely more of an RF engineering question than a coding one.

Tl;dr, the wifi RF energy gets scattered in different directions after bouncing off walls, people, the floor etc. There's no way of telling where you are by trianglation alone, unless you're in an empty room with the wifi beacons placed in exactly the right place.

Google is able to get away with this because they essentially can map where every wifi SSID is to a GPS location when any android user (who opts in to their service) walks into range. That way, the next time a user walks by there, even without a perfect GPS signal, the google mothership can tell where you are. Typically, they'll use that in conjunction with a crappy GPS signal.

What I have seen done is a grid of Zigbee or BTLE devices. If you know where these are laid out, you can used the combined RSS to figure out relatively which ones you're closest to, and go from there.

Rossman answered 18/4, 2019 at 23:7 Comment(1)
For more info on how google does it #1668804Rossman
R
-7

Think about how you would navigate with tools that predate GPS—something like a sextant, octant, backstaff or an astrolabe.

If you receive the signal from 3 different locations, then you only need to measure the signal strength and make a ratio from those locations. Simply triangulate the calculation where a2+b2=c2. The stronger the signal strength, the closer the device is to the receiver.

Roughneck answered 18/4, 2019 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.