%% Comparison of spike-spike coherence in the baseline and delay periods
display('To compute spike-spike coherences for the baseline and delay periods, press enter');
pause
%
% Preliminary parameter setting
%
params.Fs=1000; % sampling frequency
params.fpass=[0 100]; % frequency range of interest
params.tapers=[10 19]; % tapers
params.trialave=1; % average over trials
%
% Extract data from delay period and compute coherency between the two
% spike trains
%
delay_times=[1 2];
datasp1=extractdatapt(dsp1t,delay_times,1);
datasp2=extractdatapt(dsp2t,delay_times,1);
params.err=[2 0.05];
[C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr]=coherencypt(datasp1,datasp2,params);
figure; 
plot_vector(C,f,'n',Cerr,'y'); ylim([0 1]);
xlabel([]);ylabel('Coherence');
title(['Cell 1-Cell 2 coherence - memory period, W=' num2str(params.tapers(1)/size(data,1)*params.Fs) 'Hz']);
%
% Compute coherency between the two
% spike trains in the baseline period
%
datasp1=dsp1b;
datasp2=dsp2b;
params.err=[1 0.05];
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencypt(datasp1,datasp2,params);
hold on; 
plotsig(C,confC,1,f,'m');
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('frequency Hz'); ylabel('Coherence');
title('Cell 1-Cell 2 coherence - baseline period (magenta) and memory period (yellow)');
position_figure
