%% Spike field coherence between the cells and the LFP channels for just the memory period

display('To compute spike-field coherences, press enter');
pause
%
% Preliminary parameter settings
%
params.Fs=1000; % sampling frequency
params.fpass=[0 100]; % frequency range of interest
params.tapers=[10 19]; % tapers
params.trialave=1; % average over trials
params.err=[1 0.05]; % population error bars
%
% Extract data from the memory period and compute coherences between cell 1
% and the LFP channels
%
delay_times=[1 2];
datasp=extractdatapt(dsp1t,delay_times,1);
datalfp=extractdatac(dlfp1t,params.Fs,delay_times);
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp,datasp,params);
figure;
subplot(231); 
plotsig(C,confC,1,f,'y'); ylim([0 1]);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel(''); ylabel('Coherence');
title(['LFP 1-Cell 1 , W=' num2str(params.tapers(1)) 'Hz']);
datalfp=extractdatac(dlfp2t,params.Fs,[1 2]);
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp,datasp,params);
subplot(232); 
plotsig(C,confC,1,f,'y');ylim([0 1]);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel(''); ylabel('Coherence');
ylabel('Coherence');
title(['LFP 2-Cell 1 , W=' num2str(params.tapers(1)) 'Hz']);
datalfp=extractdatac(dlfp3t,params.Fs,[1 2]);
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp,datasp,params);
subplot(233); 
plotsig(C,confC,1,f,'y'); ylim([0 1]);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel(''); ylabel('Coherence');
title(['LFP 3-Cell 1 , W=' num2str(params.tapers(1)) 'Hz']);
position_figure
%
% Extract data from the memory period and compute coherences between cell 2
% and the LFP channels
%
datasp=extractdatapt(dsp2t,delay_times,1);
datalfp=extractdatac(dlfp1t,params.Fs,delay_times);
params.err=[1 0.05];
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp,datasp,params);
subplot(234); 
plotsig(C,confC,1,f,'y'); 
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('frequency Hz'); ylabel('Coherence');
title(['LFP 1-Cell 2 , W=' num2str(params.tapers(1)) 'Hz']);
datalfp=extractdatac(dlfp2t,params.Fs,[1 2]);
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp,datasp,params);
subplot(235); 
plotsig(C,confC,1,f,'y'); ylim([0 1]);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('frequency Hz'); ylabel('Coherence');
title(['LFP 2-Cell 2 , W=' num2str(params.tapers(1)) 'Hz']);
datalfp=extractdatac(dlfp3t,params.Fs,[1 2]);
[C,phi,S12,S1,S2,f,zerosp,confC,phistd]=coherencycpt(datalfp,datasp,params);
subplot(236); 
plotsig(C,confC,1,f,'y'); ylim([0 1]);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('frequency Hz'); ylabel('Coherence');
title(['LFP 3-Cell 2 , W=' num2str(params.tapers(1)) 'Hz']);
position_figure