blob: 7a6fb4b7d5713e02e8de4819b0342b680c0c5fc7 [file] [log] [blame]
import math
import numpy as np
class L:
fw = None
@staticmethod
def logopen(f_path):
L.fw = open(f_path,"w")
@staticmethod
def info(infostr):
print infostr
file_string = infostr + '\n'
L.fw.write(file_string)
@staticmethod
def logclose():
L.fw.close()
L.fw = None
def bi2de(binary):
decValue = int(binary, 2)
return decValue
def twos_comp(val, bits):
"""compute the 2's compliment of int value val"""
if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
val = val - (1 << bits) # compute negative value
return val
def readTimeInfoFile(time_file_path):
print "\n"
print "Opening Time Info File...."
# Determine number of time stamps in the file
fr_TIME = open(time_file_path,"r+")
time_file_line_count = 0
while True:
time_file_line_count = time_file_line_count + 1
if fr_TIME.readline() == '':
time_file_line_count = time_file_line_count - 1
break
# Read and store all time stamps
fr_TIME = open(time_file_path,"r+")
file_mat = [0 for y in range(time_file_line_count)]
for kk in xrange(0,time_file_line_count):
file_mat[kk] = fr_TIME.readline()
#Determine FRC capture time boundaries
startFRC = file_mat[0]
endingFRC = file_mat[-1]
print "Time info file contains starting FRC:",
print str(int(math.floor(int(startFRC.partition(' ')[0],16) / 64))) + "(64us)"
print "Time info file contains ending FRC:",
print str(int(math.floor(int(endingFRC.partition(' ')[0],16) / 64))) + "(64us)"
return file_mat
def det_iqPairCount(inputTimeMat,frc_):
frc_64 = frc_ * 64
print "\n"
print "Input FRC:" + str(frc_) + "(64us)"
print "Identifying SIB PCC Packet Data from input FRC...."
#Covert inputFile FRC column to int
FRC_col_int = [0] * len(inputTimeMat)
for kk in xrange(0,len(inputTimeMat)):
line_string = inputTimeMat[kk]
FRC_col_int[kk] = int(line_string.partition(' ')[0],16)
#Find packet idx in Time Info File
min_FRC_idx = np.argmin([np.absolute(x-frc_64) for x in FRC_col_int])
#Accumulate packed sizes until min_FRC_idx time row
line_add = 0
for jj in xrange(0,min_FRC_idx):
line_string = inputTimeMat[jj]
line_split = line_string.split()
line_add = line_add + int(line_split[3],16)
#print [line_split[3], int(line_split[3],16), line_add]
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]) + "}"
#print [min_FRC_idx, FRC_col_int[min_FRC_idx], frc_64]
line_split = inputTimeMat[min_FRC_idx].split()
line_split_next = inputTimeMat[min_FRC_idx+1].split()
packet_size = 4 * int(line_split[3],16) #Fetch packet size
packet_frc = int(line_split[0],16) #Fetch packet start
packet_frc_next = int(line_split_next[0],16) #Fetch next packet start
frc_diff1 = frc_64 - packet_frc #Determine start and input FRC difference
frc_diff2 = packet_frc_next - packet_frc #Determine start and next(packet) FRC difference
t_diff_ratio = frc_diff1 / float(frc_diff2)
packet_fraction = int(t_diff_ratio * packet_size)
# print [packet_frc, frc_64, frc_diff1]
# print [packet_frc, packet_frc_next, frc_diff2]
# print [packet_size, t_diff_ratio, packet_fraction]
iqPair_count = 4 * line_add + packet_fraction
return iqPair_count
def CFO_stats_print( inst_CFO, cumm_CFO, cfo_count):
fw = L.fw
print ""
print "CFO Report (Instantaneous)"
print "--------------------------"
fw.write('\n')
fw.write("CFO Report (Instantaneous)")
fw.write("--------------------------")
fw.write('\n')
for kk in xrange(0,5):
print "Subframe %d (Hz):" % kk,
string = "Subframe " + str(kk) + " (Hz):"
fw.write(string)
if (kk<4):
v_ = inst_CFO[:,4*kk:4*kk+4]
print "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
string = "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
string = string + '\n'
fw.write(string)
else:
v_ = inst_CFO[:,4*kk:]
print "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
string = "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
string = string + '\n'
fw.write(string)
print ""
print ""
print "CFO Report (Avg)"
print "--------------------------"
fw.write('\n')
fw.write("CFO Report (Avg)")
fw.write("--------------------------")
fw.write('\n')
for kk in xrange(0,5):
print "Subframe %d (Hz): " % kk,
string = "Subframe " + str(kk) + " (Hz):"
fw.write(string)
if (kk<4):
v_ = cumm_CFO[:,4*kk:4*kk+4]
print "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
string = "{:10.4f} {:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]),float(v_[:,3]))
string = string + '\n'
fw.write(string)
else:
v_ = cumm_CFO[:,4*kk:]
print "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
string = "{:10.4f} {:10.4f} {:10.4f}".format(float(v_[:,0]),float(v_[:,1]),float(v_[:,2]))
string = string + '\n'
fw.write(string)
print ""
fw.write('\n')
def xor(a,b):
xor_result=[0]*len(a)
for i in range(len(a)):
temp = (int(a[i])^int(b[i]))
xor_result[i] = temp
return xor_result
def diff_stable(first, second):
second = set(second)
return [item for item in first if item not in second]