Home > NoiseTools > nt_demean2.m

nt_demean2

PURPOSE ^

y=nt_demean2(x,w) - remove mean of each row and page

SYNOPSIS ^

function x=nt_demean2(x,w)

DESCRIPTION ^

y=nt_demean2(x,w) - remove mean of each row and page
 
  w is optional

  if w is a vector with fewer samples than size(x,1), it is interpreted as
  a vector of indices to be set to 1, the others being set to 0.

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function x=nt_demean2(x,w)
0002 %y=nt_demean2(x,w) - remove mean of each row and page
0003 %
0004 %  w is optional
0005 %
0006 %  if w is a vector with fewer samples than size(x,1), it is interpreted as
0007 %  a vector of indices to be set to 1, the others being set to 0.
0008 %
0009 % NoiseTools
0010 
0011 
0012 if nargin<2; w=[]; end
0013 if nargin<1; error('!');end
0014 
0015 if ~isempty(w) && numel(w)<size(x,1)
0016     w=w(:);
0017     % interpret w as array of indices to set to 1
0018     if min(w)<1 || max(w)>size(x,1); 
0019         error('w interpreted as indices but values are out of range');
0020     end
0021     ww=zeros(size(x,1),1);
0022     size(ww)
0023     ww(w)=1;
0024     w=ww;
0025 end
0026 
0027 if ndims(x)==4; 
0028     for k=1:size(x,4);
0029         if isempty(w);
0030             x(:,:,:,k)=nt_demean2(x(:,:,:,k));
0031         else
0032             if ndims(w)==4; 
0033                 x(:,:,:,k)=nt_demean2(x(:,:,:,k),w(:,:,:,k));
0034             else
0035                 x(:,:,:,k)=nt_demean2(x(:,:,:,k),w);
0036             end
0037         end
0038     end
0039     return
0040 end
0041             
0042 if ~isempty(w)
0043     if size(w,3)==1 && size(x,3)~=1;
0044         w=repmat(w,[1,1,size(x,3)]);
0045     end
0046     if size(w,3)~=size(x,3)
0047         error('W should have same npages as X, or else 1');
0048     end
0049 end
0050 
0051 [m,n,o]=size(x);
0052 if isempty(w)
0053     x=reshape(nt_demean(reshape(x,m,n*o)), [m,n,o]);
0054 else
0055     w=repmat(w,[1,n,1]);
0056     x=reshape(nt_demean(reshape(x,m,n*o),reshape(w,m,n*o)),[m,n,o]);
0057 end
0058

Generated on Mon 10-Nov-2014 14:40:42 by m2html © 2005