% x9 - data setup for 2 parabolic tracks

if( MISSED)
  disp( 'Using missed target events.');
else
  disp( 'Not using missed target events.');
end

if( UNUSED_PENALTY)
  disp( 'Using penalty for unused measurements.');
else
  disp( 'Not using penalty for unused measurements.');
end


if( K == 1)

  LOADED = 9;

  N = 21;			% N data samples

% generate false detections somehow
%
% for initial testing, generate 0..3 false detections per time unit
% using a uniform distribution of the number of false detections:
%
  n_false_detect = floor(4*rand(1,N));	

  MM = 2 + n_false_detect;	% measurement counter array

  MM_max = max(MM);

  M = MM_max + MISSED;		% M states

  XY_offset = [0, cumsum(MM(1:N-1))];	% XY measurement offset indices

% generate XY measurements
%
  dt = 4/(N-1);			% time will go from 0 to 4
   t = [0:N-1]*dt;

  xy1_orig = [ t; 2*(t.*(1-t/4))];

  xy2_orig = [ t; 4-2*(t.*(1-t/4))];

  if(TEST)
    Kn = 0.0;
  else
    Kn = 0.01;	% measurement noise variance
  end

  xy1 = xy1_orig + sqrt(Kn) * randn( size(xy1_orig));
  xy2 = xy2_orig + sqrt(Kn) * randn( size(xy2_orig));

  if( MISSED)
    if( TEST)
      xy1(:,[ 9 10 11 12 13]) = HUGE_VAL*ones(2,5);
    else
      xy1(:,[ 9 10 11 12 13]) = 4 * rand(2,5);
    end
  end

  if( MISSED | UNUSED_PENALTY)
    missed_cost = log(16);	% volume is x,y = 0..4,0..4
  end

  XY = zeros(2,sum(MM));

  for i = 1:N
    ii = 1 + XY_offset(i);
    XY(:,ii) = xy1(:,i);		% targets
    ii = ii + 1;
    XY(:,ii) = xy2(:,i);
    for j = 1:n_false_detect(i)		% false detections
      if( TEST)
        XY(:,ii+j) = HUGE_VAL * ones(2,1);	% for testing
      else
        XY(:,ii+j) = 4 * rand(2,1);	% uniform distribution over 0..4
      end
    end
  end

  zstate = 0;	% initial state unknown

  z = [1:N];	% time index for dummy z data

else % K > 1

  if( LOADED ~= 9)
    error( 'initialize with K = 1 first');
  end

  if( K > MM_max)
    error( 'K > MM_max not allowed!');
  end

  if( any( K > MM) & (MISSED == 0))
    error( 'K > MM requires missed target events.')
  end
    
  setup_combos;	% setup global variables: perms, combos, unique_perms, MP, M

end
