Пример #1
0
eva_BER = zeros((group_num, m_num))
SC = zeros((group_num, m_num))

for i in range(group_num):
    for j in range(m_num):
        print 'Running... Current group: ', i, j

        pos_A, pos_B, pos_E = agreement(P, {'m': m[j]})
        bits_A, diagram_A, x = sender(pos_A)
        h_ab, H_ab, y_b = transmission(x)
        h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, pos_B)
        h_ae, H_ae, y_e = transmission(x)
        h_eva, H_eva, bits_eva, diagram = receiver(y_e, pos_E)
        bob_MSE[i, j] = MSE(H_ab, H_cs)
        eva_MSE[i, j] = MSE(H_ae, H_eva)
        bob_BER[i, j] = BMR(bits_A, bits_cs)
        eva_BER[i, j] = BMR(bits_A, bits_eva)
        SC[i, j] = SecCap(bob_BER[i, j], eva_BER[i, j])

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))
plt.plot(m, bob_MSE, 'ko-')
plt.xlabel('m')
plt.ylabel('MSE(dB)')
plt.title('MSE')
Пример #2
0
        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[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])

lx_MSE = mean(lx_MSE, 0)
CS_MSE = mean(CS_MSE, 0)
eva_MSE = mean(eva_MSE, 0)
lx_BER = mean(lx_BER, 0)
CS_BER = mean(CS_BER, 0)
eva_BER = mean(eva_BER, 0)
lx_SC = mean(lx_SC, 0)
CS_SC = mean(CS_SC, 0)
''' 画图 '''
plt.figure(figsize=(8, 5))
Пример #3
0
block_num = len(block_size)
bmr = zeros((group_num, block_num))
bgr = zeros((group_num, block_num))

for i in range(group_num):
    for j in range(block_num):
        print 'Running... Current group: ', i, j
        ''' 采样 '''
        rssi_A, rssi_B, rssi_E = sampling_RSSI(sampling_period, sampling_time)
        ''' RSSI量化 '''
        bits_A, drop_list_A = quantize_ASBG_1bit(rssi_A, block_size[j], coef)
        bits_B, drop_list_B = quantize_ASBG_1bit(rssi_B, block_size[j], coef)
        bits_A = remain(bits_A, drop_list_B)
        bits_B = remain(bits_B, drop_list_A)
        ''' 评价性能 '''
        bmr[i, j] = BMR(bits_A, bits_B)
        bgr[i, j] = BGR(bits_A, sampling_time, sampling_period)

bmr = mean(bmr, 0)
bgr = mean(bgr, 0)
''' 画图 '''
plt.figure(figsize=(8, 5))
plt.plot(block_size, bmr, 'ko-')
plt.xlabel('Block size')
plt.ylabel('BMR')
plt.title('BMR of different block sizes(coef=%.2f)' % coef)
plt.show()

plt.figure(figsize=(8, 5))
plt.plot(block_size, bgr, 'ko-')
plt.xlabel('Block size')
Пример #4
0
for i in range(gro_num):
    for j in range(SNR_num):
        print 'Running... Current group: ', i, j
        ''' Random pilot '''
        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_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, L, K, N, Ncp, pos_A,
                                                   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)
        random_MSE[i, j] = MSE(H_ab, H_cs)
        random_eva_MSE[i, j] = MSE(H_ab, H_eva)
        random_BER[i, j] = BMR(bits_A, bits_cs)
        random_eva_BER[i, j] = BMR(bits_A, bits_eva)
        random_SC[i, j] = SecCap(random_BER[i, j], random_eva_BER[i, j])
        ''' Even pilot '''
        pos_A = pos_B = pos_E = pos_even
        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_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, L, K, N, Ncp, pos_A,
                                                   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)
        even_MSE[i, j] = MSE(H_ab, H_cs)
        even_eva_MSE[i, j] = MSE(H_ab, H_eva)
        even_BER[i, j] = BMR(bits_A, bits_cs)
        even_eva_BER[i, j] = BMR(bits_A, bits_eva)
Пример #5
0
bgr = zeros((group_num,condi_num,qtype_num))

for i in range(group_num):
    for j in range(condi_num):
        for k in range(qtype_num):
            print 'Running... Current group: ',i,j,k
        	
            ''' 采样 '''
            phase_A,phase_B,phase_E = mod(sampling('Phase',sampling_period,sampling_time,0.9,0.4), 2*pi)

            ''' Phase量化 '''
            bits_A = quantization_even('Phase',phase_A,size(phase_A),qtype[k],order[j])
            bits_B = quantization_even('Phase',phase_B,size(phase_B),qtype[k],order[j])    
            
            ''' 评价性能 '''
            bmr[i,j,k] = BMR(bits_A,bits_B)
            bgr[i,j,k] = BGR(bits_A,sampling_time,sampling_period)

bmr = mean(bmr,0)
bgr = mean(bgr,0)

''' 画图 '''
plt.figure(figsize=(8,5))
plt.plot(order,bmr[:,0],'ko-',label=qtype[0])
plt.plot(order,bmr[:,1],'k^:',label=qtype[1])
plt.xlabel('Quantize Order')
plt.ylabel('BMR')
plt.title('BMR of different order')
plt.legend()
plt.show()
Пример #6
0
for i in range(gro_num):
    for j in range(SNR_num):
        print 'Running... Current group: ', i, j
        ''' CS '''
        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_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, L, K, N, Ncp, pos_A,
                                                   modulate_type, 'CS')
        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, 'CS')
        CS_MSE[i, j] = MSE(H_ab, H_cs)
        CS_eva_MSE[i, j] = MSE(H_ae, H_eva)
        CS_BER[i, j] = BMR(bits_A, bits_cs)
        CS_eva_BER[i, j] = BMR(bits_A, bits_eva)
        CS_SC[i, j] = SecCap(CS_BER[i, j], CS_eva_BER[i, j])
        ''' LS '''
        pos_A = pos_B = pos_E = pos_ls
        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_ls, H_ls, bits_ls, diagram_ls = receiver(y_b, L, K, N, Ncp, pos_B,
                                                   modulate_type, 'LS')
        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, 'LS')
        LS_MSE[i, j] = MSE(H_ab, H_ls)
        LS_eva_MSE[i, j] = MSE(H_ae, H_eva)
        LS_BER[i, j] = BMR(bits_A, bits_ls)
        LS_eva_BER[i, j] = BMR(bits_A, bits_eva)
