%
%  This  routine computes the autocorrelation of the bipolar and 
%  patch channels for ventricular fibrillation and ventricular tachycardia
%
%  name = name of the data file (for x channel or y channel)
%  start = starting index
%  samples = number of samples to examine
%  xyend is the amplitude the largest points are scaled to (somewhat
%  arbitrary)
%  N is the number of bins in one direction
%
function pp = laptop9(xname,yname,start,samples,xyend,N);
%
% get the x axis data
%
  sx = load(xname);
%
%  for now, format the data
%
  temp = sx';
  sx = temp(:);
%
%  get our data segment
%
  tx = sx(start:start+samples); 
%
%  scale the data
%
  xmin = min(tx);
  xmax = max(tx);
  m = xyend/(xmax-xmin);
  b = -m*xmin;
  x = m*tx+b;
%
% get the y axis data
%
  sy = load(yname);
%
%  for now, format the data
%
  temp = sy';
  sy = temp(:);
%
%  get our data segment
%
  ty = sy(start:start+samples);
%
%  scale the data
%
  ymin = min(ty);
  ymax = max(ty);
  m = xyend/(ymax-ymin);
  b = -m*ymin;
  y = m*ty+b;
 %
 %  Now construct the bins
 %
  xbin = linspace(0,xyend,N+1);
  xbin(end) = xbin(end)*1.1;
  ybin = xbin;
  bins = zeros(N,N);
%
%  now determine where each sample point ( x(k),y(k) )should go
%
   for k = 1:length(x)
     for i = 1:N
        for j = 1:N
           bins(j,i) = bins(j,i)|| ...
                       ??? && ...
                       ??? ;
       end;
     end;
   end;
 
 %  get the area occupied
 %
   area = sum(sum(bins));
   pp = area/(N*N);
 %
 %  Now plot the results
 %
   figure
   orient tall
   time = [start:start+samples]/125;
  
   subplot(2,2,1); plot(time,tx); grid; axis([0 time(end) min(tx) max(tx)]);
   xlabel('Time (sec)'); 
   title(['x-Data from ' xname]);
   
   subplot(2,2,3); plot(time,ty); grid; axis([0 time(end) min(ty) max(ty)]);
   xlabel('Time (sec)');
   title(['y-Data from ' yname]);
 
   subplot(2,2,2); plot(x,y); grid; axis([0 xyend 0 xyend])
   title(['x-y plot']);
  
   subplot(2,2,4); plot(x,y,'o'); grid; axis([0 xyend 0 xyend])
   title(['N = ' num2str(N), ', Occupied Area is ' num2str(pp)]); 
 %  bins
   return;
 