?? viterbi.m
字號:
function decode_out=viterbi(RX_I,RX_Q,FrameLength)
%**************************************************************************
% creat the output for each state
%**************************************************************************
G1=171;
G2=133;
G1_vector=fliplr(dec2binvec(oct2dec(G1)));
G2_vector=fliplr(dec2binvec(oct2dec(G2)));
shift_d=zeros(1,6);
N=64; % the number of the state
for i=1:N
shift_d(1:6)=fliplr(dec2binvec(i-1,6));
t1=0;
t2=0;
for j=1:6
t1=xor(t1,and(shift_d(j),G1_vector(j+1)));
t2=xor(t2,and(shift_d(j),G2_vector(j+1)));
end;
I1=xor(t1,1); % when the input data is '1'
Q1=xor(t2,1);
I0=t1; % when the input data is '0'
Q0=t2;
M_State(i,1)=binvec2dec([Q0 I0])+1;
M_State(i,2)=binvec2dec([Q1 I1])+1;
end;
%**************************************************************************
% initialization
%**************************************************************************
Depth_TraceBack=40;
State0_Init=0;
NL=length(RX_I); % the length of the input data
HalfState=32;
for i=1:64
OldState(i,1)=64;
OldState(i,2)=0;
end;
OldState(1,1)=State0_Init;
m=0;
%**************************************************************************
% the metrics and pathes update
%**************************************************************************
for i=1:NL
M(1)=RX_I(i)+RX_Q(i); % when the output of the state is '00';
M(2)=RX_I(i)+binvec2dec(not(dec2binvec(RX_Q(i),3))); % when the output of the state is '01';
M(3)=binvec2dec(not(dec2binvec(RX_I(i),3)))+RX_Q(i); % when the output of the state is '10';
M(4)=binvec2dec(not(dec2binvec(RX_I(i),3)))+binvec2dec(not(dec2binvec(RX_Q(i),3))); % when the output of the state is '11'.
for j=1:HalfState
if (OldState(2*j-1,1)+M(M_State(2*j-1,1)))<=(OldState(2*j,1)+M(M_State(2*j,1)))
NewState(j,1)=OldState(2*j-1,1)+M(M_State(2*j-1,1));
NewState(j,2)=Fun_Shift(OldState(2*j-1,2),0,Depth_TraceBack);
else
NewState(j,1)=OldState(2*j,1)+M(M_State(2*j,1));
NewState(j,2)=Fun_Shift(OldState(2*j,2),0,Depth_TraceBack);
end;
if (OldState(2*j-1,1)+M(M_State(2*j-1,2)))<=(OldState(2*j,1)+M(M_State(2*j,2)))
NewState(j+HalfState,1)=OldState(2*j-1,1)+M(M_State(2*j-1,2));
NewState(j+HalfState,2)=Fun_Shift(OldState(2*j-1,2),1,Depth_TraceBack);
else
NewState(j+HalfState,1)=OldState(2*j,1)+M(M_State(2*j,2));
NewState(j+HalfState,2)=Fun_Shift(OldState(2*j,2),1,Depth_TraceBack);
end;
end;
OldState=NewState;
m=m+1;
% the process of traceback
if m>=Depth_TraceBack
if (m==FrameLength)
decode_out(i-Depth_TraceBack+1:i)=fliplr(dec2binvec(OldState(1,2),Depth_TraceBack)); % the process of the "lighten"
m=0;
for i=1:64
OldState(i,1)=128;
OldState(i,2)=0;
end;
OldState(1,1)=State0_Init;
else
[MinValue,IndexMin]=min(NewState(:,1));
Tmp_vector=dec2binvec(OldState(IndexMin,2),Depth_TraceBack);
decode_out(i-Depth_TraceBack+1)=Tmp_vector(Depth_TraceBack);
end;
end;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -