您的位置:首页 > 其它

一个简单的Viterbi解码程序

2014-04-02 23:47 246 查看
以下是一个简单的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: