forked from fantasua/PolarCodesMatLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolarcode_awgn_tree.m
72 lines (58 loc) · 1.78 KB
/
polarcode_awgn_tree.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%awgn信道下的极化码性能仿真
%基本参数 N为码长,n为log2(N),k为信息长度,Zw为信道Bhattacharyya值,b为frozenbit的值
clear
FRAMES=10000%input('frames=');
MAX_FRAME_ERROR=FRAMES%input('max frame error=');
n=input('n=');
N=2^n; %参数的初始化
k=input('k='); %
R=k/N; %
SNR_dB=input('SNR_dB='); %
b=0; %
for j=1:length(SNR_dB)
%利用SNR_dB计算出误码率,利用误码率递归关系计算
SNR_not_dB(j)=10^(SNR_dB(j)/10); %转化成非dB形式
var(j)=1/(2*R*SNR_not_dB(j)); %得到噪声方差sigma^2
eb=exp(-1/(2*var(j)));
frame_error=0;
bit_err_num=zeros(1,FRAMES);
%Z=get_bec_bhattacharyya(N,eb);
%Z=get_awgn_bhattacharyya(N,var(j)); %信道的Bhattacharyya参数矩阵
Z=get_awgn_Pb(N,var(j));
[Zw,index]=sort(Z,'descend'); %按照降序排列矩阵Z
free_index=index(N-k+1:N); %信息比特的位置
frozen_index=index(1:N-k); %frozenbit的位置
uc(frozen_index)=b;
tic
for frame=1:FRAMES
%信息的生成
%u为信息向量
u=randsrc(1,k,[0 1]);
%信道的选择
%根据Bhattacharyya参数进行选择
%信息的编码
%%%%%%%%%%%%%%%%%%%编码之前的准备工作%%%%%%%%%%%%%%%%%%%%%%%%%
uc(free_index)=u;
%编码得到的码字为x
x=encoder(uc);
%AWGN信道
y=awgn_noise(x,var(j));
%译码
u_hat=decoder_tree(y,free_index,frozen_index,b,var(j));
%%input_data=u_hat(index);
%误码率
bit_err_num(frame)=biterr(u,u_hat(free_index));
if bit_err_num(frame)~=0
frame_error=frame_error+1;
end
frame
if frame_error==MAX_FRAME_ERROR
break;
end
end
FER(j)=frame_error/frame
BER(j)=sum(bit_err_num)/(k*frame)
toc
end
%semilogy(SNR_dB,BER,SNR_dB,FER)
%semilogy(SNR_dB,BER,'-+r',SNR_dB,FER,'-*b')