📄 vitdec.m
字号:
function [xx, BestMetric] = VitDec(G, y, ZeroTail);
%
% VitDec This function performs Viterbi Decoding for Hard Decision Inputs
%
% Inputs: G = [g1; g2; ...; gN] - matrix of generation polynomials
% y - encoded sequence
% ZeroTail - 1/0 - defines if contains zero tail
%
% Outputs: xx - recovered encoded bits
% BestMetric - final best metric
%
% Rule = MINIMUM METRIC WINS (MSE function)
%
L = size(G, 1); % --- num of output chips
K= size(G, 2); % --- length of generation polinom
N = 2^(K-1); % --- number of states
T = length(y)/L; % --- maximum trellis depth
%------- Output Generation Matrix Definition (contains all possible state transactions)-------------
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
%---------------------------------------------------------------------------------------------
%------------------------------------ Trellis SECTION ----------------------------------
%---------------------------------------------------------------------------------------------
%------- Path Mertrix Initialization -------------
PathMet = [0; 100*ones((N-1), 1)]; % Initial State = 0 (better initial conditions)
PathMetTemp = PathMet(:,1);
Trellis = zeros(N, T);
Trellis(:,1) = [0 : (N-1)]';
%------------------------ MAIN Trellis Calculation Loop ---------------------------
y = reshape(y, L, length(y)/L);
for t = 1:T
yy = y(:, t)';
for s = 0:N/2-1
[B0 ind0] = min( PathMet(1+[2*s, 2*s+1]) + [sum(abs(OutMtrx(1+2*s, 0+[1:L]) - yy).^2); sum(abs(OutMtrx(1+(2*s+1), 0+[1:L]) - yy).^2)] );
[B1 ind1] = min( PathMet(1+[2*s, 2*s+1]) + [sum(abs(OutMtrx(1+2*s, L+[1:L]) - yy).^2); sum(abs(OutMtrx(1+(2*s+1), L+[1:L]) - yy).^2)] );
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
%---------------------------------------------------------------------------------------------
%---------------------------------- Trace Back Section -----------------------------
%---------------------------------------------------------------------------------------------
%------- Find Best Path Mertric -------------
xx = zeros(T, 1);
if (ZeroTail)
BestInd = 1;
else
[Mycop, BestInd] = min(PathMet);
end
BestMetric = PathMet(BestInd);
xx(T) = floor((BestInd-1)/(N/2));
%------------------------ MAIN Trace Back Loop ---------------------------
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -