📄 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 + -