-
Notifications
You must be signed in to change notification settings - Fork 2
/
parameters.py
86 lines (70 loc) · 3.02 KB
/
parameters.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
# this code is to calculate the reference signal strength(rss) and signal attenuation factor(n)
# importing libraries
import time
import subprocess
import numpy
import math
# declaring an empty list to store average signal strength value at 10 different locations
Y = []
ssid = 'ZTE_5G_qaquFU' # ssid for which parameters are to be determined
# function to calculate average value of signal strength at a particular location by taking 20 readings of
# signal strength at that location
def average_rssi():
avg = 0
for num in range(20):
subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin=disabled'])
subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin=enabled'])
time.sleep(4)
# getting the result of command line command and storing it in a variable
result = subprocess.check_output(["netsh", "wlan", "show", "network", "mode=Bssid"])
# converting the result(datatype-bytes) first into string and then storing substrings in list y
cmd_output_list = list((result.decode('ASCII')).split())
i_SSID = [index for index, x in enumerate(cmd_output_list) if x == 'SSID']
i_Network = [index for index, x in enumerate(cmd_output_list) if x == 'Network']
i_Signal = [index for index, x in enumerate(cmd_output_list) if x == 'Signal']
for m in range(len(i_SSID)):
c = cmd_output_list[(i_SSID[m] + 3):i_Network[m]]
c = tuple(c)
s = " "
if s.join(c) == ssid:
a = cmd_output_list[i_Signal[m] + 2]
a = a[0: len(a) - 1]
dbm = ((int(a)) / 2) - 100
avg += dbm
break
time.sleep(20)
avg /= 20
return avg
# getting the average value of signal strength at 10 different locations and storing it in the list Y
for i in range(10):
rssi = average_rssi()
Y.append(rssi)
print(Y)
time.sleep(5)
print(Y)
# converting list Y into a numpy array
Y = numpy.array(Y)
# reshaping Y from dimension (1,10) into (10,1)
Y.reshape((10, 1))
# declaring a numpy array according to distance calculating formula P(d) = P(d0) - 10*n*log(d/d0) where P(d) is
# the signal strength at distance d, d0=1m is the reference distance and P(d0) is received signal strength at d0
Z = numpy.array([[1, -10 * math.log(1.5, 10)],
[1, -10 * math.log(2, 10)],
[1, -10 * math.log(3, 10)],
[1, -10 * math.log(3.5, 10)],
[1, -10 * math.log(4, 10)],
[1, -10 * math.log(4.5, 10)],
[1, -10 * math.log(5, 10)],
[1, -10 * math.log(5.5, 10)],
[1, -10 * math.log(6, 10)],
[1, -10 * math.log(6.5, 10)]])
# X=[[rss], [n]] therefore Y=Z*X and by method of least square algorithm to minimize error we get
# X=(Z_transpose.Z)^(-1).(Z_transpose.Y)
Z_trans = Z.transpose()
A = numpy.linalg.inv(Z_trans.dot(Z))
B = Z_trans.dot(Y)
X = A.dot(B)
rss = X[0][0]
n = X[1][0]
print(rss)
print(n)