function vit1_init( M, N, Nv)
%
% initialization for Viterbi algorithm
%
% R. Perry, June 2001
%
% Usage:
%
%   vit1_init( M, N, Nv)
%
%     M  - number of states
%     N  - number of input data points
%     Nv - number of Viterbi instances
%
% If Nv is not specified, it defaults to 1.
%
% Example usage, with Nv = 1:
%
%   vit1_init( M, N);
%
%   for t=1:N
%     vit1_update;
%   end
%
%   path = vit1_paths;
%
% After calling vit1_init, instances of the Viterbi algorithm can be
% invoked, for example, like this:
%
%   vit1_init( M, N, Nv);
%
%   for t=1:N              % for each input data point
%     for vnum=1:Nv        % for each Viterbi instance
%       vit1_update(vnum); % advance to next data point
%     end
%   end
%
%   paths = zeros(N,Nv);
%
%   for vnum=1:Nv
%     paths(:,vnum) = vit1_paths(vnum);
%   end
%
% and each instance can access the variables associated with the
% other instances.  This may be useful for running separate trellises
% for each user in parallel in the multiuser ISI problem, though
% we may have to include some more global variables to help with that.
%
% See also:
%
%   vit1_update, vit1_paths

% global variables
%
global HUGE_VAL; % 1e99
global DEBUG;    % for debugging
global V;        % main state array
global Vl;       % array for L-best indices
global Vw;       % cost array
global Vparam;   % parameters

% Nv set to 1 if not specified
%
if( nargin < 3)
  Nv = 1;
end

V  = zeros( M, N, Nv);
Vl = V;

% initialize cost like zstate=1 in old Viterbi
%
Vw = HUGE_VAL*ones( M, Nv);
Vw(1,:) = 0;

Vparam = zeros( 1, 4 + Nv);
Vparam(1:4) = [1, M, N, Nv];
