Home > NoiseTools > nt_smooth.m

nt_smooth

PURPOSE ^

y=nt_smooth(x,T,nIterations,nodelayflag) - smooth by convolution with square window

SYNOPSIS ^

function x=nt_smooth(x,T,nIterations,nodelayflag)

DESCRIPTION ^

y=nt_smooth(x,T,nIterations,nodelayflag) - smooth by convolution with square window

  y: smoothed data
 
  x: data to smooth
  T: samples, size of window (can be fractionary)
  nIterations: number of iterations of smoothing operation
  nodelayflag: if true, compensate for delay

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function x=nt_smooth(x,T,nIterations,nodelayflag)
0002 %y=nt_smooth(x,T,nIterations,nodelayflag) - smooth by convolution with square window
0003 %
0004 %  y: smoothed data
0005 %
0006 %  x: data to smooth
0007 %  T: samples, size of window (can be fractionary)
0008 %  nIterations: number of iterations of smoothing operation
0009 %  nodelayflag: if true, compensate for delay
0010 %
0011 
0012 if nargin<4; nodelayflag=0; end
0013 if nargin<3; nIterations=1; end
0014 if nargin<2; help nt_smooth ; error; end
0015 
0016 if ndims(x)>4; error('!'); end
0017 
0018 integ=floor(T);
0019 frac=T-integ;
0020 
0021 % remove onset step
0022 mn=mean(x(1:(integ+1),:,:),1);
0023 x=bsxfun(@minus,x,mn);
0024 
0025 % filter kernel
0026 B=[ones(integ,1);frac]/T;
0027 for k=1:nIterations-1
0028     B=conv(B,[ones(integ,1);frac]/T);
0029 end
0030 
0031 % apply
0032 x=filter(B,1,x);    
0033 
0034 if nodelayflag
0035     shift=round(T/2*nIterations); %[shift n*T]
0036     x=[x(shift+1:end,:,:,:); zeros(shift,size(x,2),size(x,3),size(x,4))];
0037 end
0038 
0039 % restore DC
0040 x=bsxfun(@plus,x,mn);

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