


Multi-taper time-frequency coherence - continuous processes
Usage:
[C,phi,t,f,confC,phierr,Cerr]=cohgramc(data1,data2,movingwin,tapers,nfft,Fs,fpass,err,trialave)
Input:
Note units have to be consistent. Thus, if movingwin is in seconds, Fs
has to be in Hz. see chronux.m for more information.
data1 (in form samples x channels/trials) -- required
data2 (in form samples x channels/trials) -- required
movingwin (in the form [window winstep] -- 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
err (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
[0 p] or 0 - no error bars) - optional. Default 0.
trialave (average over trials when 1, don't average when 0) - optional. Default 0
Output:
C (abs of coherency frequency index x channels/trials)
phi (phase of coherency frequency x channels/trials)
t (time)
f (frequencies)
confC (confidence level for c at 1-p %)
phierr (error bars for phi)
Cerr (Jackknife error bars for C - use only for Jackknife)

0001 function [C,phi,t,f,confC,phierr,Cerr]=cohgramc(data1,data2,movingwin,tapers,pad,Fs,fpass,err,trialave) 0002 % Multi-taper time-frequency coherence - continuous processes 0003 % 0004 % Usage: 0005 % 0006 % [C,phi,t,f,confC,phierr,Cerr]=cohgramc(data1,data2,movingwin,tapers,nfft,Fs,fpass,err,trialave) 0007 % Input: 0008 % Note units have to be consistent. Thus, if movingwin is in seconds, Fs 0009 % has to be in Hz. see chronux.m for more information. 0010 % 0011 % data1 (in form samples x channels/trials) -- required 0012 % data2 (in form samples x channels/trials) -- required 0013 % movingwin (in the form [window winstep] -- required 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 % trialave (average over trials when 1, don't average when 0) - optional. Default 0 0027 % Output: 0028 % C (abs of coherency frequency index x channels/trials) 0029 % phi (phase of coherency frequency x channels/trials) 0030 % t (time) 0031 % f (frequencies) 0032 % confC (confidence level for c at 1-p %) 0033 % phierr (error bars for phi) 0034 % Cerr (Jackknife error bars for C - use only for Jackknife) 0035 0036 if nargin < 3; error('Need data1 and data2 and window parameters'); end; 0037 [N1,C1]=size(data1);[N2,C2]=size(data2); 0038 if N1~=N2 | C1~=C2; error('data incompatible'); end; 0039 if nargin < 4; tapers=[3 5]; end; 0040 if nargin < 5;pad=0;end; 0041 if nargin < 6; Fs=1; end; 0042 if nargin < 7; fpass=[0 Fs/2]; end; 0043 if nargin < 8; err=0; end; 0044 if nargin < 9; trialave=0;end; 0045 if nargout > 6 & err(1)~=2; 0046 error('Cerr computed only for Jackknife. Correct inputs and run again'); 0047 end; 0048 0049 if isempty(tapers); tapers=[3 5]; end; 0050 if isempty(pad);pad=0;end; 0051 if isempty(Fs); Fs=1; end; 0052 if isempty(fpass); fpass=[0 Fs/2]; end; 0053 if isempty(err); err=0; end; 0054 if isempty(trialave); trialave=0;end; 0055 0056 0057 Nwin=round(Fs*movingwin(1)); % number of samples in window 0058 Nstep=round(movingwin(2)*Fs); % number of samples to step through 0059 nfft=2^(nextpow2(Nwin)+pad); 0060 [f,findx]=getfgrid(Fs,nfft,fpass); 0061 tapers=dpsschk(tapers,Nwin)/sqrt(Fs); % check tapers 0062 0063 winstart=[1:Nstep:N1-Nwin+1]; 0064 nw=length(winstart); 0065 for n=1:nw; 0066 indx=winstart(n):winstart(n)+Nwin-1; 0067 datawin1=data1(indx,:);datawin2=data2(indx,:); 0068 if nargout==7; 0069 [c,ph,f,confc,phie,cerr]=coherencyc(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave); 0070 confC=confc; 0071 phierr(1,n,:,:)=squeeze(phie(1,:,:)); 0072 phierr(2,n,:,:)=squeeze(phie(2,:,:)); 0073 Cerr(1,n,:,:)=squeeze(cerr(1,:,:)); 0074 Cerr(2,n,:,:)=squeeze(cerr(2,:,:)); 0075 elseif nargout==6; 0076 [c,ph,f,confc,phie]=coherencyc(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave); 0077 confC=confc; 0078 phierr(1,n,:,:)=squeeze(phie(1,:,:)); 0079 phierr(2,n,:,:)=squeeze(phie(2,:,:)); 0080 else 0081 [c,ph,f]=coherencyc(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave); 0082 end; 0083 C(n,:,:)=c; 0084 phi(n,:,:)=ph; 0085 end; 0086 C=squeeze(C); phi=squeeze(phi);if nargout==7;Cerr=squeeze(Cerr);end; 0087 if nargout==6; phierr=squeeze(phierr);end 0088 winmid=winstart+round(Nwin/2); 0089 t=winmid/Fs;