ftestc

PURPOSE ^

ftestc computes the F-statistic for sine wave in locally-white noise (continuous data).

SYNOPSIS ^

function [Fval,A,f,sig,sd] = ftestc(data,tapers,Fs,fpass,pad,p)

DESCRIPTION ^

 ftestc computes the F-statistic for sine wave in locally-white noise (continuous data).

 [Fval,A,f,sig,sd] = ftest(data,tapers,Fs,fpass,pad,p)

  Inputs:  
       data        (data in [N,C] i.e. time x channels/trials) - required.
        tapers         (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
        Fs             (sampling frequency) -- optional. Defaults to 1.
       fpass       (frequency band to be used in the calculation in the form
                                   [fmin fmax])- optional. 
                                   Default all frequencies between 0 and Fs/2
        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.
        p            (P-value to calculate error bars for) - optional. Defaults to 0.05 (95% confidence).


  Outputs: 
       Fval        (F-statistic in frequency x channels/trials form)
          A            (Line amplitude for X in frequency x channels/trials form) 
        f            (frequencies of evaluation) 
       sig         (F distribution (1-p)% confidence level)
       sd          (standard deviation of the amplitude C) - optional

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Fval,A,f,sig,sd] = ftestc(data,tapers,Fs,fpass,pad,p)
0002 % ftestc computes the F-statistic for sine wave in locally-white noise (continuous data).
0003 %
0004 % [Fval,A,f,sig,sd] = ftest(data,tapers,Fs,fpass,pad,p)
0005 %
0006 %  Inputs:
0007 %       data        (data in [N,C] i.e. time x channels/trials) - required.
0008 %        tapers         (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
0009 %        Fs             (sampling frequency) -- optional. Defaults to 1.
0010 %       fpass       (frequency band to be used in the calculation in the form
0011 %                                   [fmin fmax])- optional.
0012 %                                   Default all frequencies between 0 and Fs/2
0013 %        pad            (padding factor for the FFT) - optional. Defaults to 0.
0014 %                       e.g. For N = 500, if PAD = 0, we pad the FFT
0015 %                       to 512 points; if PAD = 2, we pad the FFT
0016 %                       to 2048 points, etc.
0017 %        p            (P-value to calculate error bars for) - optional. Defaults to 0.05 (95% confidence).
0018 %
0019 %
0020 %  Outputs:
0021 %       Fval        (F-statistic in frequency x channels/trials form)
0022 %          A            (Line amplitude for X in frequency x channels/trials form)
0023 %        f            (frequencies of evaluation)
0024 %       sig         (F distribution (1-p)% confidence level)
0025 %       sd          (standard deviation of the amplitude C) - optional
0026 if nargin < 1; error('Need data'); end;
0027 [N,C]=size(data);
0028 if nargin<2; tapers=[3 5];end;
0029 if nargin<3; Fs=1; end;
0030 if nargin<4;fpass=[0 Fs/2];end;
0031 if nargin<5;pad=0;end;
0032 if nargin<6;p=0.05;end;
0033 tapers=dpsschk(tapers,N); % calculate the tapers
0034 [N,K]=size(tapers);
0035 nfft=2^(nextpow2(N)+pad);% number of points in fft
0036 [f,findx]=getfgrid(Fs,nfft,fpass);% frequency grid to be returned
0037 errorchk = 0; % set error checking to default (no errors calculated)
0038 if nargout <= 3 % if called with 4 output arguments, activate error checking
0039     errorchk = 0;
0040 else
0041     errorchk = 1; 
0042 end 
0043 Kodd=1:2:K;
0044 Keven=2:2:K;
0045 J=mtfftc(data,tapers,nfft);% tapered fft of data - f x K x C
0046 Jp=J(findx,Kodd,:); % drop the even ffts and restrict fft to specified frequency grid - f x K x C
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 if C==1;H0=H0';end;
0050 Nf=length(findx);% number of frequencies
0051 H0 = H0(:,:,ones(1,Nf)); % add frequency indices to H0 - K x C x f
0052 H0=permute(H0,[3 1 2]); % permute H0 to get dimensions to match those of Jp - f x K x C
0053 H0sq=sum(H0.*H0,2);% sum of squares of H0^2 across taper indices - f x C
0054 JpH0=sum(Jp.*squeeze(H0),2);% 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,2); % number of even prolates
0057 Ap=A(:,:,ones(1,Kp)); % add the taper index to C
0058 Ap=permute(Ap,[1 3 2]); % permute indices to match those of H0
0059 Jhat=Ap.*H0; % fitted value for the fft
0060 
0061 num=(K-1).*(abs(A).^2).*squeeze(H0sq);%numerator for F-statistic
0062 den=squeeze(sum(abs(Jp-Jhat).^2,2)+sum(abs(J(findx,Keven,:)).^2,2));% denominator for F-statistic
0063 Fval=num./den; % F-statisitic
0064 sig=finv(1-p,2,2*K-2); % F-distribution based 1-p% point
0065 var=den./(K*squeeze(H0sq)); % variance of amplitude
0066 sd=sqrt(var);% standard deviation of amplitude
0067 if nargout==0 
0068    plot(f,Fval); line(get(gca,'xlim'),[sig sig],'Color','r');xlabel('frequency Hz');
0069     ylabel('F ratio');
0070 end

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