blob: 7a6fb4b7d5713e02e8de4819b0342b680c0c5fc7 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001import math
2import numpy as np
3
4class L:
5 fw = None
6 @staticmethod
7 def logopen(f_path):
8 L.fw = open(f_path,"w")
9
10 @staticmethod
11 def info(infostr):
12 print infostr
13 file_string = infostr + '\n'
14 L.fw.write(file_string)
15 @staticmethod
16 def logclose():
17 L.fw.close()
18 L.fw = None
19
20def bi2de(binary):
21 decValue = int(binary, 2)
22
23 return decValue
24
25def twos_comp(val, bits):
26
27 """compute the 2's compliment of int value val"""
28 if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
29 val = val - (1 << bits) # compute negative value
30 return val
31
32
33def readTimeInfoFile(time_file_path):
34
35 print "\n"
36 print "Opening Time Info File...."
37
38 # Determine number of time stamps in the file
39 fr_TIME = open(time_file_path,"r+")
40 time_file_line_count = 0
41 while True:
42 time_file_line_count = time_file_line_count + 1
43 if fr_TIME.readline() == '':
44 time_file_line_count = time_file_line_count - 1
45 break
46
47 # Read and store all time stamps
48 fr_TIME = open(time_file_path,"r+")
49 file_mat = [0 for y in range(time_file_line_count)]
50 for kk in xrange(0,time_file_line_count):
51 file_mat[kk] = fr_TIME.readline()
52
53 #Determine FRC capture time boundaries
54 startFRC = file_mat[0]
55 endingFRC = file_mat[-1]
56
57 print "Time info file contains starting FRC:",
58 print str(int(math.floor(int(startFRC.partition(' ')[0],16) / 64))) + "(64us)"
59 print "Time info file contains ending FRC:",
60 print str(int(math.floor(int(endingFRC.partition(' ')[0],16) / 64))) + "(64us)"
61
62 return file_mat
63
64
65
66def det_iqPairCount(inputTimeMat,frc_):
67
68 frc_64 = frc_ * 64
69
70 print "\n"
71 print "Input FRC:" + str(frc_) + "(64us)"
72 print "Identifying SIB PCC Packet Data from input FRC...."
73
74 #Covert inputFile FRC column to int
75 FRC_col_int = [0] * len(inputTimeMat)
76 for kk in xrange(0,len(inputTimeMat)):
77 line_string = inputTimeMat[kk]
78 FRC_col_int[kk] = int(line_string.partition(' ')[0],16)
79
80 #Find packet idx in Time Info File
81 min_FRC_idx = np.argmin([np.absolute(x-frc_64) for x in FRC_col_int])
82
83 #Accumulate packed sizes until min_FRC_idx time row
84 line_add = 0
85 for jj in xrange(0,min_FRC_idx):
86 line_string = inputTimeMat[jj]
87 line_split = line_string.split()
88 line_add = line_add + int(line_split[3],16)
89 #print [line_split[3], int(line_split[3],16), line_add]
90
91 print "Found input FRC in packet with FRC_Time:" + str(FRC_col_int[min_FRC_idx]/64) + "(64us) - {id: " + hex(FRC_col_int[min_FRC_idx]) + "}"
92 #print [min_FRC_idx, FRC_col_int[min_FRC_idx], frc_64]
93
94 line_split = inputTimeMat[min_FRC_idx].split()
95 line_split_next = inputTimeMat[min_FRC_idx+1].split()
96
97 packet_size = 4 * int(line_split[3],16) #Fetch packet size
98 packet_frc = int(line_split[0],16) #Fetch packet start
99 packet_frc_next = int(line_split_next[0],16) #Fetch next packet start
100
101 frc_diff1 = frc_64 - packet_frc #Determine start and input FRC difference
102 frc_diff2 = packet_frc_next - packet_frc #Determine start and next(packet) FRC difference
103
104 t_diff_ratio = frc_diff1 / float(frc_diff2)
105 packet_fraction = int(t_diff_ratio * packet_size)
106
107# print [packet_frc, frc_64, frc_diff1]
108# print [packet_frc, packet_frc_next, frc_diff2]
109# print [packet_size, t_diff_ratio, packet_fraction]
110
111 iqPair_count = 4 * line_add + packet_fraction
112 return iqPair_count
113
114
115def CFO_stats_print( inst_CFO, cumm_CFO, cfo_count):
116
117 fw = L.fw
118 print ""
119 print "CFO Report (Instantaneous)"
120 print "--------------------------"
121 fw.write('\n')
122 fw.write("CFO Report (Instantaneous)")
123 fw.write("--------------------------")
124 fw.write('\n')
125 for kk in xrange(0,5):
126
127 print "Subframe %d (Hz):" % kk,
128 string = "Subframe " + str(kk) + " (Hz):"
129 fw.write(string)
130 if (kk<4):
131 v_ = inst_CFO[:,4*kk:4*kk+4]
132 print "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
133 string = "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
134 string = string + '\n'
135 fw.write(string)
136 else:
137 v_ = inst_CFO[:,4*kk:]
138 print "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
139 string = "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
140 string = string + '\n'
141 fw.write(string)
142 print ""
143
144 print ""
145 print "CFO Report (Avg)"
146 print "--------------------------"
147 fw.write('\n')
148 fw.write("CFO Report (Avg)")
149 fw.write("--------------------------")
150 fw.write('\n')
151 for kk in xrange(0,5):
152 print "Subframe %d (Hz): " % kk,
153 string = "Subframe " + str(kk) + " (Hz):"
154 fw.write(string)
155 if (kk<4):
156 v_ = cumm_CFO[:,4*kk:4*kk+4]
157 print "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
158 string = "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
159 string = string + '\n'
160 fw.write(string)
161 else:
162 v_ = cumm_CFO[:,4*kk:]
163 print "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
164 string = "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
165 string = string + '\n'
166 fw.write(string)
167 print ""
168 fw.write('\n')
169
170def xor(a,b):
171 xor_result=[0]*len(a)
172 for i in range(len(a)):
173 temp = (int(a[i])^int(b[i]))
174 xor_result[i] = temp
175 return xor_result
176
177
178def diff_stable(first, second):
179 second = set(second)
180 return [item for item in first if item not in second]