


Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting two univariate time series into chunks - continuous process
Usage:
[C,phi,S12,S1,S2,f]=coherencysegc(data1,data2,win,tapers,pad,Fs,fpass,segave)
Input:
Note units have to be consistent. See chronux.m for more information.
data1 (column vector) -- required
data2 (column vector) -- 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 x segments for no segment averaging)
phi (phase of coherency as a function of frequency x segments for no segment averaging)
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)

0001 function [C,phi,S12,S1,S2,f]=coherencysegc(data1,data2,win,tapers,pad,Fs,fpass,segave) 0002 % Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting two univariate time series into chunks - continuous process 0003 % 0004 % Usage: 0005 % [C,phi,S12,S1,S2,f]=coherencysegc(data1,data2,win,tapers,pad,Fs,fpass,segave) 0006 % Input: 0007 % Note units have to be consistent. See chronux.m for more information. 0008 % data1 (column vector) -- required 0009 % data2 (column vector) -- 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 x segments for no segment averaging) 0024 % phi (phase of coherency as a function of frequency x segments for no segment averaging) 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 if nargin < 3; error('Need data1 and data2 and size of segment'); end; 0030 if nargin < 4; tapers=[3 5]; end; 0031 if nargin < 5;pad=0;end; 0032 if nargin < 6; Fs=1; end; 0033 if nargin < 7; fpass=[0 Fs/2]; end; 0034 if isempty(tapers); tapers=[3 5]; end; 0035 if isempty(pad);pad=0;end; 0036 if isempty(Fs); Fs=1; end; 0037 if isempty(fpass); fpass=[0 Fs/2]; end; 0038 0039 [N1,C1,N2,C2]=check_consistency(data1,data2); 0040 N=N1; 0041 0042 dt=1/Fs; % sampling interval 0043 T=N*dt; % length of data in seconds 0044 E=[dt:win:T]; % fictitious event triggers 0045 win=[0 win]; % use window length to define left and right limits of windows around triggers 0046 data1=createdatamatc(data1,E,Fs,win); % segmented data 1 0047 data2=createdatamatc(data2,E,Fs,win); % segmented data 2 0048 [C,phi,S12,S1,S2,f]=coherencyc(data1,data2,tapers,pad,Fs,fpass,0,segave); % compute coherency for segmented data