dset='/Desktop/Dropbox/Mouse12-120807';

% datSegments = load('DatSegments.txt');
% datSegments = 10000*datSegments/1250;
% datSegments = intervalSet([0;cumsum(datSegments(1:end-1))]',[cumsum(datSegments)-1]);    
% 
% exploEp = subset(datSegments,4); %Only valid for this dataset!

[X,Y,V,GoodRanges,ep] = LoadPosition_Wrapper(dset);
speedEp = thresholdIntervals(tsd(Range(X),V),0.015);
exploEp = speedEp;

remEp = LoadEpoch(dset,'REM');
swsEp = LoadEpoch(dset,'SWS');


eegTh=LoadBinary([dset,'.eeg'],'nchannels',90,'channels',1);
t = 0:length(eegTh)-1;
eegTh=tsd(t*10^4/1250,eegTh);
eegThREM=Restrict(eegTh,remEp);
eegThEx=Restrict(eegTh,exploEp);
clear eegTh 

eegHpc=LoadBinary([dset,'.eeg'],'nchannels',90,'channels',65);
t = 0:length(eegHpc)-1;
eegHpc=tsd(t*10^4/1250,eegHpc);
eegHpcREM=Restrict(eegHpc,remEp);
eegHpcEx=Restrict(eegHpc,exploEp);
clear eegHpc

% REM
[xcf1,lags1,bounds1] = crosscorr(Data(eegThREM),Data(eegHpcREM),600);

% Explo
[xcf2,lags2,bounds2] = crosscorr(Data(eegThEx),Data(eegHpcEx),600);


Figure, plot(lags1,xcf1), title('REM period');
Figure, plot(lags2,xcf2), title('Explo period');