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     ww(w)=1;
0023     w=ww;
0024 end
0025 
0026 if ndims(x)==4; 
0027     for k=1:size(x,4);
0028         if isempty(w);
0029             x(:,:,:,k)=nt_demean2(x(:,:,:,k));
0030         else
0031             if ndims(w)==4; 
0032                 x(:,:,:,k)=nt_demean2(x(:,:,:,k),w(:,:,:,k));
0033             else
0034                 x(:,:,:,k)=nt_demean2(x(:,:,:,k),w);
0035             end
0036         end
0037     end
0038     return
0039 end
0040             
0041 if ~isempty(w)
0042     if size(w,3)==1 && size(x,3)~=1;
0043         w=repmat(w,[1,1,size(x,3)]);
0044     end
0045     if size(w,3)~=size(x,3)
0046         error('W should have same npages as X, or else 1');
0047     end
0048 end
0049 
0050 [m,n,o]=size(x);
0051 if isempty(w)
0052     x=reshape(nt_demean(reshape(x,m,n*o)), [m,n,o]);
0053 else
0054     w=repmat(w,[1,n,1]);
0055     x=reshape(nt_demean(reshape(x,m,n*o),reshape(w,m,n*o)),[m,n,o]);
0056 end
0057

Generated on Tue 18-Feb-2020 11:23:12 by m2html © 2005