Nonstationarity test - continuous process Usage: sigma=nonst_test(data,A,sumV,params) Input: Note units have to be consistent. See chronux.m for more information. data (1d array in samples) -- required A quadratic coefficient matrix - (Compute this separately since the computation is time consuming - [A,sumV]=quadcof(N,NW,order). order has to < 4NW.) sumV sum of the quadratic inverse basis vectors params: structure with fields tapers, pad, Fs, fpass, err, trialave -optional tapers : precalculated tapers from dpss or in the one of the following forms: (1) A numeric vector [TW K] where TW is the time-bandwidth product and K is the number of tapers to be used (less than or equal to 2TW-1). (2) A numeric vector [W T p] where W is the bandwidth, T is the duration of the data and p is an integer such that 2TW-p tapers are used. In this form there is no default i.e. to specify the bandwidth, you have to specify T and p as well. Note that the units of W and T have to be consistent: if W is in Hz, T must be in seconds and vice versa. Note that these units must also be consistent with the units of params.Fs: W can be in Hz if and only if params.Fs is in Hz. The default is to use form 1 with TW=3 and K=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. Output: sigma (nonstationarity index Thomson, 2000)
0001 function sigma = nonst_stat(data,A,sumV,params) 0002 0003 % Nonstationarity test - continuous process 0004 % 0005 % Usage: 0006 % 0007 % sigma=nonst_test(data,A,sumV,params) 0008 % Input: 0009 % Note units have to be consistent. See chronux.m for more information. 0010 % data (1d array in samples) -- required 0011 % A quadratic coefficient matrix - (Compute this separately since 0012 % the computation is time consuming - [A,sumV]=quadcof(N,NW,order). order 0013 % has to < 4NW.) 0014 % sumV sum of the quadratic inverse basis vectors 0015 % params: structure with fields tapers, pad, Fs, fpass, err, trialave 0016 % -optional 0017 % tapers : precalculated tapers from dpss or in the one of the following 0018 % forms: 0019 % (1) A numeric vector [TW K] where TW is the 0020 % time-bandwidth product and K is the number of 0021 % tapers to be used (less than or equal to 0022 % 2TW-1). 0023 % (2) A numeric vector [W T p] where W is the 0024 % bandwidth, T is the duration of the data and p 0025 % is an integer such that 2TW-p tapers are used. In 0026 % this form there is no default i.e. to specify 0027 % the bandwidth, you have to specify T and p as 0028 % well. Note that the units of W and T have to be 0029 % consistent: if W is in Hz, T must be in seconds 0030 % and vice versa. Note that these units must also 0031 % be consistent with the units of params.Fs: W can 0032 % be in Hz if and only if params.Fs is in Hz. 0033 % The default is to use form 1 with TW=3 and K=5 0034 % 0035 % pad (padding factor for the FFT) - optional (can take values -1,0,1,2...). 0036 % -1 corresponds to no padding, 0 corresponds to padding 0037 % to the next highest power of 2 etc. 0038 % e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT 0039 % to 512 points, if pad=1, we pad to 1024 points etc. 0040 % Defaults to 0. 0041 % Fs (sampling frequency) - optional. Default 1. 0042 % Output: 0043 % sigma (nonstationarity index Thomson, 2000) 0044 0045 0046 if nargin < 1; error('Need data'); end; 0047 if nargin < 2; params=[]; end; 0048 0049 order = length(A); 0050 N = length(data); 0051 %nfft=max(2^(nextpow2(N)+pad),N); 0052 [tapers,pad,Fs]=getparams(params); 0053 tapers=dpsschk(tapers,N,Fs); % check tapers 0054 0055 alpha=zeros(1,order); 0056 for j=1:order 0057 alpha(j) = trace(squeeze(A(:,:,j))*squeeze(A(:,:,j))); 0058 end; 0059 0060 tmp=mtfftc(data,tapers,N,Fs); 0061 %tmp=mtfftc(data,tapers,nfft,Fs); 0062 sigma = zeros(length(data),1); 0063 % Pbar = sum(abs(tmp).^2,2)./sum(weights.^2,2); 0064 Pbar=mean(abs(tmp).^2,2); 0065 for ii=1:order 0066 a0=real(sum(tmp'.*(squeeze(A(:,:,ii))*tmp.')))'/alpha(ii); 0067 sigma=sigma+alpha(ii)*(a0./Pbar-sumV(ii)).^2; 0068 end; 0069