📄 ctcdecoder.m
字号:
function CtcDecode=CtcDecoder(CtcCode,niter,index,L1)
% niter is the num of decoding iterations
% first extract the system code and parity from the CtcCode and insert
% necessary zeros into parity sequences
% g=[1 0 1 1;1 1 0 1];
%首先调用trellis函数生成网格图state_map
state_map=trellis;
%第一,四种ctc的码率是1/2,不打孔,直接把接收码字分离成syscode(信息),parity1(校验1)和parity2(校验2)即可
if index==1|index==4
leng=length(CtcCode)/2;% leng is the length of all information bits
CtcDecode=zeros(1,leng);
syscode=CtcCode(1:leng);
parity1=CtcCode(leng+1:leng*3/2);
parity2=CtcCode(leng*3/2+1:end);
% puncture=[1 1 1 1 1 1];
%第二,六种ctc的码率是2/3,需要对parity1和parity2插零
elseif index==2|index==6
leng=length(CtcCode)*2/3;
CtcDecode=zeros(1,leng);
syscode=CtcCode(1:leng);
parity1=zeros(1,leng/2);
parity2=zeros(1,leng/2);
parity1(1:2:end)=CtcCode(leng+1:leng*5/4);
parity2(1:2:end)=CtcCode(leng*5/4+1:end);
% puncture=[1 0 1 0 1 0];
%其余三种ctc码速率是3/4
else
leng=length(CtcCode)*3/4;
CtcDecode=zeros(1,leng);
syscode=CtcCode(1:leng);
parity1=zeros(1,leng/2);
parity2=zeros(1,leng/2);
parity1(1:3:end)=CtcCode(leng+1:leng*7/6);
parity2(1:3:end)=CtcCode(leng*7/6+1:end);
% puncture=[1 0 0 1 0 0];
end
%生成CTC码内交织器,alpha是原始下标交织后的位置
alpha=CtcInterleaver(syscode);
%对系统码交织
sysinterleave=syscode(alpha);
% reshape
%将syscode和parity1整合为1路-rec(1,:),sysinterleave和parity2整合为1路-rec(2,:)
rec=zeros(2,leng*3/2);
rec(1,1:3:end)=syscode(1:2:end);
rec(1,2:3:end)=syscode(2:2:end);
rec(1,3:3:end)=parity1(1:end);
rec(2,1:3:end)=sysinterleave(1:2:end);
rec(2,2:3:end)=sysinterleave(2:2:end);
rec(2,3:3:end)=parity2(1:end);
start_state1=0;
start_state2=0;
%边信息
L_e=zeros(1,leng);
%迭代译码
for iter=1:niter
%decoder 1
%将L_e解交织
L_a(alpha)=L_e;
[L_all,start_state1]=logmap(rec(1,:),state_map,L_a,iter,start_state1,L1);
%更新L_e的值
L_e(1:2:end)=L_all(1:2:end)-2*rec(1,1:3:end)-L_a(1:2:end);
L_e(2:2:end)=L_all(2:2:end)-2*rec(1,2:3:end)-L_a(2:2:end);
%decoder 2
%将L_e交织,对第二个译码器译码
L_a=L_e(alpha);
[L_all,start_state2]=logmap(rec(2,:),state_map,L_a,iter,start_state2,L1);
L_e(1:2:end)=L_all(1:2:end)-2*rec(2,1:3:end)-L_a(1:2:end);
L_e(2:2:end)=L_all(2:2:end)-2*rec(2,2:3:end)-L_a(2:2:end);
end
%所有迭代完成后,对L_all进行硬判决,并且解交织作为判决结果
CtcDecode(alpha)=(sign(L_all)+1)/2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -