ust = zeros(mtype_num) ''' 采样 ''' rssi_A,rssi_B,rssi_E = sampling('RSSI',sampling_period,sampling_time,0.8,0.4) phase_A,phase_B,phase_E = mod(sampling('Phase',sampling_period,sampling_time,0.8,0.4),2*pi) ''' RSSI量化 ''' bits_A_rssi,drop_list_A = quantization_thre(rssi_A,block_size,coef) bits_B_rssi,drop_list_B = quantization_thre(rssi_B,block_size,coef) bits_A_rssi = remain(bits_A_rssi,drop_list_A,drop_list_B) ''' Phase量化 ''' bits_A_phase = quantization_even('Phase',phase_A,size(phase_A),qtype,order) ''' 合并 ''' bits_A_cross = merge(bits_A_rssi,bits_A_phase,'cross') bits_A_and = merge(bits_A_rssi,bits_A_phase,'and') bits_A_or = merge(bits_A_rssi,bits_A_phase,'or') ''' 评价性能 ''' ust[0] = UST(bits_A_rssi) ust[1] = UST(bits_A_phase) ust[2] = UST(bits_A_cross) ust[3] = UST(bits_A_and) ust[4] = UST(bits_A_or) ''' 画图 ''' labels = ['RSSI Only', 'Phase Only', 'Cross', 'AND', 'OR'] plt.figure(figsize=(8,5)) for x,y in zip(arange(len(labels)),ust): plt.bar(x+1,ust[x],width=0.5,facecolor='lightgray',edgecolor='black')
''' cross ''' begin = datetime.datetime.now() for i in range(gro_num): print 'Running... Current group: cross, ', i ''' RSSI量化 ''' bits_A_rssi, drop_list_A = quantization_thre(rssi_A, block_size, coef) bits_B_rssi, drop_list_B = quantization_thre(rssi_B, block_size, coef) bits_A_rssi = remain(bits_A_rssi, drop_list_A, drop_list_B) bits_B_rssi = remain(bits_B_rssi, drop_list_A, drop_list_B) ''' Phase量化 ''' bits_A_phase = quantization_even('Phase', phase_A, size(phase_A), qtype, order) bits_B_phase = quantization_even('Phase', phase_B, size(phase_B), qtype, order) ''' 合并 ''' bits_A = merge(bits_A_rssi, bits_A_phase, 'cross') bits_B = merge(bits_B_rssi, bits_B_phase, 'cross') end = datetime.datetime.now() times.append(end - begin) ''' and ''' begin = datetime.datetime.now() for i in range(gro_num): print 'Running... Current group: and, ', i ''' RSSI量化 ''' bits_A_rssi, drop_list_A = quantization_thre(rssi_A, block_size, coef) bits_B_rssi, drop_list_B = quantization_thre(rssi_B, block_size, coef) bits_A_rssi = remain(bits_A_rssi, drop_list_A, drop_list_B) bits_B_rssi = remain(bits_B_rssi, drop_list_A, drop_list_B) ''' Phase量化 ''' bits_A_phase = quantization_even('Phase', phase_A, size(phase_A), qtype, order)
''' Phase Only ''' bits_A_phase = quantize_phase(phase_A) bits_B_phase = quantize_phase(phase_B) else: for j in range(group_num): ''' RSSI量化 ''' bits_A_rssi, drop_list_A = quantize_ASBG_1bit(rssi_A) bits_B_rssi, drop_list_B = quantize_ASBG_1bit(rssi_B) bits_A_rssi = remain(bits_A_rssi, drop_list_B) bits_B_rssi = remain(bits_B_rssi, drop_list_A) ''' Phase量化 ''' bits_A_phase = quantize_phase(phase_A) bits_B_phase = quantize_phase(phase_B) ''' 合并 ''' bits_A = merge(bits_A_rssi, bits_A_phase, mtype[i]) bits_B = merge(bits_B_rssi, bits_B_phase, mtype[i]) end = datetime.datetime.now() # 转化成毫秒ms,并求每组样例的平均耗时。另Alice和Bob同时做量化,因此除2求每个人的耗时 times[i] = (end - begin).total_seconds() * 1000 / group_num / 2 ''' 画图 ''' labels = ['RSSI Only', 'Phase Only', 'Cross', 'AND', 'OR', 'XOR', 'Syn'] plt.figure(figsize=(8, 5)) for x, y in zip(arange(len(labels)), times): plt.bar(x + 1, times[x], width=0.5, facecolor='lightgray', edgecolor='black') plt.text(x + 1 + 0.25,