📄 vit_dec.m
字号:
function decod = vit_dec(u,constlen,codegen, puncpat) %
% hardvit.m -- Hard decision decoding Viterbi algorithm.
% Default Rate = k/n without function
[next_state,output] = trellisgen(constlen,codegen);
WindowLen = 1; % tblen=10;
[in_len out_len] = size(codegen); % in_len=k, out_len=n (without punc)
% Initialize the Viterbi algorithm. dH.m is a function to compute the
% Hamming distance, which is the path metric that is minimized for
% hard decision decoding.
initvit2(next_state, output, WindowLen, 'dH'); % sqerr2 or dH
svec = []; % Initialize state sequence through trellis to empty.
% The output from the Viterbi algorithm will be svec.
%% DEPUNC (u to v)
k=0;i=0;
while (i<length(u))
for j=1:length(puncpat)
if (puncpat(j) == 0)
k = k+1;
v(k) = 0;
else
k = k+1;
i = i+1;
v(k) = u(i);
end
end
end
%%
% out_len = length(codegen);
T = length(v)/out_len; % Number of message bits to send through channel
for t = 1:T
first = out_len*t-(out_len-1);
last = out_len*t;
x=v(first:last);
s = viterbi2(x); % returns state estimate WindowLen in the past,
if (s) % or s is empty if not enough bits through channel.
svec = [svec, s];
end
end % Loop t=1:T
% Flush remaining paths through trellis
svec = [svec, vitflush(0)];
% Translate estimate of states, svec, to estimates of message bits
% state-to-message bit conversion matrix:
wh=zeros(1,T); j = length(constlen);
for t=1:T
for i=1:size(next_state,2)
if (svec(t+1)-1==next_state(svec(t),i))
ww = bitget(uint8(i-1), j:-1:1);
first = in_len*t-(in_len-1);
last = in_len*t;
wh(first:last) = ww;
% wh = [wh i-1];
end
end
end
% disp('decoder output by This program')
% disp(double(wh))
decod = double(wh);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -