www.gusucode.com > matlab通信工程仿真源码(张德丰等编著)程序书籍 > matlab_code/matlab通信工程仿真源码(张德丰等编著)/第10章/SoftVitDec.m

    function [xx, BestMetric] = SoftVitDec(G, y, ZeroTail); 
% 此函数是实现软判决输入的Viterbi译码  
% G为生成多项式的矩阵
% y为输入的待译码序列 
% ZeroT为判断是否包含‘0’尾
% xx为Viterbi译码输出序列 
% BestMetric为最后的最佳度量
L = size(G, 1);     % 输出码片数
K= size(G, 2);      % 生成多项式的长度 
N = 2^(K-1);        % 状态数 
T = length(y)/L;    % 最大栅格深度  
OutMtrx = zeros(N, 2*L); 
for s = 1:N 
    in0 = ones(L, 1)*[0, (dec2bin((s-1), (K-1))-'0')]; 
    in1 = ones(L, 1)*[1, (dec2bin((s-1), (K-1))-'0')];      
    out0 = mod(sum((G.*in0)'), 2); 
    out1 = mod(sum((G.*in1)'), 2);      
    OutMtrx(s, :) = [out0, out1]; 
end 
OutMtrx = sign(OutMtrx-1/2); 
PathMet = [100; zeros((N-1), 1)];       % 初始状态 = 100 
PathMetTemp = PathMet(:,1);  
Trellis = zeros(N, T); Trellis(:,1) = [0 : (N-1)]'; 
y = reshape(y, L, length(y)/L); 
for t = 1:T      
    yy = y(:, t); 
    for s = 0:N/2-1 
        [B0 ind0] = max(  PathMet(1+[2*s, 2*s+1]) + [OutMtrx(1+2*s, 0+[1:L])...
 * yy; OutMtrx(1+(2*s+1), 0+[1:L])*yy] ); 
        [B1 ind1] = max(  PathMet(1+[2*s, 2*s+1]) + [OutMtrx(1+2*s, L+[1:L])...
 * yy; OutMtrx(1+(2*s+1), L+[1:L]) * yy] );          
        PathMetTemp(1+[s, s+N/2]) =  [B0; B1]; 
        Trellis(1+[s, s+N/2], t+1) = [2*s+(ind0-1); 2*s + (ind1-1)];         
    end 
   PathMet = PathMetTemp;      
end 
xx = zeros(T, 1); 
if (ZeroTail) 
    BestInd = 1; 
else 
    [Mycop, BestInd]  = max(PathMet); 
end 	 
BestMetric = PathMet(BestInd); 
xx(T) = floor((BestInd-1)/(N/2));  
NextState = Trellis(BestInd, (T+1)); 
for t=T:-1:2 
    xx(t-1) = floor(NextState/(N/2)); 
    NextState = Trellis( (NextState+1), t); 
end  
if (ZeroTail) 
    xx = xx(1:end-K+1); 
end