
files = [{'DT1_rLS_20150721_1008um'},...
         {'DT1_rLS_20150722_1152um'},...
         {'DT1_rLS_20150722_1440um'},...
         {'DT1_rLS_20150723_1584um'},...
         {'DT1_rLS_20150723_1728um'},...
         {'DT1_rLS_20150724_1800um'},...
         {'DT1_rLS_20150724_1872um'},...
         {'DT1_rLS_20150725_1944um'},...         
         {'DT1_rLS_20150726_2016um'},... 
         {'DT1_rLS_20150727_2088um'},...
         {'DT1_rLS_20150727_2232um'},...
         {'DT1_rLS_20150728_2304um'},...
         {'DT1_rLS_20150729_2448um'},...
         {'DT1_rLS_20150729_2592um'},...
         {'DT1_rLS_20150730_2736um'}];
all_histo=[];
p=[];
z=[];
depth=[];
all_rate =[];
% phase_locking_histo=zeros(794,100,180);
n=1;
nn=1;
all_pairs=[];
vals=[];
amplitude_rate_correlations=[];
amplitude_rate_correlations_flip=[];
c=1;

for f = 1:length(files);
    cd(files{f})
    xml = dir('*xml');
%     SetCurrentSession(xml.name)
%     nunits = GetUnits();
%     lfp = GetLFP([2 5 12 15 18 23 28 29]);
%      lfp = GetLFP([2]);% 5 12 15 18 23 28 29]);
% if exist(['acg.mat'])
%     for n = 1:size(nunits,1);
% %         spikes{n} = GetSpikeTimes(nunits(n,:));
%         spikes_all{c} = GetSpikeTimes(nunits(n,:));
%         c=1+c
% %         all_rate = [all_rate,length(spikes{n})./length(lfp)*1000];
%     end
% end
%     if exist([files{f} '-states.mat'])
%         load([files{f} '-states.mat'])
%     end
    
%     
%    %% phaselocking
if exist(['phaselocking.mat'])
    load('phaselocking.mat','phl*','histo')
    p = [p; phl_p];
    z = [z; phl_z];
    for i=1:size(histo,1)
        for j=1:100
            phase_locking_histo{n,j} = (histo{i,j});
            circ_resultants(n,j) = circ_r(histo{i,j});
            circ_means(n,j) = circ_mean(histo{i,j});
        end
        n=1+n;
    end
end




% if exist('psd.mat')
%     dat(f) = importdata('psd.mat');
%     
%     
% end


%% amp/power correlations

% if exist('amp_rate_corrs.mat')
%    load('amp_rate_corrs.mat')
%    
%    amplitude_rate_correlations = [amplitude_rate_correlations; amp_corr];
%    amplitude_rate_correlations_flip = [amplitude_rate_correlations_flip; amp_corr_flip];
%     
% end

%% ripple modulation
% 
% 
% if exist(['ripple_modulation.mat'])
%     load('ripple_modulation','histo_phase')
%     all_histo = [all_histo; histo_phase];
%     for t = 1:size(histo_phase,1)
%         depth = [depth; str2num(files{f}(end-5:end-2))];
%     end
% end

   %% phase/amp
% if exist(['lfp_phase_amplitude.mat'])
%     load('lfp_phase_amplitude.mat')
%     for i=1:100
%     p(i,:) = zscore(phase_amplitude(i,:));
%     end
%     subplot(4,4,n) 
%     imagesc(p)
%     axis([750 1750 0 100])
%     n=1+n;
% end

       %% CCG
% if exist(['acg.mat'])
% load('acg.mat','acg');
% for i=1:size(acg)
%     for j=i       
% %         acg{i,j}(501)=nan;
%         aa(nn,:) = acg{i,j};
%         spikes_all{nn} = GetSpikeTimes(nunits(i,:));
% %         plot(acg{i,j})
% %         pause
%  nn=1+nn
%     end
% end
% end

%     [b a] = butter(3,[4/500 9/500],'bandpass');
%     [bb aa] = butter(3,[100/500 200/500],'bandpass');
%     for i =1:size(all_ccgs(n).ccg,1)
%         for j =1:size(all_ccgs(n).ccg,1)
%            if ~isempty(all_ccgs(n).ccg)
% 
% %                slow = filtfilt(b,a,double(all_ccgs(n).ccg{i,j}));
% %                fast = filtfilt(bb,aa,double(all_ccgs(n).ccg{i,j}));
% slow = smooth(double(all_ccgs(n).ccg{i,j}),150);
% fast = smooth(double(all_ccgs(n).ccg{i,j}),15);
%                [pks_s locs_s] = max(slow);
%                [pks_f locs_f] = max(fast);
%                all_pairs = [all_pairs;locs_s,locs_f];
%                vals = [vals;pks_s,pks_f];
%            end
%         end
%     end
%     n=1+n;
   

    
    cd ..
end