Home > chronux_code > exploratory > correlations > pointtimes > cohgrampt.m

cohgrampt

PURPOSE ^

Multi-taper time-frequency coherence - two point processes given as times

SYNOPSIS ^

function [C,phi,S12,S1,S2,t,f,zerosp,confC,phierr,Cerr]=cohgrampt(data1,data2,movingwin,tapers,pad,Fs,fpass,err,trialave,fscorr)

DESCRIPTION ^

 Multi-taper time-frequency coherence - two point processes given as times
 process 

 Usage:

 [C,phi,S12,S1,S2,t,f,confC,phierr,Cerr]=cohgramcpt(data1,data2,movingwin,tapers,nfft,Fs,fpass,err,trialave,fscorr)
 Input: 
 Note units have to be consistent. Thus, if movingwin is in seconds, Fs
 has to be in Hz. see chronux.m for more information.

       data1  (structure array of spike times with dimension trials; also accepts 1d array of spike times) -- required
       data2  (structure array of spike times with dimension trials; also accepts 1d array of spike times) -- required
       movingwin (in the form [window winstep] -- required
       tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 
                                                 specified, use [NW K]=[3 5]
        pad            (padding factor for the FFT) - optional. Defaults to 0.  
                       e.g. For N = 500, if PAD = 0, we pad the FFT 
                       to 512 points; if PAD = 2, we pad the FFT
                       to 2048 points, etc.
       Fs   (sampling frequency) - optional. Default 1.
       fpass    (frequency band to be used in the calculation in the form
                                   [fmin fmax])- optional. 
                                   Default all frequencies between 0 and Fs/2
       err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
                                   [0 p] or 0 - no error bars) - optional. Default 0.
       trialave (average over trials when 1, don't average when 0) - optional. Default 0
       fscorr   (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
                (available only for spikes). Defaults 0.
 Output:
       C (abs of coherency time x frequency x trials if no trial averaging)
       phi (phase of coherency time x frequency x trials if no trial averaging)
       S12 (cross spectrum - time x frequencies x trials for no trial averaging)
       S1 (spectrum 1- time x frequencies x trials for no trial averaging)
       S2 (spectrum 2- time x frequencies x trials for no trial averaging)
       t (time)
       f (frequencies)
       zerosp (1 for windows where spikes in either channel were absent,zero otherwise)
       confC (confidence level for c at 1-p %)
       phierr (error bars for phi)
       Cerr  (Jackknife error bars for C - use only for Jackknife)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [C,phi,S12,S1,S2,t,f,zerosp,confC,phierr,Cerr]=cohgrampt(data1,data2,movingwin,tapers,pad,Fs,fpass,err,trialave,fscorr)
0002 % Multi-taper time-frequency coherence - two point processes given as times
0003 % process
0004 %
0005 % Usage:
0006 %
0007 % [C,phi,S12,S1,S2,t,f,confC,phierr,Cerr]=cohgramcpt(data1,data2,movingwin,tapers,nfft,Fs,fpass,err,trialave,fscorr)
0008 % Input:
0009 % Note units have to be consistent. Thus, if movingwin is in seconds, Fs
0010 % has to be in Hz. see chronux.m for more information.
0011 %
0012 %       data1  (structure array of spike times with dimension trials; also accepts 1d array of spike times) -- required
0013 %       data2  (structure array of spike times with dimension trials; also accepts 1d array of spike times) -- required
0014 %       movingwin (in the form [window winstep] -- required
0015 %       tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
0016 %                                                 specified, use [NW K]=[3 5]
0017 %        pad            (padding factor for the FFT) - optional. Defaults to 0.
0018 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0019 %                       to 512 points; if PAD = 2, we pad the FFT
0020 %                       to 2048 points, etc.
0021 %       Fs   (sampling frequency) - optional. Default 1.
0022 %       fpass    (frequency band to be used in the calculation in the form
0023 %                                   [fmin fmax])- optional.
0024 %                                   Default all frequencies between 0 and Fs/2
0025 %       err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
0026 %                                   [0 p] or 0 - no error bars) - optional. Default 0.
0027 %       trialave (average over trials when 1, don't average when 0) - optional. Default 0
0028 %       fscorr   (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
0029 %                (available only for spikes). Defaults 0.
0030 % Output:
0031 %       C (abs of coherency time x frequency x trials if no trial averaging)
0032 %       phi (phase of coherency time x frequency x trials if no trial averaging)
0033 %       S12 (cross spectrum - time x frequencies x trials for no trial averaging)
0034 %       S1 (spectrum 1- time x frequencies x trials for no trial averaging)
0035 %       S2 (spectrum 2- time x frequencies x trials for no trial averaging)
0036 %       t (time)
0037 %       f (frequencies)
0038 %       zerosp (1 for windows where spikes in either channel were absent,zero otherwise)
0039 %       confC (confidence level for c at 1-p %)
0040 %       phierr (error bars for phi)
0041 %       Cerr  (Jackknife error bars for C - use only for Jackknife)
0042 
0043 if nargin < 3; error('Need data1 and data2 and window parameters'); end;
0044 if nargin < 4; tapers=[3 5]; end;
0045 if nargin < 5;pad=0;end;
0046 if nargin < 6; Fs=1; end;
0047 if nargin < 7; fpass=[0 Fs/2]; end;
0048 if nargin < 8; err=0; end;
0049 if nargin < 9; trialave=0;end;
0050 if nargin < 10; fscorr=0; end;
0051 if nargout > 10 & err(1)~=2; 
0052     error('Cerr computed only for Jackknife. Correct inputs and run again');
0053 end;
0054 
0055 if isempty(tapers); tapers=[3 5]; end;
0056 if isempty(pad);pad=0;end;
0057 if isempty(Fs); Fs=1; end;
0058 if isempty(fpass); fpass=[0 Fs/2]; end;
0059 if isempty(err); err=0; end;
0060 if isempty(trialave); trialave=0;end;
0061 if isempty(fscorr);fscorr=0;end
0062 [N1,C1,N2,C2]=check_consistency(data1,data2);
0063 [mintime,maxtime]=minmaxsptimes(data1);
0064 tn=mintime+movingwin(1)/2:movingwin(2):maxtime-movingwin(1)/2;
0065 Nwin=round(Fs*movingwin(1)); % number of samples in window
0066 Nstep=round(movingwin(2)*Fs); % number of samples to step through
0067 nfft=2^(nextpow2(Nwin)+pad);
0068 [f,findx]=getfgrid(Fs,nfft,fpass); 
0069 tapers=dpsschk(tapers,Nwin,Fs); % check tapers
0070 nw=length(tn);
0071 for n=1:nw;
0072    t=linspace(tn(n)-movingwin(1)/2,tn(n)+movingwin(1)/2,Nwin);
0073    datawin1=extractspdata(data1,[t(1) t(end)]);datawin2=extractspdata(data1,[t(1) t(end)]);
0074    if nargout==11;
0075      [c,ph,s12,s1,s2,f,zsp,confc,phie,cerr]=coherencypt(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave,fscorr);
0076      confC=confc;
0077      phierr(1,n,:,:)=squeeze(phie(1,:,:));
0078      phierr(2,n,:,:)=squeeze(phie(2,:,:));
0079      Cerr(1,n,:,:)=squeeze(cerr(1,:,:));
0080      Cerr(2,n,:,:)=squeeze(cerr(2,:,:));
0081    elseif nargout==10;
0082      [c,ph,s12,s1,s2,f,zsp,confc,phie]=coherencypt(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave,fscorr);
0083      confC=confc;
0084      phierr(1,n,:,:)=squeeze(phie(1,:,:));
0085      phierr(2,n,:,:)=squeeze(phie(2,:,:));
0086    else
0087      [c,ph,s12,s1,s2,f,zsp]=coherencycpt(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave,fscorr);
0088    end;
0089    C(n,:,:)=c;
0090    phi(n,:,:)=ph;
0091    S12(n,:,:)=s12;
0092    S1(n,:,:)=s1;
0093    S2(n,:,:)=s2;
0094    zerosp(n,:)=zsp;
0095 end;
0096 t=tn;
0097 C=squeeze(C); phi=squeeze(phi);S12=squeeze(S12); S1=squeeze(S1); S2=squeeze(S2);zerosp=squeeze(zerosp);
0098 if nargout==11;Cerr=squeeze(Cerr);end;
0099 if nargout==10; phierr=squeeze(phierr);end

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003