


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