vitshort.m

来自「经典通信系统仿真书籍《通信系统与 MATLAB (Proakis)》源代码」· M 代码 · 共 45 行

M
45
字号
function out = vitshort(fst_in, snd_in, n_sta, mima);
%VITSHORT makes two steps of transfering expense into one step expense.
%   OUT = VITSHORT(FST_IN SCD_IN, N_STA, MIMA)
%   FST_IN, step one
%   SND_IN, step two
%   N_STA,  number of state
%   MIMA,   ==1 to find the minimum, == 0 to find the maximum
%   OUT, FST_IN, and SND_IN are size 2^n_sta row vectors which recorded the data of
%   [d00, d10, d20, ..., dn0, d01, d11, d21,..., dn1, ...., d0n, d1n, d2n, ...., dnn]
%   where dij means the cost of transfering state i to state j.
%   dij = NaN means that there is no transfering between the two states.
%
%   Used by viterbi.

%       Wes Wang 12/10/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 18:04:53 $

pow_sta = length(fst_in);
for i = 1 : n_sta
    aft_indx = i * n_sta - n_sta;
    for j = 1 : n_sta
        wei_mat = [fst_in(j : n_sta : pow_sta);...
                  snd_in(aft_indx+1 : aft_indx + n_sta)];
        wei_sum = sum(wei_mat);
        wei_indx = find(~isnan(wei_sum));
        if mima
            sub_indx = find(wei_sum == max(sum(wei_mat(:, wei_indx))));
            if length(sub_indx) > 1
                sub_indx = find(wei_mat(1,:) == max(wei_mat(1, sub_indx)));
            end;
        else
            sub_indx = find(wei_sum == min(sum(wei_mat(:, wei_indx))));
            if length(sub_indx) > 1
                sub_indx = find(wei_mat(1,:) == min(wei_mat(1, sub_indx)));
            end;
        end;
        if ~isempty(sub_indx)
            out(aft_indx + j) = wei_sum(sub_indx(1));
        else
            out(aft_indx + j) = NaN;
        end;
    end;
end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?