% x1 - data setup for 1 parabolic track
% with random missed target events and
% Poisson distributed numbers of false detections.

if( K == 1)

  LOADED = 1;

  N = 21;			% N data samples

% generate false detections
%
  false_alarm_rate = 2;		% average number of false alarms per unit time

  n_false_detect = zeros(1,N);

  n_false_detect(1) = 2;	% to allow initialization up to K=3

  for i=2:N
    n_false_detect(i) = n_poisson( false_alarm_rate);
  end

% generate missed target events
%
  Pmiss = 0.4;				% probability of a missed target event

%  n1 = rand(1,N) > Pmiss;		% n1 == 1 when target 1 is not missed
%
%  n1(1) = 1;				% to allow initialization up to K=3
%
%  n1(2) = 1;				% really need measurements at first two time instants
%  					%  to initialize Kalman effectively

% used in the Radar2000 paper summary:
%
  n1 = [ 1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1 1 0 1 0 1];

%  n1 = [ 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 0 1];

  MM = n1 + n_false_detect;		% measurement counter array

  MM_max = max(MM);

  M = MM_max + 1;			% M states

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

% apriori costs for missed target events
%
% Cmiss(n+1,K) is -log( P(n target events)) apriori cost
%
  Cmiss = get_Cmiss( Pmiss, MM_max);

% apriori costs for false detections
%
% Cfalse(m+1) is -log(P(m false detections))

  Cfalse = get_Cfalse( false_alarm_rate, MM_max);

% 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))];

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

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

  missed_cost = log(16);	% volume is x,y = 0..4,0..4

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

  for i = 1:N
    ii = XY_offset(i);
    if( n1(i) ~= 0)
      ii = ii + 1;
      XY(:,ii) = xy1(:,i);		% target #1
    end
    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 ~= 1)
    error( 'initialize with K = 1 first');
  end

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

  setup_combos;	% setup global variables: perms, combos, unique_perms, MP, M

end
