crossspecc

PURPOSE ^

SYNOPSIS ^

function [S12,f]=crossspecc(data1,data2,tapers,pad,Fs,fpass)

DESCRIPTION ^


 Multi-taper spectrum - continuous process

 Usage:

 [S12,f]=crossspecc(data1,data2,tapers,pad,Fs,fpass)
 Input: 
 Note units have to be consistent. See chronux.m for more information.
       data1 (in form samples x channels/trials) -- required
       data2 (in form samples x channels/trials) -- 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
 Output:
       S12 (cross spectrum frequency x channels/trials)
       f (frequencies)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [S12,f]=crossspecc(data1,data2,tapers,pad,Fs,fpass)
0002 %
0003 %
0004 % Multi-taper spectrum - continuous process
0005 %
0006 % Usage:
0007 %
0008 % [S12,f]=crossspecc(data1,data2,tapers,pad,Fs,fpass)
0009 % Input:
0010 % Note units have to be consistent. See chronux.m for more information.
0011 %       data1 (in form samples x channels/trials) -- required
0012 %       data2 (in form samples x channels/trials) -- required
0013 %       tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
0014 %                                                 specified, use [NW K]=[3 5]
0015 %        pad            (padding factor for the FFT) - optional. Defaults to 0.
0016 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0017 %                       to 512 points; if PAD = 2, we pad the FFT
0018 %                       to 2048 points, etc.
0019 %       Fs   (sampling frequency) - optional. Default 1.
0020 %       fpass    (frequency band to be used in the calculation in the form
0021 %                                   [fmin fmax])- optional.
0022 %                                   Default all frequencies between 0 and Fs/2
0023 % Output:
0024 %       S12 (cross spectrum frequency x channels/trials)
0025 %       f (frequencies)
0026 if nargin < 2; error('Need data1 and data2'); end;
0027 N=size(data1,1);
0028 if nargin < 3; tapers=[3 5]; end;
0029 if nargin < 4;pad=0;end;
0030 if nargin < 5; Fs=1; end;
0031 if nargin < 6; fpass=[0 Fs/2]; end;
0032 if isempty(tapers); tapers=[3 5]; end;
0033 if isempty(pad);pad=0;end;
0034 if isempty(Fs); Fs=1; end;
0035 if isempty(fpass); fpass=[0 Fs/2]; end;
0036 
0037 nfft=2^(nextpow2(N)+pad);
0038 [f,findx]=getfgrid(Fs,nfft,fpass); 
0039 tapers=dpsschk(tapers,N,Fs); % check tapers
0040 J1=mtfftc(data1,tapers,nfft,Fs);
0041 J2=mtfftc(data2,tapers,nfft,Fs);
0042 J1=J1(findx,:,:); J2=J2(findx,:,:);
0043 S12=squeeze(mean(conj(J1).*J2,2));
0044 if trialave; S12=squeeze(mean(S12,2));end;

Generated on Fri 20-May-2005 13:10:28 by m2html © 2003