y=nt_specific(x) - isolate channel-specific activity y: channel-specific component x: data (2D or 3D) w: weights thresh: threshold to discard PCs (default: 10^-6)
0001 function y=nt_specific(x,w,thresh) 0002 %y=nt_specific(x) - isolate channel-specific activity 0003 % 0004 % y: channel-specific component 0005 % 0006 % x: data (2D or 3D) 0007 % w: weights 0008 % thresh: threshold to discard PCs (default: 10^-6) 0009 0010 if nargin<3||isempty(thresh); thresh=0; end 0011 if nargin<2; w=[]; end 0012 0013 if ~isempty(w); error('weights not yet implemented'); end 0014 0015 if ndims(x)>2; 0016 [m,n,o]=size(x); 0017 x=nt_specific(nt_unfold(x),w,thresh); 0018 x=nt_fold(x,m); 0019 return 0020 end 0021 0022 [m,n]=size(x); 0023 cc=x'*x; 0024 0025 y=zeros(size(x)); 0026 for k=1:n 0027 idx=[1:k-1,k+1:n]; 0028 [topcs,eigenvalues]=nt_pcarot(cc(idx,idx)); % PCA to orthogonalize the other channels 0029 topcs=topcs(:,find(eigenvalues/max(eigenvalues)>thresh)); 0030 b=x(:,idx)*topcs(:,:); 0031 b=nt_normcol(b); % this could be optimized 0032 c=x(:,k)'*b/m; % projection matrix 0033 %y(:,k)=x(:,k)-b*c'; % remove projection 0034 y(:,k)=b*c'; % remove projection 0035 end 0036 0037 0038 0039 % function x=nt_specific(x,w,thresh) 0040 % %y=nt_specific(x) - isolate channel-specific activity 0041 % % 0042 % % y: channel-specific component 0043 % % 0044 % % x: data (2D or 3D) 0045 % % w: weights 0046 % % thresh: threshold to discard PCs (default: 10^-6) 0047 % 0048 % if nargin<3||isempty(thresh); thresh=0; end 0049 % if nargin<2; w=[]; end 0050 % 0051 % if ~isempty(w); error('weights not yet implemented'); end 0052 % 0053 % if ndims(x)>2; 0054 % [m,n,o]=size(x); 0055 % x=nt_specific(nt_unfold(x),w,thresh); 0056 % x=nt_fold(x,m); 0057 % return 0058 % end 0059 % [m,n]=size(x); 0060 % cc=x'*x; 0061 % 0062 % y=zeros(size(x)); 0063 % for k=1:n 0064 % idx=[1:k-1,k+1:n]; 0065 % [topcs,eigenvalues]=nt_pcarot(cc(idx,idx)); % PCA to orthogonalize the other channels 0066 % topcs=topcs(:,1:60); 0067 % %topcs=topcs(:,find(eigenvalues/max(eigenvalues)>thresh)); 0068 % b=x(:,idx)*topcs(:,:); 0069 % b=nt_normcol(b); % this could be optimized 0070 % c=x(:,k)'*b/m; % projection matrix 0071 % x(:,k)=x(:,k)-b*c'; % remove projection 0072 % cc(idx,k)=x(:,k)'*x(:,idx); % update covariance matrix 0073 % cc(k,:)=cc(:,k)'; 0074 % end