⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viterbi.m

📁 viterbi译码以及psk调制解调的源程序
💻 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 + -