Home > chronux_code > exploratory > correlations > continuous > cohgramc.m

cohgramc

PURPOSE ^

Multi-taper time-frequency coherence,cross-spectrum and individual spectra - continuous processes

SYNOPSIS ^

function [C,phi,S12,S1,S2,t,f,confC,phierr,Cerr]=cohgramc(data1,data2,movingwin,tapers,pad,Fs,fpass,err,trialave)

DESCRIPTION ^

 Multi-taper time-frequency coherence,cross-spectrum and individual spectra - continuous processes

 Usage:

 [C,phi,S12,S1,S2,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 trials) -- required
       data2 (in form samples x 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 time x frequency index x trials for no trial averaging)
       phi (phase of coherency time x frequency x trials for no trial averaging)
       S12 (cross spectrum - time x frequencies x trials for no trial averaging)
       S1 (spectrum 1- time x frequencies x trials for no trial averaging)
       S2 (spectrum 2- time x frequencies x trials for no trial averaging)
       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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [C,phi,S12,S1,S2,t,f,confC,phierr,Cerr]=cohgramc(data1,data2,movingwin,tapers,pad,Fs,fpass,err,trialave)
0002 % Multi-taper time-frequency coherence,cross-spectrum and individual spectra - continuous processes
0003 %
0004 % Usage:
0005 %
0006 % [C,phi,S12,S1,S2,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 trials) -- required
0012 %       data2 (in form samples x 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 time x frequency index x trials for no trial averaging)
0029 %       phi (phase of coherency time x frequency x trials for no trial averaging)
0030 %       S12 (cross spectrum - time x frequencies x trials for no trial averaging)
0031 %       S1 (spectrum 1- time x frequencies x trials for no trial averaging)
0032 %       S2 (spectrum 2- time x frequencies x trials for no trial averaging)
0033 %       t (time)
0034 %       f (frequencies)
0035 %       confC (confidence level for c at 1-p %)
0036 %       phierr (error bars for phi)
0037 %       Cerr  (Jackknife error bars for C - use only for Jackknife)
0038 
0039 if nargin < 3; error('Need data1 and data2 and window parameters'); end;
0040 if nargin < 4; tapers=[3 5]; end;
0041 if nargin < 5;pad=0;end;
0042 if nargin < 6; Fs=1; end;
0043 if nargin < 7; fpass=[0 Fs/2]; end;
0044 if nargin < 8; err=0; end;
0045 if nargin < 9; trialave=0;end;
0046 if nargout > 9 & err(1)~=2; 
0047     error('Cerr computed only for Jackknife. Correct inputs and run again');
0048 end;
0049 
0050 if isempty(tapers); tapers=[3 5]; end;
0051 if isempty(pad);pad=0;end;
0052 if isempty(Fs); Fs=1; end;
0053 if isempty(fpass); fpass=[0 Fs/2]; end;
0054 if isempty(err); err=0; end;
0055 if isempty(trialave); trialave=0;end;
0056 
0057 [N1,C1,N2,C2]=check_consistency(data1,data2);
0058 N=N1;
0059 
0060 Nwin=round(Fs*movingwin(1)); % number of samples in window
0061 Nstep=round(movingwin(2)*Fs); % number of samples to step through
0062 nfft=2^(nextpow2(Nwin)+pad);
0063 f=getfgrid(Fs,nfft,fpass); 
0064 tapers=dpsschk(tapers,Nwin,Fs); % check tapers
0065 
0066 winstart=1:Nstep:N-Nwin+1;
0067 nw=length(winstart);
0068 for n=1:nw;
0069    indx=winstart(n):winstart(n)+Nwin-1;
0070    datawin1=data1(indx,:);datawin2=data2(indx,:);
0071    if nargout==10;
0072      [c,ph,s12,s1,s2,f,confc,phie,cerr]=coherencyc(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave);
0073      confC=confc;
0074      phierr(1,n,:,:)=squeeze(phie(1,:,:));
0075      phierr(2,n,:,:)=squeeze(phie(2,:,:));
0076      Cerr(1,n,:,:)=squeeze(cerr(1,:,:));
0077      Cerr(2,n,:,:)=squeeze(cerr(2,:,:));
0078    elseif nargout==9;
0079      [c,ph,s12,s1,s2,f,confc,phie]=coherencyc(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave);
0080      confC=confc;
0081      phierr(1,n,:,:)=squeeze(phie(1,:,:));
0082      phierr(2,n,:,:)=squeeze(phie(2,:,:));
0083    else
0084      [c,ph,s12,s1,s2,f]=coherencyc(datawin1,datawin2,tapers,pad,Fs,fpass,err,trialave);
0085    end;
0086    C(n,:,:)=c;
0087    S12(n,:,:)=s12;
0088    S1(n,:,:)=s1;
0089    S2(n,:,:)=s2;
0090    phi(n,:,:)=ph;
0091 end;
0092 C=squeeze(C); phi=squeeze(phi);S12=squeeze(S12); S1=squeeze(S1); S2=squeeze(S2);
0093 if nargout==10;Cerr=squeeze(Cerr);end;
0094 if nargout>=9; phierr=squeeze(phierr);end
0095 winmid=winstart+round(Nwin/2);
0096 t=winmid/Fs;

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003