Home > chronux_1_50 > continuous > cohmatrixc.m

cohmatrixc

PURPOSE ^

Multi-taper coherency,cross-spectral matrix - continuous process

SYNOPSIS ^

function [C,phi,S12,f,confC,phistd,Cerr]=cohmatrixc(data,params)

DESCRIPTION ^

 Multi-taper coherency,cross-spectral matrix - continuous process

 Usage:

 [C,phi,S12,f,confC,phistd,Cerr]=cohmatrixc(data,params)
 Input: 
 Note units have to be consistent. See chronux.m for more information.
       data (in form samples x channels) -- required
       params: structure with fields tapers, pad, Fs, fpass, err
       - optional
           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 (can take values -1,0,1,2...). 
                    -1 corresponds to no padding, 0 corresponds to padding
                    to the next highest power of 2 etc.
                       e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
                       to 512 points, if pad=1, we pad to 1024 points etc.
                       Defaults to 0.
           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.
 Output:
       C (magnitude of coherency frequency x channels x channels)
       phi (phase of coherency frequency x channels x channels)
       S12 (cross-spectral matrix frequency x channels x channels)
       f (frequencies)
       confC (confidence level for C at 1-p %) - only for err(1)>=1
       phistd - theoretical/jackknife (depending on err(1)=1/err(1)=2) standard deviation for phi - Note that 
                phi + 2 phistd and phi - 2 phistd will give 95% confidence
                bands for phi - only for err(1)>=1 
       Cerr  (Jackknife error bars for C - use only for Jackknife - err(1)=2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [C,phi,S12,f,confC,phistd,Cerr]=cohmatrixc(data,params)
0002 % Multi-taper coherency,cross-spectral matrix - continuous process
0003 %
0004 % Usage:
0005 %
0006 % [C,phi,S12,f,confC,phistd,Cerr]=cohmatrixc(data,params)
0007 % Input:
0008 % Note units have to be consistent. See chronux.m for more information.
0009 %       data (in form samples x channels) -- required
0010 %       params: structure with fields tapers, pad, Fs, fpass, err
0011 %       - optional
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 (can take values -1,0,1,2...).
0015 %                    -1 corresponds to no padding, 0 corresponds to padding
0016 %                    to the next highest power of 2 etc.
0017 %                       e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
0018 %                       to 512 points, if pad=1, we pad to 1024 points etc.
0019 %                       Defaults to 0.
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 % Output:
0027 %       C (magnitude of coherency frequency x channels x channels)
0028 %       phi (phase of coherency frequency x channels x channels)
0029 %       S12 (cross-spectral matrix frequency x channels x channels)
0030 %       f (frequencies)
0031 %       confC (confidence level for C at 1-p %) - only for err(1)>=1
0032 %       phistd - theoretical/jackknife (depending on err(1)=1/err(1)=2) standard deviation for phi - Note that
0033 %                phi + 2 phistd and phi - 2 phistd will give 95% confidence
0034 %                bands for phi - only for err(1)>=1
0035 %       Cerr  (Jackknife error bars for C - use only for Jackknife - err(1)=2)
0036 if nargin < 1; error('need data'); end;
0037 if nargin < 2; params=[]; end;
0038 [N,Ch]=size(data);
0039 if Ch==1; error('Need at least two channels of data'); end;
0040 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0041 clear trialave params
0042 if nargout > 6 && err(1)~=2; 
0043     error('Cerr computed only for Jackknife. Correct inputs and run again');
0044 end;
0045 if nargout >= 4 && err(1)==0;
0046 %   Errors computed only if err(1) is nonzero. Need to change params and run again.
0047     error('When errors are desired, err(1) has to be non-zero.');
0048 end;
0049 nfft=max(2^(nextpow2(N)+pad),N);
0050 [f,findx]=getfgrid(Fs,nfft,fpass); 
0051 tapers=dpsschk(tapers,N,Fs); % check tapers
0052 J=mtfftc(data,tapers,nfft,Fs);
0053 J=J(findx,:,:); 
0054 if err(1)==0;
0055      [C,phi,S12]=cohmathelper(J,err);
0056 elseif err(1)==1;
0057      [C,phi,S12,confC,phistd]=cohmathelper(J,err);
0058 elseif err(1)==2;
0059      [C,phi,S12,confC,phistd,Cerr]=cohmathelper(J,err);
0060 end

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003