读者3代码:
1. 5G NR LDPC编码与译码,Matlab仿真链路,如下介绍:
(1)算法文档及协议文档
Matlab仿真报告.docx
R15 38.211.pdf
R15 38.212.pdf
LDPC Encoder/Decoderv2.0.pdf 详细介绍
LDPC BER性能及说明.html
(2)仿真源代码-源码实现
global system_para;
bit_len = system_para.bitlen;
rate = system_para.code_rate;
%system_para.charcode_rate = '1/5';
IterMax = system_para.Iter;
numframe = system_para.Frame;
snr = system_para.SNR;
dec_mode = system_para.dectype;
coef = 0.6;
ldpc_param = nr_ldpc_param_init(bit_len,rate);
rawbiterror = zeros(1,length(snr));
errbiterror = zeros(1,length(snr));
errFramerror = zeros(1,length(snr));
for indexx = 1 : length(snr)
snr(indexx)
pause(.5);
rawbitnum = 0;
errbitnum = 0;
errFrame = 0;
tic
for frame = 1 : numframe
source_bits = randi([0 1],1,bit_len);
[enc_bits,punctured_bits,err_info] = nr_ldpc_enc(source_bits,ldpc_param);
data_sym = modulation_bpsk(enc_bits);
modu_sig = reshape(data_sym,1,[]);
awgn_sig = awgn(modu_sig,snr(indexx));
if system_para.plot == 1
scatterplot(awgn_sig);
end
receive_sig2 = demodulation_bpsk(awgn_sig);
receive_sig = reshape(receive_sig2,1,[]);
rawbit(receive_sig2 >= 0) = 1;
rawbit(receive_sig2 < 0) = 0;
[rawnumber,~] = biterr(rawbit,enc_bits);
output_bits = nr_ldpc_dec(-receive_sig,ldpc_param,IterMax,dec_mode,coef);
[errnumber,~ ] = biterr(source_bits,output_bits);
rawbitnum = rawbitnum + rawnumber;
errbitnum = errbitnum + errnumber;
xerrFramenumber = 1 - isequal(source_bits,output_bits);
errFrame = errFrame + xerrFramenumber;
end
rawbiterror(indexx) = rawbitnum/(numframe*length(rawbit)) ;
errbiterror(indexx) = errbitnum/(numframe*length(source_bits)) ;
errFramerror(indexx) = errFrame/numframe;
toc
end
figure;
semilogy(snr,rawbiterror,'r-*');
hold on
semilogy(snr,errbiterror,'b-');
semilogy(snr,errFramerror,'k-o');
grid on
xlabel('SNR(dB)');
ylabel('Pe');
legend('误解调率','误码率','误帧率');
title();
end
(4)性能仿真曲线
2. 5G NR LDPC编码与译码,FPGA IP工程实现链路,如下介绍:
(1)FPGA工程源码
ldpc_decoder_top decoder(
.clk (sys_clk),
.rst (sys_rst),
.i_soft_llr_data (soft_llr_data),
.i_soft_llr_vld (soft_llr_vld_d),
.i_soft_llr_sop (soft_llr_sop_d),
.i_soft_llr_eop (soft_llr_eop_d),
.i_soft_llr_info (soft_llr_info),//[2:0]-z_j, [5:3]-z_set, [8:6]-bg, [12:9]-sc_idx
.o_soft_llr_rdy (soft_llr_rdy),
.o_hard_bit_data (o_hard_bit_data),
.o_hard_bit_vld (o_hard_bit_vld),
.o_hard_bit_sop (o_hard_bit_sop),
.o_hard_bit_eop (o_hard_bit_eop),
.i_hard_bit_rdy (1'b1)
);
integer derate_match;
integer ldpc_llr_comp;
integer ldpc_hardbit;
integer ldpc_report;
wire fec_din_tlast;
assign fec_din_tlast = (fec_din_tvld && fec_din_trdy && din_tlast)?1'b1:1'b0;
always@(posedge clk)
begin
fifo_dout_done <= fec_din_tvld && fec_din_trdy && fec_din_tlast;
end
ldpc_encoder u_ldpc_encoder (
.reset_n (~rst ), // input wire reset_n
.core_clk (clk ), // input wire core_clk
.s_axis_ctrl_tready (fec_ctrl_trdy ), // output wire s_axis_ctrl_tready
.s_axis_ctrl_tvalid (fec_ctrl_tvld ), // input wire s_axis_ctrl_tvalid
.s_axis_ctrl_tdata (fec_ctrl_tdata ), // input wire [39 : 0] s_axis_ctrl_tdata
.s_axis_din_tready (fec_din_trdy ), // output wire s_axis_din_tready
.s_axis_din_tvalid (fec_din_tvld ), // input wire s_axis_din_tvalid
.s_axis_din_tlast (fec_din_tlast ), // input wire s_axis_din_tlast
.s_axis_din_tdata (fec_din_tdata ), // input wire [127 : 0] s_axis_din_tdata
.m_axis_status_tready (fec_status_trdy ), // input wire m_axis_status_tready
.m_axis_status_tvalid (fec_status_tvld ), // output wire m_axis_status_tvalid
.m_axis_status_tdata (fec_status_tdata ), // output wire [39 : 0] m_axis_status_tdata
.m_axis_dout_tready (fec_dout_trdy ), // input wire m_axis_dout_tready
.m_axis_dout_tvalid (fec_dout_tvld ), // output wire m_axis_dout_tvalid
.m_axis_dout_tlast (fec_dout_tlast ), // output wire m_axis_dout_tlast
.m_axis_dout_tdata (fec_dout_tdata ) // output wire [127 : 0] m_axis_dout_tdata
IP license可用。
3. 4G LTE Turbo编码与译码,Matlab仿真链路,如下介绍:
(1)算法文档及协议文档
Turbo算法说明0820.doc
(turbo码)LTE协议的翻译-36.212-900_TDD_0912.doc
(2)仿真源代码-源码实现
%****************************************************************
% 内容概述:Turbo编码与Turbo译码链路,符合LTE标准
% 仿真链路:源比特-->Turbo编码-->速率匹配-->BPSK调制-->高斯白噪声信道-->
% BPSK解调-->解速率匹配-->Turbo译码-->BER
% 创 建 人:
% 创建时间:2014年10月21日
% 修改时间:2014年11月19日 码率R调整
% 修改时间:2020年08月20日
% 参考文献:LTE协议
% 版权声明:未经许可,不得传播,侵权必究。
%****************************************************************
clc;
clear all;
close all;
%系统参数设计------------------------------
R = 1/3 ;%码率---rate=1/3,rate=1/2
TurboIter = 8;%Turbo迭代次数,(2-8) interation_number
SourceBitlen = 512;%1024;%256;%688;%输入源比特长度 frame_size
decodermethod = 1; % 1 logMap , 2 max-log-map
sim_framernum = 10000;%越大越好,但是速度仿真速度会越慢,
SNR = -4.5 : 0.1 : -3;% -4;%0:0.1:2;%信噪比序列 -4.5 : 0.1 : -3
BerEbNo = zeros(1,length(SNR));
for nEN=1:length(SNR)
Err_counter = 0;
for nframe=1:sim_framernum
%输入源比特序列基带信号--------------------
SourceBit = round(rand(1,SourceBitlen));
%Turbo编码--------------------------------
TurboInterTable = [256,15,32;512,31,64;688,21,86;1024,31,64;1344,211,252;2624,27,164;3904,363,244;5184,31,96];
for k=1:8
if TurboInterTable(k,1)>=SourceBitlen
break;
end
end
RefLen = TurboInterTable(k,1);
F1 = TurboInterTable(k,2);
F2 = TurboInterTable(k,3);
Turbo_outzc = TurboEncode(SourceBit,SourceBitlen,RefLen,F1,F2);
%调整Turbo编码速率-R---包括算法:速率匹配删余复用,子块交织-----
OutLen = length(SourceBit)/R ;
Turbo_out = rateMatching(Turbo_outzc,OutLen,1);
%BPSK调制---------------------------------
Turbo_out1 = reshape(Turbo_out',1,[]);
Turbo_out2 = modulation(Turbo_out1,1);
%高斯白噪声信道----------------------
soft_in = awgn(Turbo_out2,SNR(nEN));
%BPSK解调---------------------------
soft_in1 = demodulation(soft_in,1)';
%Rate matching----------------------
soft_inxx = soft_in1' ;
soft_in2 = rateDeMatching(soft_inxx,3*length(Turbo_outzc),1);
%Turbo译码--------------------------
[hard_out,soft_out] = TurboDecode(soft_in2,TurboIter,RefLen,F1,F2,decodermethod);
%误码率-----------------------------
errs = length(find(hard_out(1:SourceBitlen) ~= SourceBit));
Err_counter = Err_counter + errs;
Ber = Err_counter/nframe/SourceBitlen;
%disp(['-----SNR=',num2str(SNR(nEN)),',Frame=',num2str(nframe),',Errorbit=',num2str(errs)']);
end
BerEbNo(nEN) = Ber;
fprintf('EcNo:%1.2fdB,误码率:%8.4e,\n',SNR(nEN),Ber);
end
semilogy(SNR,BerEbNo,'b-v');
grid on;
xlabel('Ec/No[dB]');
ylabel('Bit Error Rate');
title('Turbo性能仿真误码率曲线');
(3)仿真MATLAB库函数
a.基于MATLAB库函数搭建,turbo仿真链路,包含turbo编码译码,速率匹配和解速率匹配模块,调制和解调模块。TBD
b. 完全一样的源码实现模块。
(4)性能曲线
4. LTE (4G ) Turbo编码与译码,Fpga IP链路工程实现,如下介绍:
(1) IP license可用。