Home > chronux_1_1 > continuous > mtpowerandfstatc.m

mtpowerandfstatc

PURPOSE ^

Multi-taper computation of the power and the fstatistic for a particular frequency - continuous process

SYNOPSIS ^

function [P,Fstat,f0]=mtpowerandfstatc(data,params,f0)

DESCRIPTION ^

 Multi-taper computation of the power and the fstatistic for a particular frequency - continuous process

 Usage:

 [P,Fstat,f0]=mtpowerandfstatc(data,params,f0)
 Input: 
 Note units have to be consistent. See chronux.m for more information.
       data (in form samples x channels/trials or a single vector) -- required
       params: structure with fields tapers, pad, Fs, fpass, err, trialave
       -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. 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.
       f0  (frequency of calculation)
 Output:
       P       (integrated power within the frequency range of interest (trapezoidal integration))
       Fstat   (F-statistic)
       f0      (frequency)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [P,Fstat,f0]=mtpowerandfstatc(data,params,f0)
0002 % Multi-taper computation of the power and the fstatistic for a particular frequency - continuous process
0003 %
0004 % Usage:
0005 %
0006 % [P,Fstat,f0]=mtpowerandfstatc(data,params,f0)
0007 % Input:
0008 % Note units have to be consistent. See chronux.m for more information.
0009 %       data (in form samples x channels/trials or a single vector) -- required
0010 %       params: structure with fields tapers, pad, Fs, fpass, err, trialave
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. Defaults to 0.
0015 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0016 %                       to 512 points; if PAD = 2, we pad the FFT
0017 %                       to 2048 points, etc.
0018 %           Fs   (sampling frequency) - optional. Default 1.
0019 %       f0  (frequency of calculation)
0020 % Output:
0021 %       P       (integrated power within the frequency range of interest (trapezoidal integration))
0022 %       Fstat   (F-statistic)
0023 %       f0      (frequency)
0024 
0025 if nargin < 1; error('Need data'); end;
0026 if nargin < 2; params=[]; end;
0027 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0028 clear fpass err trialave params
0029 data=change_row_to_column(data);
0030 [N,C]=size(data);
0031 tapers=dpsschk(tapers,N,Fs); % calculate the tapers
0032 [N,K]=size(tapers);
0033 nfft=2^(nextpow2(N)+pad);% number of points in fft
0034 %[f0,findx]=getfgrid(Fs,nfft,f0);% frequency grid to be returned
0035 
0036 tapers=tapers(:,:,ones(1,C)); % add channel indices to tapers
0037 data=data(:,:,ones(1,K)); % add taper indices to data
0038 data=permute(data,[1 3 2]); % reshape data to get dimensions to match those of tapers
0039 data_proj=data.*tapers; % product of data with tapers in the form time x tapers x channels
0040 t=(0:N-1)'/Fs;
0041 fourier=exp(-i*2*pi*f0*t);
0042 fourier=fourier(:,ones(1,K),ones(1,C));
0043 J=squeeze(sum(fourier.*data_proj))/Fs; 
0044 
0045 Kodd=1:2:K;
0046 Keven=2:2:K;
0047 tapers=tapers(:,:,ones(1,C)); % add channel indices to the tapers - t x K x C
0048 H0 = squeeze(sum(tapers(:,Kodd,:),1)); % calculate sum of tapers for even prolates - K x C
0049 
0050 if C==1; H0=H0'; J=J'; end;
0051 P=squeeze(mean(J.*conj(J),1));
0052 Jp=J(Kodd,:); % drop the even ffts
0053 H0sq=sum(H0.*H0,1);% sum of squares of H0^2 across taper indices - dimensions C
0054 JpH0=sum(Jp.*H0,1);% sum of the product of Jp and H0 across taper indices - f x C\
0055 A=squeeze(JpH0./H0sq); % amplitudes for all frequencies and channels
0056 Kp=size(Jp,1); % number of even prolates
0057 Ap=A(ones(1,Kp),:); % add the taper index to C
0058 Jhat=Ap.*H0; % fitted value for the fft
0059 
0060 num=(K-1).*(abs(A).^2).*squeeze(H0sq);%numerator for F-statistic
0061 den=squeeze(sum(abs(Jp-Jhat).^2,1)+sum(abs(J(Keven,:)).^2,1));% denominator for F-statistic
0062 Fstat=num./den; % F-statisitic
0063

Generated on Sun 13-Aug-2006 11:49:44 by m2html © 2003