📄 trelica0.m
字号:
%trelica
function trellis=trelica0(K,g1,g2)
%clear all
%K=3;
%g1=[1 1 1];
%g2=[1 0 1]
trellis.mem=K-1; %memory of de code
trellis.numState=2^(K-1); %number of states
trellis.state=zeros(trellis.numState,2); %matrix of next states
trellis.out=zeros(trellis.numState,2); %matrix of output matrix
s=zeros(1,trellis.mem); %state s
%implementation os state matrix
%fist row of state matrix
for j=trellis.mem:2
s(j)=s(j-1);
end
s(1)=0;
trellis.state(1,1)=bi2de(s);
s(1)=1;
trellis.state(1,2)=bi2de(s);
%other rows of state matrix
for i=1:trellis.numState-1
s=de2bi(i);
for j=trellis.mem:2
s(j)=s(j-1);
end
s(1)=0;
trellis.state(i+1,1)=bi2de(s);
s(1)=1;
trellis.state(i+1,2)=bi2de(s);
end
%implemantation of the first columm of the output matrix
reg=zeros(1,K);
for w=1:trellis.numState ;
outg1=0;
outg2=0;
right=de2bi(w-1);
aux=length(right);
if aux<K
x=trellis.mem-aux;
gamb=zeros(1,x);
right=[right gamb];
end
aux=isempty(right);
if aux==1
right=zeros(1,trellis.mem);
end
reg=[0 right]; %ok
out1=bitand(reg,g1);
out2=bitand(reg,g2);
for j=1:2
outg1=bitxor(outg1,out1(j+1));
outg2=bitxor(outg2,out2(j+1));
end
z=[outg2 outg1];
trellis.out(w,1)=bi2de(z);
end
trellis.out;
%implemantation of the second columm of the output matrix
reg=zeros(1,K);
for w=1:trellis.numState
outg1=1;
outg2=1;
right=de2bi(w-1);
aux=length(right);
if aux<K
x=trellis.mem-aux;
gamb=zeros(1,x);
right=[right gamb];
end
aux=isempty(right);
if aux==1
right=zeros(1,trellis.mem);
end
reg=[1 right]; %ok
out1=bitand(reg,g1);
out2=bitand(reg,g2);
for j=1:2
outg1=bitxor(outg1,out1(j+1));
outg2=bitxor(outg2,out2(j+1));
end
z=[outg2 outg1];
trellis.out(w,2)=bi2de(z);
end
trellis.out;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -