📄 turbo码仿真.m
字号:
clear all
L_frame=1000;
n_frame=20;
start=0;
step=2;
finish=8;
g=[1,1,1;1,0,1]; % g ------生成矩阵
[n,k]=size(g);
m=k-1;
method=1; % method ---译码方案 0--logmapo
% 1--sova0
puncture=1;% puncture----是否凿孔 0--凿孔,码率1/2
% 1--不凿孔,码率1/3
r=1/(puncture+2);
[a,Alpha]=sort(rand(1,L_frame+m)); % Alpha ---交织器 (交织器大小为 L_frame+m)
Eb=1;
plot_pe=[];
Q=1;
axis_EbN0=start:step:finish;
%******************************************************
for EbN0=start:step:finish
Liner_EbN0=10^(EbN0/10);
pe_number=0;
variance=0.5*(Eb/Liner_EbN0)/r; % 噪声方差, 来源于a^2/(2*delta^2)=Liner_EbN0,a^2信息幅值的平方即比特能量, 2*delta^2=N0. N0/r得到编码后的噪声功率谱密度
for i=1:1:n_frame
x_msg = randint(1,L_frame,2); % random bits
x_code_msg=turbo_encode( x_msg,g,Alpha,puncture); % coding
x_bpsk_msg= 2*x_code_msg-1; % BPSK modulation
rec = x_bpsk_msg+sqrt(variance)*randn(1,length(x_code_msg)); % AWGN transmission
x_decode_msg=turbo_decode(rec,g,Alpha,puncture,niter,method);
pe_number=pe_number+sum(x_msg~=x_decode_msg);
current_time=fix(clock);
fprintf('i am working %g %g年 %g月 %g日 %g时 %g分 %g秒\n\n',Q,current_time(1),current_time(2),current_time(3),current_time(4),current_time(5),current_time(6))
Q=Q+1;
fprintf('\n\n')
end
pe=pe_number/(L_frame*n_frame);
plot_pe=[plot_pe,pe];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
semilogy(axis_EbN0,plot_pe,'b*-')
xlabel('Eb/N0 信号功率/噪声功率(db)')
ylabel('BER')
title('误码率')
grid on
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -