[squares,quads,D]=nt_qca(x,npcs,nsmooth,nquads) - maximize induced power using quadratic component analysis squares: linear components closest to most repeatable quadratic component quads: most reproducible quadratic component(s) D: eigenvalues x: data (time*channel*trial) npcs: maximum number of data PCs to use (if [] use all) nsmooth: square smoothing window to apply to xproducts [default: 1] nquads: number of quadratic components to return [default: 1] Usually we are interested in the first component of 'squares' (component with square closest to best quadratic component). See nt_qca0, nt_quad2square. NoiseTools.
0001 function [squares,quads,D]=nt_qca(x,npcs,nsmooth,nquads) 0002 %[squares,quads,D]=nt_qca(x,npcs,nsmooth,nquads) - maximize induced power using quadratic component analysis 0003 % 0004 % squares: linear components closest to most repeatable quadratic component 0005 % quads: most reproducible quadratic component(s) 0006 % D: eigenvalues 0007 % 0008 % x: data (time*channel*trial) 0009 % npcs: maximum number of data PCs to use (if [] use all) 0010 % nsmooth: square smoothing window to apply to xproducts [default: 1] 0011 % nquads: number of quadratic components to return [default: 1] 0012 % 0013 % Usually we are interested in the first component of 'squares' 0014 % (component with square closest to best quadratic component). 0015 % 0016 % See nt_qca0, nt_quad2square. 0017 % NoiseTools. 0018 0019 0020 if nargin<4||isempty(nquads); nquads=1; end 0021 if nargin<3||isempty(nsmooth); nsmooth=1; end 0022 if nargin<2; error('!'); end 0023 [nsamples,nchans,ntrials]=size(x); 0024 0025 x=[x,ones(nsamples,1,ntrials)*max(abs(x(:)))]; % append a DC component to absorb DC 0026 0027 if nargout==1; 0028 tosquares=nt_qca0(x,npcs,nsmooth,nquads); 0029 else 0030 [tosquares,quads,D]=nt_qca0(x,npcs,nsmooth,nquads); 0031 quads=quads(:,2:end,:); % discard first (DC) 0032 end 0033 0034 squares=nt_mmat(x,tosquares); 0035 squares=nt_demean2(squares); 0036 0037 if 0 0038 r=nt_repeatability(squares.^2); 0039 [dummy,idx]=sort(r,'descend'); 0040 squares=squares(:,idx,:); 0041 end 0042 0043 if nargout==0; 0044 disp('no output arguments: plot'); 0045 figure(100); 0046 subplot 311; 0047 plot(abs(D), '.-'); xlabel('component'); ylabel('score'); 0048 subplot 312; 0049 nt_bsplot(quads(:,1,:)); 0050 title('best quadratic'); 0051 subplot 313; 0052 nt_bsplot(squares(:,1,:).^2); 0053 xlabel('samples'); title('closest square'); 0054 clear squares quads D 0055 end 0056 0057 0058 0059 0060 0061