-
Notifications
You must be signed in to change notification settings - Fork 6
/
wifi.py
106 lines (81 loc) · 2.61 KB
/
wifi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""wifi.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1tJTeO7DSwhR26UTdJec7qey1HImdnkxJ
"""
import math
from math import pi
import pandas as pd
import csv
from math import pow
import numpy as np
import matplotlib.pyplot as plot
rssi_arr_1=np.genfromtxt('/content/Wifi_ap_0.5.csv',delimiter=',')
rssi_arr_2=np.genfromtxt('/content/Wifi_ap_1.csv',delimiter=',')
rssi_arr_3=np.genfromtxt('/content/Wifi_ap_1.5.csv',delimiter=',')
n=1.5
a=-36
def calc_dist(rss,a,n):
cal_d= pow(10,((rss-a)/(-10*n)))
return cal_d
dist_arr_1=[]
dist_arr_2=[]
dist_arr_3=[]
weight_arr_1=[]
weight_arr_2=[]
weight_arr_3=[]
for x in rssi_arr_1:
cal_d=calc_dist(x,a,n)
dist_arr_1=np.append(dist_arr_1,cal_d)
weight_arr_1=np.append(weight_arr_1,(1/cal_d))
for x in rssi_arr_2:
cal_d=calc_dist(x,a,n)
dist_arr_2=np.append(dist_arr_2,cal_d)
weight_arr_2=np.append(weight_arr_2,(1/cal_d))
for x in rssi_arr_3:
cal_d=calc_dist(x,a,n)
dist_arr_3=np.append(dist_arr_3,cal_d)
weight_arr_3=np.append(weight_arr_3,(1/cal_d))
rssi_var1=np.nanvar(rssi_arr_1)
rssi_var2=np.nanvar(rssi_arr_2)
rssi_var3=np.nanvar(rssi_arr_3)
print("variance of rssi of APs are respectively(in dBm)=",rssi_var1,rssi_var2,rssi_var3)
mean_1=np.nanmean(dist_arr_1)
mean_2=np.nanmean(dist_arr_2)
mean_3=np.nanmean(dist_arr_3)
wmean_1=np.nanmean(weight_arr_1)
wmean_2=np.nanmean(weight_arr_2)
wmean_3=np.nanmean(weight_arr_3)
arr_weight=[wmean_1,wmean_2,wmean_3]
print("calculated distance from ref.point 1=",mean_1)
print("calculated distance from ref.point 2=",mean_2)
print("calculated distance from ref.point 3=",mean_3)
fig = plot.figure()
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax1.plot(dist_arr_1)
ax1.axhline(y=mean_1, color='g', linestyle='-')
ax1.axhline(y=0.5, color='r', linestyle='-')
ax2.plot(dist_arr_2)
ax2.axhline(y=mean_2, color='g', linestyle='-')
ax2.axhline(y=1, color='r', linestyle='-')
ax3.plot(dist_arr_3)
ax3.axhline(y=mean_3, color='g', linestyle='-')
ax3.axhline(y=1.5, color='r', linestyle='-')
plot.show()
x=[2,1.5,0]
y=[0,1,0]
def wcl(weight,x,y):
xiwi=np.multiply(x,weight)
yiwi=np.multiply(y,weight)
xw=np.sum(xiwi)/np.sum(weight)
yw=np.sum(yiwi)/np.sum(weight)
return xw,yw
res_x,res_y=wcl(arr_weight,x,y)
print("resultant location coordinates(x,y)=",res_x,res_y)
def calculateDistance(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
print("distance between calculated and setup coordinates in meteres=", calculateDistance(1.5, 0, res_x, res_y) )