Home > NoiseTools > nt_back.m

nt_back

PURPOSE ^

[iBest,y,topo]=nt_back(x,z,layout) - back-project component

SYNOPSIS ^

function [iBest,y,topo]=nt_back(x,z,layout)

DESCRIPTION ^

[iBest,y,topo]=nt_back(x,z,layout) - back-project component

  iBest: best channel per component 
  y: data from best channel per component 
  topoB: amplitude of other channels relative to best 

  x: raw data (timeXchannels pr timeXchannelsXtrials)
  z: component (timeX1 or timeX1Xtrials)
  layout: for optional topoplot
 
 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [iBest,y,topo]=nt_back(x,z,layout)
0002 %[iBest,y,topo]=nt_back(x,z,layout) - back-project component
0003 %
0004 %  iBest: best channel per component
0005 %  y: data from best channel per component
0006 %  topoB: amplitude of other channels relative to best
0007 %
0008 %  x: raw data (timeXchannels pr timeXchannelsXtrials)
0009 %  z: component (timeX1 or timeX1Xtrials)
0010 %  layout: for optional topoplot
0011 %
0012 % NoiseTools
0013 %
0014 
0015 if nargin==0; test_code; return; end
0016 
0017 if nargin<2; error('!'); end
0018 if nargin<3||isempty(layout); layout=[]; end
0019 if ndims(x)~=ndims(z); error('!'); end
0020 
0021 if ndims(x)==3
0022     % 3D: unfold to 2D
0023     [m,n,o]=size(x);
0024     x=nt_unfold(x);
0025     z=nt_unfold(z);
0026     if nargout~=0
0027         [iBest,y,topo]=nt_back(x,z,layout);
0028         y=nt_fold(y,m);
0029     else
0030         nt_back(x,z,layout);
0031     end
0032     return;
0033 end
0034 
0035 
0036 % correlation with each channel
0037 z=nt_normcol(z);
0038 topo=nt_xcov(z,x)/size(x,1); % non-normalized
0039 
0040 % best channel for each component
0041 [~,iBest]=max(abs(topo)');
0042 
0043 % back-project each component to its best channel
0044 for iComp=1:size(z,2)
0045     y(:,iComp)=z(:,iComp)*topo(iComp,iBest(iComp));
0046 end
0047 
0048 % make sure topo has right sign
0049 for iComp=1:size(z,2)
0050     topo(iComp,:)=topo(iComp,:)*sign(mean(z(:,iComp).*y(:,iComp)));
0051 end
0052 
0053 
0054 
0055 
0056 if nargout==0
0057     disp('nt_back: no output requested, plot back matrices');
0058     
0059     J=floor(sqrt(size(z,2)));
0060     K=ceil(size(z,2)/J);
0061 
0062     figure(101); clf;
0063     nt_banner('best channel for each component','fontsize',16)
0064     for iComp=1:size(z,2)
0065         subplot(J,K,iComp);
0066         plot(x(:,iBest(iComp)), ':k'); hold on
0067         plot(y(:,iComp), 'b');
0068         title(['c',num2str(iComp), ', ch', num2str(iBest)]);
0069     end
0070     
0071     if ~isempty(layout)
0072         figure(102); clf
0073         nt_banner('RMS per channel','fontsize',16)
0074         for iComp=1:size(z,2)
0075             subplot(J,K,iComp);
0076             nt_topoplot(layout, topo(iComp,:)); colorbar
0077             title(iComp);
0078         end
0079     end
0080     
0081     clear iBest y topo
0082  end
0083 
0084 
0085 
0086 end % function
0087 
0088 
0089 
0090 
0091 % test/example code
0092 function test_code
0093     disp('nt_back test code');
0094     disp('3D random matrix, apply nt_dss1, give to nt_back()');
0095     
0096     x=randn(1000,10,10);
0097     [todss]=nt_dss1(x);
0098     nt_back(x,todss)
0099 end % function

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005