1 Star 0 Fork 1

xiaodangshan/PAPR-net

forked from zhoub86/PAPR-net 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ber_plot.py 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
XieYe9909 提交于 2020-03-22 23:31 . PAPR net
import numpy as np
import matplotlib.pyplot as plt
from ofdm import OFDMTransmitter, OFDMReceiver
from initialize.params import channel, h, bit_allocation, coef
from signals import awgn
params = dict()
params['BitAllocation'] = bit_allocation
params['Coef'] = coef
params['OverSampleRate'] = 4
params['CPLength'] = 100
symbol_num = 1000
bits_per_symbol = sum(params['BitAllocation'])
bit_send = np.random.randint(0, 2, bits_per_symbol * symbol_num)
tx = OFDMTransmitter(**params)
rx = OFDMReceiver(**params)
encoder_list = [
None,
'training/encoder_3.hdf5',
'training/encoder_5.hdf5',
'training/encoder_10.hdf5',
'training/encoder_30.hdf5',
]
decoder_list = [
None,
'training/decoder_3.hdf5',
'training/decoder_5.hdf5',
'training/decoder_10.hdf5',
'training/decoder_30.hdf5',
]
sig_list = list()
for encoder in encoder_list:
if encoder:
sig = tx.transmit(bit_send, encoder=encoder, papr_net=True)
else:
sig = tx.transmit(bit_send, papr_net=False)
sig_list.append(sig)
for [i, sig] in enumerate(sig_list):
sig_list[i] = np.convolve(sig, h)[0: sig.size]
snr_list = np.arange(0, 32, 1)
ber_list = np.zeros((len(sig_list), len(snr_list)))
for [i, sig] in enumerate(sig_list):
sig_power = np.var(sig)
decoder = decoder_list[i]
for j, snr in enumerate(snr_list):
sig_n = awgn(sig, snr=snr, sig_power=sig_power)
if decoder:
bit_recv = rx.receive(sig_n, shift=rx.CPLength, channel=channel, decoder=decoder, papr_net=True)
else:
bit_recv = rx.receive(sig_n, shift=rx.CPLength, channel=channel, papr_net=False)
ber_list[i, j] = np.sum(np.logical_xor(bit_send, bit_recv)) / bit_send.size
print('%d' % j)
plt.figure()
plt.plot(snr_list, ber_list[0], label='conventional OFDM', color='b', marker='o')
plt.plot(snr_list, ber_list[1], label=r'PAPR net $ \lambda $ = 0.03', color='r', marker='o')
plt.plot(snr_list, ber_list[2], label=r'PAPR net $ \lambda $ = 0.05', color='g', marker='o')
plt.plot(snr_list, ber_list[3], label=r'PAPR net $ \lambda $ = 0.1', color='c', marker='o')
plt.plot(snr_list, ber_list[4], label=r'PAPR net $ \lambda $ = 0.3', color='m', marker='o')
plt.xlabel('snr (dB)')
plt.ylabel('BER')
plt.semilogy()
plt.legend()
plt.grid()
plt.savefig('results/ber.eps', dpi=600, format='eps')
plt.show()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenxuanlut/PAPR-net.git
git@gitee.com:chenxuanlut/PAPR-net.git
chenxuanlut
PAPR-net
PAPR-net
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385