%
%  This  routine computes the autocorrelation of the bipolar and 
%  patch channels for ventricular fibrillation and ventricular tachycardia
%
%  name = name of the data file
%  start = starting index
%  samples = number of samples to examine
%
function [beat_index] = laptop2(name,start,samples,threshold,dead);
%
  s = load(name);
%
%  for now, format the data
%
  temp = s';
  s = temp(:);
%
%  get our data segment
%
  x = s(start:start+samples);
  N = length(x);
%
% the sampling rate for this data is 125 Hz
%
  fs = 125;
  time = [0:N-1]/fs;
%
%  Now look at the maximum signal value
%
  tt = (x >= max(abs(x))*threshold);
  index = find(tt);
%
%  Now start at the back and eliminate a point if it is 
%  is adjacent to the one next to it. Also eliminate any points
%  at the beginning or end
%
  beat_index = [];
  ii = length(index)-1;
  while (ii > 1)
      if ((abs(index(ii)-index(ii-1)) ~= 1)   ... 
            && (N-index(ii) > dead)             ...
             && (index(ii) > dead))
          beat_index = [index(ii) beat_index];
      end;
      ii = ii-1;
  end;
%
%  Plot the results
%
  figure;
  plot(time,x,'-'); grid; xlabel('Time (sec)');
  