⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vitdec.m

📁 最大后验概率的vertbi算法的译码算法
💻 M
📖 第 1 页 / 共 2 页
字号:
                  'INIT_METRIC, INIT_STATES and ' ,...
                  'INIT_INPUTS, all three of them are required to be\n' ,...
                  'the empty matrix [].']))
            
         else
            error(sprintf(['Invalid syntax.  To specify initial metrics, states and inputs, ' ,...
                  'all three of\n' ,...
                  'them must be provided at the same time.']))
         end
         
      else
          error('Seven input arguments have been provided.  Invalid syntax.')
      end
      
   case 3
      % --- initmetric is first (element 1), initstate (element 2), initinput (element 3)

      if (opmodeNum == CONT)
         if dectypeNum~=SOFT
            initmetric    = varargin{numArg(1)};
            initstate     = varargin{numArg(2)};
            initinput     = varargin{numArg(3)};
            
            if ~(isempty(initmetric) & isempty(initstate) & isempty(initinput))
               initTableSet  = 1;      % Indicates that traceback memory is given
            end
            
         elseif isscalar(varargin{numArg(1)})
            error(sprintf(['Invalid syntax.  To specify initial metrics, states and inputs,' ,...
                  'all three of them\n' ,...
                  'must be provided at the same time.']))
         else
            error(sprintf(['To use the ''soft'' decision type, the number of soft ' ,...
                  'decision bits must be\n' ,...
                  'specified.']))
         end
         
      else
         error(sprintf(['Eight input arguments have been provided.  ' ,...
                'This is only allowed for the ''cont''\n' ,...
                'mode used with the ''unquant'' or ''hard'' decision type.']))
      end;
      
   case 4
      % --- nsdec, initmetric, initstate, initinput provided : 
      %       (only allowed in 'cont' mode w/ 'soft' dectype)

      if (opmodeNum == CONT & dectypeNum == SOFT)
         nsdec         = varargin{numArg(1)};
         initmetric    = varargin{numArg(2)};
         initstate     = varargin{numArg(3)};
         initinput     = varargin{numArg(4)};
          
         if ~(isempty(initmetric) & isempty(initstate) & isempty(initinput))
            initTableSet  = 1;      % Indicates that traceback memory is given
         end
         
      else
         error(sprintf(['Nine input arguments have been provided.  ' ,...
                'This is only allowed for the ''cont''\n' ,...
                'mode used with the ''soft'' decision type.']))
      end;

   otherwise
      error('Invalid syntax.  Too many input arguments.')
end;


% Check code
if ~isempty(code)

    code_dim = size(code);
    if ~isnumeric(code) | code_dim >2 | ~( isvector(code) && ~isscalar(code) ) ...
            | max(max(~isfinite(code))) | (~isreal(code))
        error('CODE must be a vector of real numbers.')
    end
    
    if max(max(code < 0)) | (max(max(floor(code) ~= code)))
        if dectypeNum == HARD & max(max(code)) > 1
            error('For hard decision type, CODE must contain only binary numbers.');
        elseif dectypeNum == SOFT & max(max(code)) > 2^nsdec-1
            error(['For soft decision type, CODE must contain only integers ', ...
                    'between 0 and 2^NSDEC-1.']);
        end
    end
    
    if mod(length(code), n) ~=0
        error(sprintf(['Length of the input code vector must be a multiple of the ', ...
                'number of bits in an\n' ,...
                'output symbol.']))
    end
    
    % Get code orientation
    if code_dim(1)>1
        code_flip = 1;
        code=code';
    else
        code_flip = 0;
    end
    
end

% Check tblen
if ~isscalar(tblen) | ~isnumeric(tblen) | ~isreal(tblen) ...
 | ~isfinite(tblen) | tblen<=0 | floor(tblen)~=tblen  
    error('Traceback depth must be a positive integer scalar.');

elseif ~isempty(code) & (opmodeNum ~= CONT & tblen>length(code)/n )
    error(sprintf(['For the ''cont'' mode, traceback depth must be ', ...
           'a positive integer scalar not\n', ...
           'larger than the number of input symbols in CODE.']))
end

% Check nsdec if dectype=='soft'
if (dectypeNum == SOFT)
    if ~isscalar(nsdec) | ~isnumeric(nsdec) | ~isreal(nsdec) ...
      | nsdec<0 | floor(nsdec)~=nsdec 
        error(['Number of soft decision bits must be a positive ', ...
        'scalar integer.']);
    end
end

% Check initmetric, initstate, initinput
if (initTableSet == 1)
    if ~isnumeric(initmetric) | ~( isvector(initmetric) && ...
        ~isempty(initmetric) && ~isscalar(initmetric) ) ...
            | length(initmetric)~=trellis.numStates | max(max(~isfinite(initmetric))) ...
            | (~isreal(initmetric))
         
       if isempty(initmetric)
          error(sprintf(['When using [] as the default for INIT_METRIC, ' ,...
                'INIT_STATES and INIT_INPUTS must\n' ,...
                'also be [].']))
       else
          error(sprintf(['The inital state metrics must be a real vector with length ' ,...
                'equal to the number\n' ,...
                'of states in the specified trellis.']))
       end
       
    end
    
    dimState = size(initstate);
    if ~isnumeric(initstate) | ~isequal([dimState], [trellis.numStates tblen])  ...
            | max(max(~isfinite(initstate))) | (~isreal(initstate))...
            | max(max(floor(initstate)~=initstate)) | min(initstate(:))<0 ...
            | max(initstate(:)>trellis.numStates-1)
         
       if isempty(initstate)
          error(sprintf(['When using [] as the default for INIT_STATES, ' ,...
                'INIT_METRIC and INIT_INPUTS must\n' ,...
                'also be [].']))
       else
          error(sprintf(['The initial traceback states must be integers ' ,...
                'between 0 and\n' ,...
                '(number of states - 1), arranged in a matrix.  ' ,...
                'Its number of rows must equal the\n' ,...
                'number of states in the specified trellis, ' ,...
                'and its number of columns must equal\n' ,...
                'the traceback depth.']))
       end
            
    end
    
    dimInput = size(initinput);
    if ~isnumeric(initinput) | ~isequal([dimInput], [trellis.numStates tblen]) ...
            | max(max(~isfinite(initinput))) | (~isreal(initinput))...
            | max(max(floor(initstate)~=initstate)) | min(initstate(:))<0 ...
            | max(initstate(:)>trellis.numStates-1)
         
       if isempty(initinput)
          error(sprintf(['When using [] as the default for INIT_INPUTS, ' ,...
                'INIT_METRIC and INIT_STATES must\n' ,...
                'also be [].']))
       else
          error(sprintf(['The initial traceback inputs must be integers ' ,...
                'between 0 and\n' ,...
                '(number of states - 1), arranged in a matrix.  ' ,...
                'Its number of rows must equal the\n' ,...
                'number of states in the specified trellis, ' ,...
                'and its number of columns must equal\n' ,...
                'the traceback depth.']))
       end
         
    end
end

% Return if input code is empty
if isempty(code)   
    varargout{1} = [];
    varargout{2} = initmetric;
    varargout{3} = initstate;
    varargout{4} = initinput;
    return;
end

% Call to vit.c
[varargout{1} varargout{2} varargout{3} varargout{4}] ...
    = vit(code,k,n,trellis.numStates,outputs,trellis.nextStates,tblen,opmodeNum, ...
      dectypeNum,nsdec,initTableSet,initmetric,initstate,initinput);

% Change message back to same orientation as the input code if needed
if code_flip
    varargout{1}=(varargout{1})';
end

% [EOF]

⌨️ 快捷键说明

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