?? vitdec.m
字號:
function [xx, BestMetric] = VitDec(G, y, ZeroTail);
L = size(G, 1); % 輸出比特數
K= size(G, 2); % 記憶長度
N = 2^(K-1); % 狀態數
T = length(y)/L; % trellis圖的最大深度
%------- 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')];%輸入為0時的記憶狀態(輸入+寄存器狀態)
in1 = ones(L, 1)*[1, (dec2bin((s-1), (K-1))-'0')];%輸入為1時的記憶狀態(輸入+寄存器狀態)
out0 = mod(sum((G.*in0)'), 2);%當前狀態下,輸入為0時對應的輸出
out1 = mod(sum((G.*in1)'), 2);%當前狀態下,輸入為1時對應的輸出
OutMtrx(s, :) = [out0, out1];%將兩個輸出作為矩陣的某一行存入矩陣OutMtrx中
end
%---------------------------------------------------------------------------------------------
%------------------------------------ Trellis SECTION ----------------------------------
%---------------------------------------------------------------------------------------------
%------- Path Mertrix Initialization -------------
PathMet = [0; 100*ones((N-1), 1)]; % 設定初始狀態為0狀態(0狀態初始漢明距設為0,其余狀態為100)
PathMetTemp = PathMet(:,1);
Trellis = zeros(N, T+1);%定義Trellis 矩陣
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)] );%當輸入為0時,比較到達同一狀態的兩條路徑,取較小的漢明距和與其相對應的漢明距
[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)] );%當輸入為1時,比較到達同一狀態的兩條路徑,取較小的漢明距和與其相對應的漢明距
PathMetTemp(1+[s, s+N/2]) = [B0; B1];%將得到的漢明距存在矩陣PathMetTemp中
Trellis(1+[s, s+N/2], t+1) = [2*s+(ind0-1); 2*s + (ind1-1)];%將得到的幸存路徑存于Trellis矩陣中,Trellis矩陣中存放的是到達此狀態的上一狀態
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 + -