Skip to content

Instantly share code, notes, and snippets.

@Shylock-Hg
Created December 7, 2018 05:41
Show Gist options
  • Save Shylock-Hg/d9c5f6f7cc460e08c7544789e0a597c6 to your computer and use it in GitHub Desktop.
Save Shylock-Hg/d9c5f6f7cc460e08c7544789e0a597c6 to your computer and use it in GitHub Desktop.
Convert RSSI to distance to AP.
#! /usr/bin/env python3
from matplotlib import pyplot as plt
import math
# hyper parameters
calib1m_rssi = -43 #!< bias of rssi in 1 meter
propa = 2.8
scale_factor = 10 #!< scale factor of distance input of level function
# measured_rssi -> distance(meter)
dist = lambda value : math.pow(10,((calib1m_rssi-value)/(10.0*propa)))
# measured_rssi -> displayed signal level [0-9]
level = lambda value : int(9*math.exp(-dist(value)/scale_factor))
# testing
# samples for testing
measured_rssi = range(-100,1,1)
dists = map(dist,measured_rssi)
levels = map(level,measured_rssi)
plt.plot(list(measured_rssi),list(dists))
plt.scatter(list(measured_rssi),list(levels))
plt.show()
#for d,l in zip(dists,levels):
# print(d,l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment