Home > chronux_1_15 > continuous > ftestc.m

ftestc

PURPOSE ^

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

SYNOPSIS ^

function [Fval,A,f,sig,sd] = ftestc(data,params,p,plt)

DESCRIPTION ^

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

 [Fval,A,f,sig,sd] = ftestc(data,params,p,plt)

  Inputs:  
       data        (data in [N,C] i.e. time x channels/trials or a single
       vector) - required.
       params      structure containing parameters - params has the
       following fields: tapers, Fs, fpass, pad
            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/N where N is the number of samples which
                     corresponds to a false detect probability of approximately 0.05.
       plt         (y/n for plot and no plot respectively)

  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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Fval,A,f,sig,sd] = ftestc(data,params,p,plt)
0002 % computes the F-statistic for sine wave in locally-white noise (continuous data).
0003 %
0004 % [Fval,A,f,sig,sd] = ftestc(data,params,p,plt)
0005 %
0006 %  Inputs:
0007 %       data        (data in [N,C] i.e. time x channels/trials or a single
0008 %       vector) - required.
0009 %       params      structure containing parameters - params has the
0010 %       following fields: tapers, Fs, fpass, pad
0011 %            tapers         (parameters for calculating tapers [NW,K]) - optional. Defaults to [3 5]
0012 %            Fs             (sampling frequency) -- optional. Defaults to 1.
0013 %           fpass       (frequency band to be used in the calculation in the form
0014 %                                   [fmin fmax])- optional.
0015 %                                   Default all frequencies between 0 and Fs/2
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 %        p            (P-value to calculate error bars for) - optional. Defaults to 0.05/N where N is the number of samples which
0021 %                     corresponds to a false detect probability of approximately 0.05.
0022 %       plt         (y/n for plot and no plot respectively)
0023 %
0024 %  Outputs:
0025 %       Fval        (F-statistic in frequency x channels/trials form)
0026 %          A            (Line amplitude for X in frequency x channels/trials form)
0027 %        f            (frequencies of evaluation)
0028 %       sig         (F distribution (1-p)% confidence level)
0029 %       sd          (standard deviation of the amplitude C)
0030 if nargin < 1; error('Need data'); end;
0031 if nargin < 2 || isempty(params); params=[]; end;
0032 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0033 clear err trialave
0034 data=change_row_to_column(data);
0035 [N,C]=size(data);
0036 if nargin<3|| isempty(p);p=0.05/N;end;
0037 tapers=dpsschk(tapers,N,Fs); % calculate the tapers
0038 [N,K]=size(tapers);
0039 nfft=2^(nextpow2(N)+pad);% number of points in fft
0040 [f,findx]=getfgrid(Fs,nfft,fpass);% frequency grid to be returned
0041 % errorchk = 0; % set error checking to default (no errors calculated)
0042 % if nargout <= 3 % if called with 4 output arguments, activate error checking
0043 %     errorchk = 0;
0044 % else
0045 %     errorchk = 1;
0046 % end
0047 Kodd=1:2:K;
0048 Keven=2:2:K;
0049 J=mtfftc(data,tapers,nfft,Fs);% tapered fft of data - f x K x C
0050 Jp=J(findx,Kodd,:); % drop the even ffts and restrict fft to specified frequency grid - f x K x C
0051 tapers=tapers(:,:,ones(1,C)); % add channel indices to the tapers - t x K x C
0052 H0 = squeeze(sum(tapers(:,Kodd,:),1)); % calculate sum of tapers for even prolates - K x C
0053 if C==1;H0=H0';end;
0054 Nf=length(findx);% number of frequencies
0055 H0 = H0(:,:,ones(1,Nf)); % add frequency indices to H0 - K x C x f
0056 H0=permute(H0,[3 1 2]); % permute H0 to get dimensions to match those of Jp - f x K x C
0057 H0sq=sum(H0.*H0,2);% sum of squares of H0^2 across taper indices - f x C
0058 JpH0=sum(Jp.*squeeze(H0),2);% sum of the product of Jp and H0 across taper indices - f x C
0059 A=squeeze(JpH0./H0sq); % amplitudes for all frequencies and channels
0060 Kp=size(Jp,2); % number of even prolates
0061 Ap=A(:,:,ones(1,Kp)); % add the taper index to C
0062 Ap=permute(Ap,[1 3 2]); % permute indices to match those of H0
0063 Jhat=Ap.*H0; % fitted value for the fft
0064 
0065 num=(K-1).*(abs(A).^2).*squeeze(H0sq);%numerator for F-statistic
0066 den=squeeze(sum(abs(Jp-Jhat).^2,2)+sum(abs(J(findx,Keven,:)).^2,2));% denominator for F-statistic
0067 Fval=num./den; % F-statisitic
0068 if nargout > 3
0069    sig=finv(1-p,2,2*K-2); % F-distribution based 1-p% point
0070    var=den./(K*squeeze(H0sq)); % variance of amplitude
0071    sd=sqrt(var);% standard deviation of amplitude
0072 end;
0073 if nargout==0 || strcmp(plt,'y');
0074    [S,f]=mtspectrumc(detrend(data),params);subplot(211); plot(f,10*log10(S));xlabel('frequency Hz'); ylabel('Spectrum dB');
0075    subplot(212);plot(f,Fval); line(get(gca,'xlim'),[sig sig],'Color','r');xlabel('frequency Hz');
0076    ylabel('F ratio');
0077 end
0078 A=A*Fs;

Generated on Tue 15-Aug-2006 22:51:57 by m2html © 2003