?? 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 + -