Home > chronux_1_1 > 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 - standard deviation for phi (note that the routine gives phierr as phierr(1,...) and phierr(2,...) 
                in order to incorporate Jackknife (eventually). Currently phierr(1,...)=phierr(2,...). Note that 
                phi + 2 phierr(1,...) and phi -2 phierr(2,...) will give 95% confidence bands 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 - standard deviation for phi (note that the routine gives phierr as phierr(1,...) and phierr(2,...)
0039 %                in order to incorporate Jackknife (eventually). Currently phierr(1,...)=phierr(2,...). Note that
0040 %                phi + 2 phierr(1,...) and phi -2 phierr(2,...) will give 95% confidence bands for phi - only for err(1)>=1
0041 %       Cerr  (Jackknife error bars for C - use only for Jackknife - err(1)=2)
0042 
0043 
0044 if nargin < 3; error('Need data1 and data2 and size of segment'); end;
0045 if nargin < 4; params=[]; end;
0046 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0047 clear tapers pad fpass trialave
0048 if nargin < 5 || isempty(segave); segave=1;end;
0049 if nargin < 6 || isempty(fscorr); fscorr=0; end;
0050 
0051 if nargout > 9 && err(1)~=2; 
0052     error('Cerr computed only for Jackknife. Correct inputs and run again');
0053 end;
0054 if nargout > 7 && err(1)==0;
0055     error('Errors computed only if err(1) is not equal to zero');
0056 end;
0057 
0058 check_consistency(data1,data2);
0059 [mintime1,maxtime1]=minmaxsptimes(data1);
0060 [mintime2,maxtime2]=minmaxsptimes(data2);
0061 mintime=min(mintime1,mintime2);
0062 maxtime=max(maxtime1,maxtime2);
0063 % dt=1/Fs;
0064 % t=mintime:dt:maxtime+dt; % time grid for prolates
0065 % N=length(t); % number of points in grid for dpss
0066 
0067 E=mintime:win:maxtime; % fictitious event triggers
0068 win=[0 win]; % use window length to define left and right limits of windows around triggers
0069 data1=createdatamatpt(data1,E,win); % segmented data 1
0070 data2=createdatamatpt(data2,E,win); % segmented data 2
0071 params.trialave=segave;
0072 if err(1)==0;
0073    [C,phi,S12,S1,S2,f,zerosp]=coherencypt(data1,data2,params,fscorr); % compute coherency for segmented data
0074 elseif err(1)==1;
0075    [C,phi,S12,S1,S2,f,zerosp,confC,phierr]=coherencypt(data1,data2,params,fscorr); % compute coherency for segmented data
0076 elseif err(1)==2;
0077    [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencypt(data1,data2,params,fscorr); % compute coherency for segmented data
0078 end;

Generated on Sun 13-Aug-2006 11:49:44 by m2html © 2003