


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 (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.
f0 (frequency of calculation)
Output:
P (integrated power within the frequency range of interest (trapezoidal integration))
Fstat (F-statistic)
f0 (frequency)

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 (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 % f0 (frequency of calculation) 0022 % Output: 0023 % P (integrated power within the frequency range of interest (trapezoidal integration)) 0024 % Fstat (F-statistic) 0025 % f0 (frequency) 0026 0027 if nargin < 1; error('Need data'); end; 0028 if nargin < 2; params=[]; end; 0029 [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params); 0030 clear fpass err trialave params 0031 data=change_row_to_column(data); 0032 [N,C]=size(data); 0033 tapers=dpsschk(tapers,N,Fs); % calculate the tapers 0034 [N,K]=size(tapers); 0035 nfft=max(2^(nextpow2(N)+pad),N);% number of points in fft 0036 %[f0,findx]=getfgrid(Fs,nfft,f0);% frequency grid to be returned 0037 0038 tapers=tapers(:,:,ones(1,C)); % add channel indices to tapers 0039 data=data(:,:,ones(1,K)); % add taper indices to data 0040 data=permute(data,[1 3 2]); % reshape data to get dimensions to match those of tapers 0041 data_proj=data.*tapers; % product of data with tapers in the form time x tapers x channels 0042 t=(0:N-1)'/Fs; 0043 fourier=exp(-i*2*pi*f0*t); 0044 fourier=fourier(:,ones(1,K),ones(1,C)); 0045 J=squeeze(sum(fourier.*data_proj))/Fs; 0046 0047 Kodd=1:2:K; 0048 Keven=2:2:K; 0049 tapers=tapers(:,:,ones(1,C)); % add channel indices to the tapers - t x K x C 0050 H0 = squeeze(sum(tapers(:,Kodd,:),1)); % calculate sum of tapers for even prolates - K x C 0051 0052 if C==1; H0=H0'; J=J'; end; 0053 P=squeeze(mean(J.*conj(J),1)); 0054 Jp=J(Kodd,:); % drop the even ffts 0055 H0sq=sum(H0.*H0,1);% sum of squares of H0^2 across taper indices - dimensions C 0056 JpH0=sum(Jp.*H0,1);% sum of the product of Jp and H0 across taper indices - f x C\ 0057 A=squeeze(JpH0./H0sq); % amplitudes for all frequencies and channels 0058 Kp=size(Jp,1); % number of even prolates 0059 Ap=A(ones(1,Kp),:); % add the taper index to C 0060 Jhat=Ap.*H0; % fitted value for the fft 0061 0062 num=(K-1).*(abs(A).^2).*squeeze(H0sq);%numerator for F-statistic 0063 den=squeeze(sum(abs(Jp-Jhat).^2,1)+sum(abs(J(Keven,:)).^2,1));% denominator for F-statistic 0064 Fstat=num./den; % F-statisitic 0065