


Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting two univariate time series
into chunks - continuous and point process stored as times
Usage:
[C,phi,S12,S1,S2,f,zerosp]=coherencysegcpt(data1,data2,tapers,nfft,Fs,fpass,err,trialave)
Input:
Note units have to be consistent. See chronux.m for more information.
data1 (column vector, continuous data) -- required
data2 (1d structure array of spike times; also accepts 1d array of spike times) -- required
win (length of segments) - 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
segave (average over segments for 1, don't average for 0)
Output:
C (abs of coherency as a function of frequency and segment index)
phi (phase of coherency as a function of frequency and segment index)
S12 (cross spectrum - frequencies x segments for no segment averaging)
S1 (spectrum 1- frequencies x segments for no segment averaging)
S2 (spectrum 2- frequencies x segments for no segment averaging)
f (frequencies)
zerosp (1 for trials where no spikes were found, 0 otherwise)

0001 function [C,phi,S12,S1,S2,f,zerosp]=coherencysegcpt(data1,data2,win,tapers,pad,Fs,fpass,err,segave) 0002 % Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting two univariate time series 0003 % into chunks - continuous and point process stored as times 0004 % 0005 % Usage: 0006 % [C,phi,S12,S1,S2,f,zerosp]=coherencysegcpt(data1,data2,tapers,nfft,Fs,fpass,err,trialave) 0007 % Input: 0008 % Note units have to be consistent. See chronux.m for more information. 0009 % data1 (column vector, continuous data) -- required 0010 % data2 (1d structure array of spike times; also accepts 1d array of spike times) -- required 0011 % win (length of segments) - required 0012 % tapers(precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0013 % specified, use [NW K]=[3 5] 0014 % pad (padding factor for the FFT) - optional. Defaults to 0. 0015 % e.g. For N = 500, if PAD = 0, we pad the FFT 0016 % to 512 points; if PAD = 2, we pad the FFT 0017 % to 2048 points, etc. 0018 % Fs (sampling frequency) - optional. Default 1. 0019 % fpass (frequency band to be used in the calculation in the form 0020 % [fmin fmax])- optional. 0021 % Default all frequencies between 0 and Fs/2 0022 % segave (average over segments for 1, don't average for 0) 0023 % Output: 0024 % C (abs of coherency as a function of frequency and segment index) 0025 % phi (phase of coherency as a function of frequency and segment index) 0026 % S12 (cross spectrum - frequencies x segments for no segment averaging) 0027 % S1 (spectrum 1- frequencies x segments for no segment averaging) 0028 % S2 (spectrum 2- frequencies x segments for no segment averaging) 0029 % f (frequencies) 0030 % zerosp (1 for trials where no spikes were found, 0 otherwise) 0031 0032 if nargin < 3; error('Need data1 and data2 and size of segment'); end; 0033 if nargin < 4; tapers=[3 5]; end; 0034 if nargin < 5;pad=0;end; 0035 if nargin < 6; Fs=1; end; 0036 if nargin < 7; fpass=[0 Fs/2]; end; 0037 if isempty(tapers); tapers=[3 5]; end; 0038 if isempty(pad);pad=0;end; 0039 if isempty(Fs); Fs=1; end; 0040 if isempty(fpass); fpass=[0 Fs/2]; end; 0041 0042 [N1,C1,N2,C2]=check_consistency(data1,data2); 0043 N=N1; 0044 dt=1/Fs; % sampling interval 0045 T=N*dt; % length of data in seconds 0046 E=[dt:win:T]; % fictitious event triggers 0047 win=[0 win]; % use window length to define left and right limits of windows around triggers 0048 data1=createdatamatc(data1,E,Fs,win); % segmented data 1 0049 data2=createdatamatpt(data2,E,Fs,win); % segmented data 2 0050 [C,phi,S12,S1,S2,f,zerosp]=coherencycpt(data1,data2,tapers,pad,Fs,fpass,0,segave); % compute coherency for segmented data