Home > chronux_0.5 > pointtimes > coherencysegpt.m

coherencysegpt

PURPOSE ^

Multi-taper coherency computed by segmenting two univariate point processes

SYNOPSIS ^

function [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegpt(data1,data2,win,params,segave,fscorr)

DESCRIPTION ^

 Multi-taper coherency computed by segmenting two univariate point processes
 into chunks

 Usage:
 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegpt(data1,data2,win,params,segave,fscorr)
 Input: 
 Note units have to be consistent. See chronux.m for more information.
       data1 (1d structure array of spike times; also accepts 1d array of spike times) -- required
       data2 (1d structure array of spike times; also accepts 1d array of spike times) -- required
       win   (length of segments) - required
       params: structure with fields tapers, pad, Fs, fpass, err
       - optional
           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.
       segave - optional 0 for don't average over segments, 1 for average - default
       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 (magnitude of coherency - frequencies x segments if segave=0; dimension frequencies if segave=1)
       phi (phase of coherency - frequencies x segments if segave=0; dimension frequencies if segave=1)
       S12 (cross spectrum -  frequencies x segments if segave=0; dimension frequencies if segave=1)
       S1 (spectrum 1 - frequencies x segments if segave=0; dimension frequencies if segave=1)
       S2 (spectrum 2 - frequencies x segments if segave=0; dimension frequencies if segave=1)
       f (frequencies)
       zerosp (1 for segments where no spikes were found, 0 otherwise)
       confC (confidence level for C at 1-p %) - only for err(1)>=1
       phierr (error bars for phi) - only for err(1)>=1
       Cerr  (Jackknife error bars for C - use only for Jackknife - err(1)=2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegpt(data1,data2,win,params,segave,fscorr)
0002 % Multi-taper coherency computed by segmenting two univariate point processes
0003 % into chunks
0004 %
0005 % Usage:
0006 % [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegpt(data1,data2,win,params,segave,fscorr)
0007 % Input:
0008 % Note units have to be consistent. See chronux.m for more information.
0009 %       data1 (1d structure array of spike times; also accepts 1d array of spike times) -- required
0010 %       data2 (1d structure array of spike times; also accepts 1d array of spike times) -- required
0011 %       win   (length of segments) - required
0012 %       params: structure with fields tapers, pad, Fs, fpass, err
0013 %       - optional
0014 %           tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
0015 %                                                 specified, use [NW K]=[3 5]
0016 %            pad            (padding factor for the FFT) - optional. Defaults to 0.
0017 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0018 %                       to 512 points; if PAD = 2, we pad the FFT
0019 %                       to 2048 points, etc.
0020 %           Fs   (sampling frequency) - optional. Default 1.
0021 %           fpass    (frequency band to be used in the calculation in the form
0022 %                                   [fmin fmax])- optional.
0023 %                                   Default all frequencies between 0 and Fs/2
0024 %           err  (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
0025 %                                   [0 p] or 0 - no error bars) - optional. Default 0.
0026 %       segave - optional 0 for don't average over segments, 1 for average - default
0027 %       fscorr   (finite size corrections, 0 (don't use finite size corrections) or 1 (use finite size corrections) - optional
0028 %                (available only for spikes). Defaults 0.
0029 % Output:
0030 %       C (magnitude of coherency - frequencies x segments if segave=0; dimension frequencies if segave=1)
0031 %       phi (phase of coherency - frequencies x segments if segave=0; dimension frequencies if segave=1)
0032 %       S12 (cross spectrum -  frequencies x segments if segave=0; dimension frequencies if segave=1)
0033 %       S1 (spectrum 1 - frequencies x segments if segave=0; dimension frequencies if segave=1)
0034 %       S2 (spectrum 2 - frequencies x segments if segave=0; dimension frequencies if segave=1)
0035 %       f (frequencies)
0036 %       zerosp (1 for segments where no spikes were found, 0 otherwise)
0037 %       confC (confidence level for C at 1-p %) - only for err(1)>=1
0038 %       phierr (error bars for phi) - only for err(1)>=1
0039 %       Cerr  (Jackknife error bars for C - use only for Jackknife - err(1)=2)
0040 
0041 
0042 if nargin < 3; error('Need data1 and data2 and size of segment'); end;
0043 if nargin < 4; params=[]; end;
0044 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0045 if nargin < 5 || isempty(segave); segave=1;end;
0046 if nargin < 6 || isempty(fscorr); fscorr=0; end;
0047 
0048 if nargout > 9 && err(1)~=2; 
0049     error('Cerr computed only for Jackknife. Correct inputs and run again');
0050 end;
0051 if nargout > 7 && err(1)==0;
0052     error('Errors computed only if err(1) is not equal to zero');
0053 end;
0054 
0055 [N1,C1,N2,C2]=check_consistency(data1,data2);
0056 [mintime1,maxtime1]=minmaxsptimes(data1);
0057 [mintime2,maxtime2]=minmaxsptimes(data2);
0058 mintime=min(mintime1,mintime2);
0059 maxtime=max(maxtime1,maxtime2);
0060 dt=1/Fs;
0061 t=mintime:dt:maxtime+dt; % time grid for prolates
0062 N=length(t); % number of points in grid for dpss
0063 
0064 E=mintime:win:maxtime; % fictitious event triggers
0065 win=[0 win]; % use window length to define left and right limits of windows around triggers
0066 data1=createdatamatpt(data1,E,win); % segmented data 1
0067 data2=createdatamatpt(data2,E,win); % segmented data 2
0068 params.trialave=segave;
0069 if err(1)==0;
0070    [C,phi,S12,S1,S2,f,zerosp]=coherencypt(data1,data2,params,fscorr); % compute coherency for segmented data
0071 elseif err(1)==1;
0072    [C,phi,S12,S1,S2,f,zerosp,confC,phierr]=coherencypt(data1,data2,params,fscorr); % compute coherency for segmented data
0073 elseif err(1)==2;
0074    [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencypt(data1,data2,params,fscorr); % compute coherency for segmented data
0075 end;

Generated on Tue 16-Aug-2005 21:33:45 by m2html © 2003