Пример #7
0
h_lx, H_lx, bits_lx, diagram_lx = receiver(y_b, L, K, N, M, Ncp, Nt, Nr, pos_A,
                                           modulate_type)
''' 接收端 信道估计'''
h_cs, H_cs, bits_cs, diagram_cs = receiver(y_b, L, K, N, M, Ncp, Nt, Nr, pos_B,
                                           modulate_type)
''' 窃听信道 '''
h_ae, H_ae, y_e = transmission(x, L, K, N, M, Ncp, Nt, Nr, SNR)
''' 非法用户 '''
h_eva, H_eva, bits_eva, diagram_eva = receiver(y_e, L, K, N, M, Ncp, Nt, Nr,
                                               pos_E, modulate_type)
''' 评价性能 '''
lx_MSE = MSE(H_ab[0, 0, :], H_lx[0, 0, :, 0])
CS_MSE = MSE(H_ab[0, 0, :], H_cs[0, 0, :, 0])
eva_MSE = MSE(H_ae[0, 0, :], H_eva[0, 0, :, 0])

lx_BER = BMR(bits_A, bits_lx)
CS_BER = BMR(bits_A, bits_cs)
eva_BER = BMR(bits_A, bits_eva)

lx_SC = SecCap(lx_BER, eva_BER)
CS_SC = SecCap(CS_BER, eva_BER)
''' 打印信息 '''
print lx_MSE, CS_MSE, eva_MSE
print lx_BER, CS_BER, eva_BER
print lx_SC, CS_SC
''' 画图 '''
# 第一个发送天线
plot(h_ab[0, 0, :], H_ab[0, 0, :], diagram_A, h_cs[0, 0, :, 0],
     H_cs[0, 0, :, 0], diagram_cs)
# 第二个发送天线
plot(h_ab[0, 1, :], H_ab[0, 1, :], diagram_A, h_cs[0, 1, :, 0],
Пример #8
0
for i in range(gro_num):
    for j in range(P_num):
        print 'Running... Current group: ', i, j

        pos_A, pos_B, pos_E = agreement(P[j])
        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)
        h_ae, H_ae, y_e = transmission(x, L, K, N, Ncp, SNR)
        h_eva, H_eva, bits_eva, diagram = receiver(y_e, L, K, N, Ncp, pos_E,
                                                   modulate_type)
        val_MSE[i, j] = MSE(H_ab, H_lx)
        eva_MSE[i, j] = MSE(H_ae, H_eva)
        val_BER[i, j] = BMR(bits_A, bits_lx)
        eva_BER[i, j] = BMR(bits_A, bits_eva)
        SC[i, j] = SecCap(val_BER[i, j], eva_BER[i, j])

val_MSE = mean(val_MSE, 0)
eva_MSE = mean(eva_MSE, 0)
val_BER = mean(val_BER, 0)
eva_BER = mean(eva_BER, 0)
SC = mean(SC, 0)
''' 画图 '''
plt.figure(figsize=(8, 5))
plt.plot(P, val_MSE, 'ko-', label='Bob')
plt.plot(P, eva_MSE, 'ks--', label='Eve')
plt.xlabel('Pilot Amount')
plt.ylabel('MSE(dB)')
plt.title('MSE')
Пример #9
0
coef = 0.8
''' 多组取平均 '''
group_num = 10
condi_num = 3
bmr = zeros((group_num, condi_num))
bgr = zeros((group_num, condi_num))

for i in range(group_num):
    print 'Running... Current group: ', i
    ''' 采样 '''
    rssi_A, rssi_B, rssi_E = sampling('RSSI', sampling_period, sampling_time,
                                      0.9, 0.4)
    ''' RSSI均匀量化 '''
    bits_A = quantization_even('RSSI', rssi_A, block_size, qtype, order)
    bits_B = quantization_even('RSSI', rssi_B, block_size, qtype, order)
    bmr[i, 0] = BMR(bits_A, bits_B)
    bgr[i, 0] = BGR(bits_A, sampling_time, sampling_period)

    bits_A = quantization_even('RSSI', rssi_A, size(rssi_A), qtype, order)
    bits_B = quantization_even('RSSI', rssi_B, size(rssi_A), qtype, order)
    bmr[i, 1] = BMR(bits_A, bits_B)
    bgr[i, 1] = BGR(bits_A, sampling_time, sampling_period)
    ''' RSSI阈值量化 '''
    bits_A, drop_list_A = quantization_thre(rssi_A, block_size, coef)
    bits_B, drop_list_B = quantization_thre(rssi_B, block_size, coef)
    bits_A = remain(bits_A, drop_list_A, drop_list_B)
    bits_B = remain(bits_B, drop_list_A, drop_list_B)
    ''' 评价性能 '''
    bmr[i, 2] = BMR(bits_A, bits_B)
    bgr[i, 2] = BGR(bits_A, sampling_time, sampling_period)
''' 画图 '''