📄 decodeout.m
字号:
%decode_out is last out.卷积码译码值最终输出算法,输入为软迭代编码输入,输出为软译码输出 即SISO算法。Tested 2005.4.23
function out=decodeout(x1,y1) %x1=L_encodedata1,y1=L_encoderdata2
% data=[1,0,1,1,0,1];
len=length(x1);
%x=zeros(1,len);
%y=zeros(1,len);
x=zeros(1,len+1);
y=zeros(1,len+1);
%z=zeros(1,len+1);
x(2:len+1)=x1(1:len);
y(2:len+1)=y1(1:len);
%z(2:len+1)=z1(1:len);
%out_up=zeros(1,len);
%out_down=zeros(1,len);
out=zeros(1,len); %输出值
a=zeros(len,8); %前向递归值
b=zeros(len+1,8); %后向递归值
temp=zeros(1,8); %摸板对数似然比
factor=0;
gama_with_info=0; %r的值
gama_yk0=0;
gama_yk1=0;
%initialize a0,a1,b %书上有对应
a(1,1)=1;
b(len+1,1)=1.0/len;
for i=2:8
a(1,i)=0; %1.0/len;
b(len+1,i)=1.0/len;
end
%compute the gama
judge=zeros(8,8);
c=zeros(8,8);
d=zeros(8,8,2);
%matrix judge[i][j] judge the probability of the state i turn into the state j
judge(1,1)=1;
judge(1,2)=1;
judge(2,3)=1;
judge(2,4)=1;
judge(3,5)=1;
judge(3,6)=1;
judge(4,7)=1;
judge(4,8)=1;
judge(5,1)=1;
judge(5,2)=1;
judge(6,3)=1;
judge(6,4)=1;
judge(7,5)=1;
judge(7,6)=1;
judge(8,7)=1;
judge(8,8)=1;
%the value of c(i)(j) is the input data of encoder that tansform state i into state j
c(1,1)=0;
c(1,2)=1;
c(2,3)=0;
c(2,4)=1;
c(3,5)=0;
c(3,6)=1;
c(4,7)=0;
c(4,8)=1;
c(5,1)=0;
c(5,2)=1;
c(6,3)=0;
c(6,4)=1;
c(7,5)=0;
c(7,6)=1;
c(8,7)=0;
c(8,8)=1;
%// the output data when state i turn into state j
d(1,1,1)=0;d(1,1,2)=0;%d(state,nextstate,'1'up/'2'down)=output
d(1,2,1)=1; d(1,2,2)=1;
d(2,3,1)=1;d(2,3,2)=1;
d(2,4,1)=0;d(2,4,2)=0;
d(3,5,1)=0;d(3,5,2)=1;
d(3,6,1)=1;d(3,6,2)=0;
d(4,7,1)=1;d(4,7,2)=0;
d(4,8,1)=0;d(4,8,2)=1;
d(5,1,1)=1;d(5,1,2)=1;
d(5,2,1)=0; d(5,2,2)=0;
d(6,3,1)=0;d(6,3,2)=0;
d(6,4,1)=1;d(6,4,2)=1;
d(7,5,1)=1;d(7,5,2)=0;
d(7,6,1)=0; d(7,6,2)=1;
d(8,7,1)=0;d(8,7,2)=1;
d(8,8,1)=1;d(8,8,2)=0;
%var1=computevariance(x1);
%var2=computevariance(y1);
% var1=var(x1);
Lc1=1; Lc2=1;
%Lc1=2/var1;
%Lc2=2/var2;
%compute the value of a %前向递推
for k=2:len
factor=0;
for m=1:8
temp(m)=0;
for fm=1:8
if (judge(fm,m)==0)
gama_with_info=0;
else
x_up=(2*d(fm,m,1)-1);%*(0.1746);
x_down=(2*d(fm,m,2)-1);%*(0.1746);
gama_with_info=exp(0.5*(x_up*(Lc1*x(k))+Lc2*y(k)*x_down)); %这个公式在书上
if (gama_with_info==inf)
gama_with_info=300;
elseif(gama_with_info>300)
gama_with_info=300;
end
end
temp(m)=temp(m)+gama_with_info*a(k-1,fm);
if (temp(fm)==inf)
temp(fm)=300;
end
end
factor=factor+temp(m);
end
for i=1:8
a(k,i)=temp(i)/factor; %归一化
end
end
%compute the value of b %后向递推
for k=len:-1:2
factor=0;
for fm=1:8
temp(fm)=0;
for m=1:8
if (judge(fm,m)==0)
gama_with_info=0;
else
x_up=(2*d(fm,m,1)-1);%*(0.1746);
x_down=(2*d(fm,m,2)-1);%*(0.1746);
gama_with_info=exp(0.5*(x_up*(Lc1*x(k+1))+Lc2*y(k+1)*x_down)); %这个公式在书上
if (gama_with_info==inf)
gama_with_info=300;
elseif(gama_with_info>300)
gama_with_info=300;
end
end
% factor=factor+gama_with_info*a(k,fm);
temp(fm)=temp(fm)+gama_with_info*b(k+1,m);
if (temp(fm)==inf)
temp(fm)=300;
end
end
factor=factor+temp(fm);
end
for i=1:8
b(k,i)=temp(i)/factor; %归一化
end
end
%compute the output y_up and y_down
for k=2:len+1
temp0=0; %out(k-1)=log(temp1/temp0);
temp1=0;
for m=1:8
for fm=1:8
if (judge(fm,m)==0)
gama_yk0=0; %分支度量x=-1
gama_yk1=0; %分支度量x=1
else
x_up=(2*d(fm,m,1)-1);%*(0.1746);
x_down=(2*d(fm,m,2)-1);
if (c(fm,m)==1)
gama_yk0=0;
gama_yk1=exp(0.5*(Lc1*x(k)*x_up+Lc2*y(k)*x_down));%y(x)=0,表示删余。gama_yk=1,对求a(k-1,fm),b(k,m)无影响。
else
gama_yk0=exp(0.5*(Lc1*x(k)*x_up+Lc2*y(k)*x_down));
gama_yk1=0;
end
if (gama_yk0==inf) %inf代表无穷大
gama_yk0=300;
elseif(gama_yk0>300)
gama_yk0=300;
end
if (gama_yk1==inf)
gama_yk1=300;
elseif(gama_yk1>300)
gama_yk1=300;
end
end
temp1=temp1+gama_yk1*a(k-1,fm)*b(k,m); %摸板1
temp0=temp0+gama_yk0*a(k-1,fm)*b(k,m); %摸板-1
end
end
if((temp0==0)&(temp1==0))
Temp=0;
elseif((temp0==0)&(temp1~=0))
Temp=300;
elseif((temp1==0)&(temp0~=0))
Temp=-300;
else
Temp=log(temp1/temp0);
end
if (Temp==Inf)
out(k-1)=300;
elseif(Temp==-Inf)
out(k-1)=-300;
else
out(k-1)=Temp;
end
end
%compute the decoding output
% temp = sign(out);
for i=1:len
if out(i)>0
out(i) = 1;
else out(i) = 0;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -