📄 viterbi_decoder_acs217.m
字号:
function [sys,x0,str,ts] = viterbi_decoder_acs217(t,x,u,flag)
switch flag,
case 0,
[sys, x0, str, ts] = mdlInitializeSizes(t, x, u);
case 2,
sys = mdlUpdate(t,x,u);
case 3,
sys = mdlOutputs(t,x,u);
case 9,
sys = [];
otherwise
error(['unhandled flag = ', num2str(flag)]);
end
%end dsfunc
%
%=======================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=======================================================================
%
function [sys, x0, str, ts] = mdlInitializeSizes(t, x, u)
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 6852; %6628+132;
sizes.NumOutputs = 1;
sizes.NumInputs = 4;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = zeros(1,sizes.NumDiscStates);
str = [];
ts = [-1.0 0.0];
% end mdlInitializeSizes
%
%=======================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=======================================================================
%
function sys = mdlUpdate(t, x, u)
%%%%%%initialize%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
met_in = u;
% for i1 = 1 : 132
% met_in_D(i1) = x(6700+i1);
% end
met_in_D(1:132) = x(6721:6852);
met_in_D(133:136) = met_in;
met_ac = x(1:64);
rout = zeros(3,64,35);
% for i1 = 1 : 6528 %% 3*64*34 = 6528
% rout(i1) = x(100+i1);
% end
rout(1:6528) = x(101:6628);
if rout == 0
rout(1,1,1:33) = 1;
rout(2,1,1:33) = 1;
rout(3,1,1:33) = 0;
rout(:,1,34) = [1 1 2]';
% rout(:,1,33) = [1 0 2]';
% rout(:,1,34) = [0 0 0]';
% rout(:,2,34) = [2 3 4]';
met_ac = zeros(64,1);
end
trellis217 = trellis217_fcn;
met_ac_tmp1 = zeros(64,1);
met_ac_tmp2 = zeros(64,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i1 = 1 : 64
if rout(1,i1,34) ~= 0
ns_1 = trellis217(i1,[3 4]) + [1 1];
ns = [rout([2 3],i1,34)]';
met_index = trellis217(i1,[1 2])+[1 1];
met_ac_tmp2(ns_1(1)) = met_in(met_index(1)) + met_ac(i1);
met_ac_tmp2(ns_1(2)) = met_in(met_index(2)) + met_ac(i1);
for i2 = 1 : 2
if ns(i2) == 0
break;
else
if rout(1,ns(i2),35) == 0
met_ac_tmp1(ns(i2)) = met_ac_tmp2(ns(i2));
rout(1,ns(i2),35) = i1;
rout([2 3],ns(i2),35) = [trellis217(ns(i2),[3 4])+[1 1]]';
elseif met_ac_tmp2(ns(i2)) < met_ac_tmp1(ns(i2))
met_ac_tmp1(ns(i2)) = met_ac_tmp2(ns(i2));
ns_now = ns(i2);
index_del = rout(1,ns_now,35);
rout(1,ns(i2),35) = i1;
rout([2 3],ns(i2),35) = [trellis217(ns(i2),[3 4])+[1 1]]';
ns_set = trellis217(index_del,[3 4]) + [1 1];
j1 = 34;
while 1,
switch ns_now,
case ns_set(1),
rout(2,index_del,j1) = 0;
case ns_set(2),
rout(3,index_del,j1) = 0;
otherwise
error('error index');
end
if rout(2:3,index_del,j1)==[0;0]
ns_now = index_del;
index_del = rout(1,ns_now,j1);
rout(1,ns_now,j1) = 0;
ns_set = trellis217(index_del,[3 4]) + [1 1];
j1 = j1-1;
if j1 == 1
break;
end
else
break;
end
end
else
ns_now = ns(i2);
index_del = i1;
ns_set = trellis217(index_del,[3 4]) + [1 1];
j1 = 34;
while 1,
switch ns_now,
case ns_set(1),
rout(2,index_del,j1) = 0;
case ns_set(2),
rout(3,index_del,j1) = 0;
otherwise
error('error index');
end
if rout(2:3,index_del,j1)==[0;0]
ns_now = index_del;
index_del = rout(1,ns_now,j1);
rout(1,ns_now,j1) = 0;
ns_set = trellis217(index_del,[3 4]) + [1 1];
j1 = j1-1;
if j1 == 1
break;
end
else
break;
end
end
end
end
end
end
end
met_ac = met_ac_tmp1;
met_ac_35 = met_ac;
num = 0;
for i1 = 1 : 64
if rout(1,i1,2) ~= 0
num = num + 1;
codeword_tmp = mod(i1+1,2);
node_head = rout(1,i1,2);
end
end
if num == 1
codeword = codeword_tmp;
met_ac_35 = met_ac_35 - min(met_ac_35);
% met_ac_35 = met_ac_35 - met_in_D(trellis217(node_head,codeword+1)+1); %%%% ????????????????
% met_ac_35 = met_ac_35 - met_in_D(bin_vector_to_dec(trellis217(node_head,codeword+1))+1); %%%% ????????????????
else
% codeword = 0;
codeword = 0;
met_ac_35 = met_ac_35 - min(met_ac_35);
% codeword = 2;
rout(3,node_head,1) = 0;
for ia = 2 : 35
for ib = 1 : 64
if rout(1,ib,ia) ~= 0
ps = rout(1,ib,ia);
ps_set = rout([2 3],ps,ia-1);
if ps_set(1) ~= ib & ps_set(2) ~= ib
rout(:,ib,ia) = zeros(3,1);
end
end
end
end
end
x_reg(100) = codeword;
% for i1 = 1 : 6528
% x_reg(100+i1) = rout(192+i1);
% end
x_reg(101:6628) = rout(193:6720);
x_reg(1:64) = met_ac_35;
% for i1 = 1 : 132
% x_reg(6700+i1) = met_in_D(4+i1);
% end
x_reg(6721:6852) = met_in_D(5:136);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sys = x_reg;
%end mdlUpdate
%
%=======================================================================
% mdlOutputs
% Return the output vector for the S-function
%=======================================================================
%
function sys = mdlOutputs(t, x, u)
sys = x(100);
%end mdlOutputs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -