behaviorrecordings=importdata('behavior_recordings');
addpath(genpath('/home/david/Dropbox/Tools'))

for i=9
   cd(behaviorrecordings{i}(1:end-10))
   SetCurrentSession   
   lfp = GetLFP([23 2 53 63 42 61]);
   close all; clear m
%    load('ripples_ls.mat')

   [b a] = butter(3,[110/625 190/625],'bandpass');
   [ripples_ls,stdev_ls,noise_ls] = FindRipples([lfp(:,1) filtfilt(b,a,lfp(:,2))],...
       'durations',[5 100],...
       'thresholds',[1 2],...
       'noise',[lfp(:,1) filtfilt(b,a,lfp(:,7))]);
   for r = 1:size(ripples_ls,1)
      for j=1:size(lfp,2)-1
%          [a b]= min(abs(ripples_ls(r,2)-lfp(:,1)));
         b = round(ripples_ls(r,2)*1250);
         plot(lfp(b-200:b+200,j+1)+j*1000,'k')
         hold on
      end
      plot(lfp(b-200:b+200,end)+j*1000,'r')
      title(length(ripples_ls)-r)
      hold off
      s = input('','s');
      if strcmp(s,'n')
          m(r)=1;
      else
          m(r)=0;
      end
   end
   disp(['removing ' num2str(sum(m)) ' bad ripples..'])
   ripples_ls(m==1,:)=[];
   save('ripples_ls.mat','*ls')
     if exist('ripples_ls.rLS.evt')
       delete('ripples_ls.rLS.evt')
     end
   SaveRippleEvents('ripples_ls.rLS.evt',ripples_ls,29);
   
%    close all; clear m 
%    lfp = GetLFP([84 94 76 116 97 107 115]);   
%    load('ripples_hpc.mat')
%      for r = 1:length(ripples_hpc)
%       for j=1:size(lfp,2)-1
% %          [a b]= min(abs(ripples_ls(r,2)-lfp(:,1)));
%          b = round(ripples_hpc(r,2)*1250);
%          plot(lfp(b-200:b+200,j+1)+j*1000,'k')
%          hold on
%       end
%       plot(lfp(b-200:b+200,end)+j*1000,'r')
%       title(length(ripples_hpc)-r)
%       hold off
%       s = input('','s');
%       if strcmp(s,'n')
%           m(r)=1;
%       else
%           m(r)=0;
%       end
%    end
%    disp(['removing ' num2str(sum(m)) ' bad ripples..'])
%    ripples_hpc(m==1,:)=[];
%    save('ripples_hpc.mat','*hpc')
%    
   cd ..
end