eva_BER = zeros((group_num, right_num)) lx_SC = zeros((group_num, right_num)) CS_SC = zeros((group_num, right_num)) for i in range(group_num): for j in range(right_num): print 'Running... Current group: ', i, j ''' 根据RSSI/Phase产生随机导频图样''' pos_A, pos_B, pos_E = agreement(P) ''' 发送端 ''' bits_A, diagram_A, x = sender(pos_A) ''' 信道传输 ''' h_ab, H_ab, y_b = transmission(x) ''' 理想条件下的信道估计''' # 合法用户确切知道发送端导频 h_lx, H_lx, bits_lx, diagram_lx = receiver(y_b, pos_A, 'CS', 'from_pos') ''' 接收端 信道估计''' h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, pos_B, 'CS', 'from_pos') ''' 窃听信道 ''' h_ae, H_ae, y_e = transmission(x) ''' 非法用户 ''' # 非法用户随机猜测导频位置。与发送端的导频图样pos_A相比,非法用户猜对了j个,j取值[0,P) h_eva, H_eva, bits_eva, diagram_eva = receiver(y_e, pos_A, 'CS', '%d' % (j)) ''' 评价性能 ''' lx_MSE[i, j] = MSE(H_ab, H_lx) CS_MSE[i, j] = MSE(H_ab, H_cs) eva_MSE[i, j] = MSE(H_ae, H_eva) lx_BER[i, j] = BMR(bits_A, bits_lx) CS_BER[i, j] = BMR(bits_A, bits_cs)
eva_BER = zeros((gro_num, SNR_num)) lx_SC = zeros((gro_num, SNR_num)) CS_SC = zeros((gro_num, SNR_num)) for i in range(gro_num): for j in range(SNR_num): print 'Running... Current group: ', i, j ''' 根据RSSI/Phase产生随机导频图样''' pos_A, pos_B, pos_E = agreement(P) ''' 发送端 ''' bits_A, diagram_A, x = sender(pos_A) ''' 信道传输 ''' h_ab, H_ab, y_b = transmission(x, SNR[j]) ''' 理想条件下的信道估计''' # 合法用户确切知道发送端导频 h_lx, H_lx, bits_lx, diagram_lx = receiver(y_b, pos_A) ''' 接收端 信道估计''' h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, pos_B) ''' 窃听信道 ''' h_ae, H_ae, y_e = transmission(x, SNR[j]) ''' 非法用户 ''' h_eva, H_eva, bits_eva, diagram = receiver(y_e, pos_E) ''' 评价性能 ''' lx_MSE[i, j] = MSE(H_ab, H_lx) CS_MSE[i, j] = MSE(H_ab, H_cs) eva_MSE[i, j] = MSE(H_ae, H_eva) lx_BER[i, j] = BMR(bits_A, bits_lx) CS_BER[i, j] = BMR(bits_A, bits_cs) eva_BER[i, j] = BMR(bits_A, bits_eva) lx_SC[i, j] = SecCap(lx_BER[i, j], eva_BER[i, j]) CS_SC[i, j] = SecCap(CS_BER[i, j], eva_BER[i, j])
eva_BER = zeros((gro_num, SNR_num)) lx_SC = zeros((gro_num, SNR_num)) CS_SC = zeros((gro_num, SNR_num)) for i in range(gro_num): for j in range(SNR_num): print 'Running... Current group: ', i, j ''' 根据RSSI/Phase产生随机导频图样''' pos_A, pos_B, pos_E = agreement(P) ''' 发送端 ''' bits_A, diagram_A, x = sender(N, Ncp, pos_A, modulate_type) ''' 信道传输 ''' h_ab, H_ab, y_b = transmission(x, L, K, N, Ncp, SNR[j]) ''' 理想条件下的信道估计''' # 合法用户确切知道发送端导频 h_lx, H_lx, bits_lx, diagram_lx = receiver(y_b, L, K, N, Ncp, pos_A, modulate_type) ''' 接收端 信道估计''' h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, L, K, N, Ncp, pos_B, modulate_type) ''' 窃听信道 ''' h_ae, H_ae, y_e = transmission(x, L, K, N, Ncp, SNR[j]) ''' 非法用户 ''' h_eva, H_eva, bits_eva, diagram = receiver(y_e, L, K, N, Ncp, pos_E, modulate_type) ''' 评价性能 ''' lx_MSE[i, j] = MSE(H_ab, H_lx) CS_MSE[i, j] = MSE(H_ab, H_cs) eva_MSE[i, j] = MSE(H_ae, H_eva) lx_BER[i, j] = BMR(bits_A, bits_lx) CS_BER[i, j] = BMR(bits_A, bits_cs) eva_BER[i, j] = BMR(bits_A, bits_eva)
SC = zeros((gro_num, SNR_num, etype_num)) for i in range(gro_num): for j in range(SNR_num): for k in range(etype_num): print 'Running... Current group: ', i, j, k if etype[k] == 'CS': pos_A = pos_B = get_random_pilot(N, P) pos_E = get_random_pilot(N, P) elif etype[k] == 'LS': pos_A = pos_B = pos_E = pos_ls bits_A, diagram_A, x = sender(pos_A) h_ab, H_ab, y_b = transmission(x, SNR[j]) h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, pos_B, etype[k]) h_ae, H_ae, y_e = transmission(x, SNR[j]) h_eva, H_eva, bits_eva, diagram = receiver(y_e, pos_E, etype[k]) bob_MSE[i, j, k] = MSE(H_ab, H_cs) eva_MSE[i, j, k] = MSE(H_ab, H_eva) bob_BER[i, j, k] = BMR(bits_A, bits_cs) eva_BER[i, j, k] = BMR(bits_A, bits_eva) SC[i, j, k] = SecCap(bob_BER[i, j, k], eva_BER[i, j, k]) bob_MSE = mean(bob_MSE, 0) eva_MSE = mean(eva_MSE, 0) bob_BER = mean(bob_BER, 0) eva_BER = mean(eva_BER, 0) SC = mean(SC, 0) ''' 画图 ''' plt.figure(figsize=(8, 5))
for i in range(gro_num): for j in range(right_num): print 'Running... Current group: ',i,j ''' 根据RSSI/Phase产生随机导频图样''' pos_A,pos_B,pos_E = agreement(P) ''' 发送端 ''' bits_A,diagram_A,x = sender(N,Ncp,pos_A,modulate_type) ''' 信道传输 ''' h_ab,H_ab,y_b = transmission(x,L,K,N,Ncp,SNR) ''' 理想条件下的信道估计''' # 合法用户确切知道发送端导频 h_lx,H_lx,bits_lx,diagram_lx = receiver(y_b,L,K,N,Ncp,pos_A,modulate_type,'CS','from_pos') ''' 接收端 信道估计''' h_cs,H_cs,bits_cs,diagram_cs = receiver(y_b,L,K,N,Ncp,pos_B,modulate_type,'CS','from_pos') ''' 窃听信道 ''' h_ae,H_ae,y_e = transmission(x,L,K,N,Ncp,SNR) ''' 非法用户 ''' # 非法用户随机猜测导频位置。与发送端的导频图样pos_A相比,非法用户猜对了j个,j取值[0,P) h_eva,H_eva,bits_eva,diagram_eva = receiver(y_e,L,K,N,Ncp,pos_A,modulate_type,'CS','%d'%(j)) ''' 评价性能 ''' lx_MSE[i,j] = MSE(H_ab,H_lx) CS_MSE[i,j] = MSE(H_ab,H_cs) eva_MSE[i,j] = MSE(H_ae,H_eva)
L = 50 # 信道长度 K = 6 # 稀疏度/多径数,满足:K<<L N = 512 # 训练序列长度/载波数,满足:L<=N Ncp = 64 # 循环前缀的长度,Ncp>L modulate = 4 # 星座调制 P = 36 # 导频数,P<N SNR = 20 # AWGN信道信噪比 ''' 根据RSSI/Phase产生随机导频图样''' pos_A, pos_B, pos_E = agreement(P) ''' 发送端 ''' bits_A, diagram_A, x = sender(pos_A, N, Ncp, modulate) ''' 信道传输 ''' h_ab, H_ab, y_b = transmission(x, SNR, L, K, N, Ncp) ''' 理想条件下的信道估计''' # 合法用户确切知道发送端导频 h_lx, H_lx, bits_lx, diagram_lx = receiver(y_b, pos_A, 'CS', 'from_pos', L, K, N, Ncp, modulate) ''' 接收端 信道估计''' h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, pos_B, 'CS', 'from_pos', L, K, N, Ncp, modulate) ''' 窃听信道 ''' h_ae, H_ae, y_e = transmission(x, SNR, L, K, N, Ncp) ''' 非法用户 ''' h_eva, H_eva, bits_eva, diagram_eva = receiver(y_e, pos_E, 'CS', 'from_pos', L, K, N, Ncp, modulate) ''' 评价性能 ''' lx_MSE = MSE(H_ab, H_lx) CS_MSE = MSE(H_ab, H_cs) eva_MSE = MSE(H_ae, H_eva) lx_BER = BMR(bits_A, bits_lx) CS_BER = BMR(bits_A, bits_cs)