📄 conv_dec.m
字号:
function output=conv_dec(input)
%(2,1,3)解码器
%利用Viterbi译码,首先取输出序列的前nN个值(是约束序列的长度)
n=length(input);
%移位寄存器赋初值
a=[0 0 0 0];%到状态a b c d的第三时刻的幸存路径
b=[0 0 1 1];
c=[1 1 0 1];
d=[1 1 1 0];
for i=3:n/2 %节点数
%a状态后的两条路径
reg=[0 0 0];%input the state 0
a1=[a,mod(sum(reg),2),xor(reg(1),reg(3))];
reg=[1 0 0];%input the state 1
b1=[a,mod(sum(reg),2),xor(reg(1),reg(3))];
%b状态后的两条路径
reg=[0 1 0];%input the state 0
c1=[b,mod(sum(reg),2),xor(reg(1),reg(3))];
reg=[1 1 0];
d1=[b,mod(sum(reg),2),xor(reg(1),reg(3))];
%c状态后的两条路径
reg=[0 0 1];%input the state 0
a2=[c,mod(sum(reg),2),xor(reg(1),reg(3))];
reg=[1 0 1];%input the state 1
b2=[c,mod(sum(reg),2),xor(reg(1),reg(3))];
%d状态后的两条路径
reg=[0 1 1];%input the state 0
c2=[d,mod(sum(reg),2),xor(reg(1),reg(3))];
reg=[1 1 1];%input the state 1
d2=[d,mod(sum(reg),2),xor(reg(1),reg(3))];
if length(find(a1==input(1:2*i))==1)>length(find(a2==input(1:2*i))==1)
a=a1;
else
a=a2;
end
if length(find(b1==input(1:2*i))==1)>length(find(b2==input(1:2*i))==1)
b=b1;
else
b=b2;
end
if length(find(c1==input(1:2*i))==1)>length(find(c2==input(1:2*i))==1)
c=c1;
else
c=c2;
end
if length(find(d1==input(1:2*i))==1)>length(find(d2==input(1:2*i))==1)
d=d1;
else
d=d2;
end
end
%**************************************************************************
%****************@@@求到最后一个节点的幸存路径@@@*************************
%**************************************************************************
%**************************************************************************
%88888888888888888888888888888888888888888888888888888888888888888888888888
%88888888888888888888888888888888888888888888888888888888888888888888888888
%**************************************************************************
L(1)=length(find(a==input)==1);
L(2)=length(find(b==input)==1);
L(3)=length(find(c==input)==1);
L(4)=length(find(d==input)==1);
Lmax=max(L);
position=find(L==Lmax);
if position==1
output_pre=a;
elseif position==2
output_pre=b;
elseif position==3
output_pre=c;
else
output_pre=d;
end
%求出最后一个节点的幸存路径,作为译码器的输出,然后再将译码结果还为原序列
reg=[0 0 0];
n=length(output_pre);
if output_pre(1:2)==[1 1]
output=1;
elseif output_pre(1:2)==[0 0]
output=0;
end
for i=2:n/2
reg(1)=output(end);
for j=3:-1:2
reg(j)=reg(j-1);
end
reg(1)=0;
if input((i-1)*2+1:i*2)==[mod(sum(reg),2) xor(reg(1),reg(3))]
output=[output reg(1)];
continue;
end
reg(1)=1;
if input((i-1)*2+1:i*2)==[mod(sum(reg),2) xor(reg(1),reg(3))]
output=[output reg(1)];
continue;
else
output=[output 1];
reg(1)=1;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -