-
Notifications
You must be signed in to change notification settings - Fork 4
/
Analysis.py
202 lines (184 loc) · 6.93 KB
/
Analysis.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from subprocess import check_output
import numpy as np
import matplotlib.pyplot as plt
from plot_CSI import *
from matplotlib.mlab import PCA
class CSI_get:
def __init__(self,path):
self.Path = "\""+path+"\""
def Check_Packet_Count(self):
cmd = "main "+self.Path+" "+str(1)+" Num"
return int(check_output(cmd, shell=True))
def Check_Effection_Packet(self):
cmd = "main "+self.Path+" "+str(1)+" Packet_count_packet"
result = str(check_output(cmd, shell=True))
Box = result.split('$')
return Box
def Check_effection(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" Packet_effection"
if check_output(cmd, shell=True)==b'1':
return 1
else:
return 0
def Get_Bfee_count(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" Bfee_count"
if self.Check_effection(Packet_Number):
return 1
return int(check_output(cmd, shell=True))
def Get_Perm(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" Perm"
if self.Check_effection(Packet_Number):
return 1
result = str(check_output(cmd, shell=True))
return [int(result[2]),int(result[4]),int(result[6])]
def Get_Nrx(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" Nrx"
if self.Check_effection(Packet_Number):
return 1
return int(check_output(cmd, shell=True))
def Get_Ntx(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" Ntx"
if self.Check_effection(Packet_Number):
return 1
return int(check_output(cmd, shell=True))
def Get_Noise(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" Noise"
if self.Check_effection(Packet_Number):
return 1
return int(check_output(cmd, shell=True))
def Get_RSSI(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" RSSI"
if self.Check_effection(Packet_Number):
return 1
result = str(check_output(cmd, shell=True))
pos1 = result.find(',')
pos2 = result.find(',', pos1+1)
pos3 = result.find(',', pos2+1)
return [int(result[2:pos1]),int(result[pos1+1:pos2]),int(result[pos2+1:pos3])]
def Get_CSI(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" CSI"
if self.Check_effection(Packet_Number):
return 1
result = str(check_output(cmd, shell=True))
if(len(result) < self.Get_Nrx(Packet_Number)*self.Get_Ntx(Packet_Number)*30):
return "CSI size is error"
pos1 = 0
pos2 = 0
pos3 = 0
buff = []
buff2 = []
buff3 = []
CSI_Box = []
for index in range(180):
pos3 = result.find('|',pos3+1)
pos2 = result.find(',',pos2+1)
pos1 = result.find('$',pos1+1)
buff.append(pos1)
buff2.append(pos2)
buff3.append(pos3)
count = 0
for index in buff:
prv = buff[count]
mid = buff2[count]
tail = buff3[count]
count = count + 1
CSI_Box.append(complex(int(result[prv+1:mid]),int(result[mid+1:tail])))
return CSI_Box
def Get_CSI_Q(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" CSI"
if self.Check_effection(Packet_Number):
return 1
result = str(check_output(cmd, shell=True))
if(len(result) < self.Get_Nrx(Packet_Number)*self.Get_Ntx(Packet_Number)*30):
return "CSI size is error"
pos1 = 0
pos2 = 0
pos3 = 0
buff = []
buff2 = []
buff3 = []
CSI_Box = []
for index in range(180):
pos3 = result.find('|',pos3+1)
pos2 = result.find(',',pos2+1)
pos1 = result.find('$',pos1+1)
buff.append(pos1)
buff2.append(pos2)
buff3.append(pos3)
count = 0
for index in buff:
prv = buff[count]
mid = buff2[count]
tail = buff3[count]
count = count + 1
CSI_Box.append(abs(complex(int(result[prv+1:mid]),int(result[mid+1:tail]))))
return CSI_Box
def Get_CSI_Ang(self,Packet_Number):
cmd = "main "+self.Path+" "+str(Packet_Number)+" CSI"
if self.Check_effection(Packet_Number):
return 1
result = str(check_output(cmd, shell=True))
if(len(result) < self.Get_Nrx(Packet_Number)*self.Get_Ntx(Packet_Number)*30):
return "CSI size is error"
pos1 = 0
pos2 = 0
pos3 = 0
buff = []
buff2 = []
buff3 = []
CSI_Box = []
for index in range(180):
pos3 = result.find('|',pos3+1)
pos2 = result.find(',',pos2+1)
pos1 = result.find('$',pos1+1)
buff.append(pos1)
buff2.append(pos2)
buff3.append(pos3)
count = 0
for index in buff:
prv = buff[count]
mid = buff2[count]
tail = buff3[count]
count = count + 1
CSI_Box.append(np.angle(complex(int(result[prv+1:mid]),int(result[mid+1:tail]))))
return CSI_Box
def Complete_Format(self,Packet_Number):
if self.Check_effection(Packet_Number):
return 1
Bfee_count = self.Get_Bfee_count(Packet_Number)
Perm = self.Get_Perm(Packet_Number)
Nrx = self.Get_Nrx(Packet_Number)
Ntx = self.Get_Ntx(Packet_Number)
Noise = self.Get_Noise(Packet_Number)
RSSI = self.Get_RSSI(Packet_Number)
CSI = np.sort_complex(np.zeros((30,3,2)))
#self.CSI = np.complex(self.CSI)
CSI_Packet = self.Get_CSI(Packet_Number)
if(len(CSI_Packet) < 20):
return CSI_Packet
count = 0
for Subcarrier in range(30):
for Nrx_n in range(len(Nrx)):
for Ntx_n in range(len(Ntx)):
CSI[Subcarrier,Nrx_n,Ntx_n] = CSI_Packet[count]
count = count + 1
return [Bfee_count,Perm,Nrx,Ntx,Noise,RSSI,CSI]
def Muilt_data(self,L_Range,H_Rang):
Box = []
buff = 0
for Packet_number in range(H_Rang-L_Range):
if(self.Get_Bfee_count(Packet_number) != buff):
Box.append(self.Complete_Format(Packet_number))
buff = self.Get_Bfee_count(Packet_number)
return Box
def Muilt_CSI(self,L_Range,H_Rang):
Box = []
buff = 0
for Packet_number in range(H_Rang-L_Range):
if(self.Get_Bfee_count(Packet_number) != buff):
Box.append(self.Get_CSI(Packet_number))
buff = self.Get_Bfee_count(Packet_number)
return Box
if __name__ == '__main__':
CSI = CSI_get("F:\\CSI\\Location_CSI\\01\\170109_0814st_01.dat")
print(CSI.Get_CSI(1))