一个简单的Viterbi解码程序

来源:互联网 发布:日事清 知乎 编辑:程序博客网 时间:2024/05/02 00:31

以下是一个简单的Viterbi解码程序的MATLAB实现。

% *********************************************% *                                           *% *   This function implements the viterbi    *% *   decoding mechanism.                     *% *                                           *% *********************************************function output = viterbi_decode(input,L,K)    ref_bit = [0 0 ; 0 1; 1 0  ; 1 1 ];    path = zeros(4,1);    for i = 1:L+2          r = kron(ones(4,1),input(2*i-1:2*i));        hs = sum(xor(r,ref_bit),2);        if (i == 1) || (i == 2)            temp_path(1,1) = path(1,1) + hs(1);            survivor_path(1,1)  = 1;                 %survivor path            temp_path(2,1) = path(3,1) + hs(3);            survivor_path(2,1)  = 3;            temp_path(3,1) = path(1,1) + hs(4);            survivor_path(3,1)  = 1;            temp_path(4,1) = path(3,1) + hs(2);            survivor_path(4,1)  = 3;        else            [temp_path(1,1), index] = min([path(1,1) + hs(1),path(2,1) + hs(4)]);%find the minimum            survivor_path(1,1)  = index;            [temp_path(2,1), index] = min([path(3,1) + hs(3),path(4,1) + hs(2)]);            survivor_path(2,1)  = index+2;            [temp_path(3,1), index] = min([path(1,1) + hs(4),path(2,1) + hs(1)]);            survivor_path(3,1)  = index;            [temp_path(4,1), index] = min([path(3,1) + hs(2),path(4,1) + hs(3)]);            survivor_path(4,1)  = index+2;        end        path = temp_path;        surPath(:,i) = survivor_path;    end    ipLUT = [0 0 0 0;0 0 0 0;1 1 0 0;0 0 1 1 ];%use as the reference    cur_state = 1;    decode = zeros(1,length(input)/2);    for j = length(input)/2:-1:1        prev_state = surPath(cur_state,j);                       %survivor path found        decode(j) = ipLUT(cur_state,prev_state);%        cur_state = prev_state;    end    output = decode;end


0 0
原创粉丝点击