Home > NoiseTools > nt_multismooth.m

nt_multismooth

PURPOSE ^

z=nt_multismooth(x,smooth,alignment,diff_flag) - apply multiple smoothing kernels

SYNOPSIS ^

function z=nt_multismooth(x,smooth,alignment,diff_flag)

DESCRIPTION ^

z=nt_multismooth(x,smooth,alignment,diff_flag) - apply multiple smoothing kernels

   y: result (time * channels * nsmooth)

   x: matrix to smooth
   smooth: vector of smoothing kernel sizes
   alignment: 0: left [default], 1: center
   diff_flag: if true, return 1sr colum & between-column differences
 
 X is smoothed column by column (all smoothed versions of 1st column, then all
 of second column, etc).
 
 X may be 1D, 2D or 3D. See also nt_multishift.

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function z=nt_multismooth(x,smooth,alignment,diff_flag)
0002 %z=nt_multismooth(x,smooth,alignment,diff_flag) - apply multiple smoothing kernels
0003 %
0004 %   y: result (time * channels * nsmooth)
0005 %
0006 %   x: matrix to smooth
0007 %   smooth: vector of smoothing kernel sizes
0008 %   alignment: 0: left [default], 1: center
0009 %   diff_flag: if true, return 1sr colum & between-column differences
0010 %
0011 % X is smoothed column by column (all smoothed versions of 1st column, then all
0012 % of second column, etc).
0013 %
0014 % X may be 1D, 2D or 3D. See also nt_multishift.
0015 %
0016 % NoiseTools
0017 nt_greetings;
0018 
0019 if nargin<4 || isempty(diff_flag); diff_flag=0; end
0020 if nargin<3 || isempty(alignment); alignment=0; end
0021 if nargin<2; error('!'); end
0022 if min(smooth)<1; error('smooth must be positive'); end
0023 
0024 if iscell(x)
0025     for iCell=1:length(x);
0026         z{iCell}=nt_multismooth(x{iCell},smooth,alignment);
0027     end
0028     return
0029 end
0030 
0031 if size(x,1)<max(smooth); error('smoothing kernel size should be no larger than nrows'); end
0032 if min(smooth)<0; error('smoothing kernel size should be nonnegative'); end
0033 smooth=smooth(:)';
0034 nsmooth=numel(smooth);
0035 
0036 % array of shift indices
0037 [m,n,o]=size(x);
0038 z=zeros(m,n*nsmooth,o);
0039 
0040 for iPage=1:o
0041     zz=zeros(m,n,nsmooth);
0042     for iSmooth=1:nsmooth
0043         if alignment==0; nodelayflag=0; elseif alignment==1; nodelayflag=1; else; error('!!'); end
0044         zz(:,:,iSmooth)=nt_smooth(x(:,:,iPage),smooth(iSmooth),[],nodelayflag);
0045     end
0046     if diff_flag
0047         zz=cat(3,zz(:,:,1),diff(zz,[],3));
0048     end
0049     zz=permute(zz,[1,3,2]); 
0050     zz=reshape(zz,m,n*nsmooth);
0051     z(:,:,iPage)=zz;
0052 end
0053 
0054 if alignment==1;
0055     warning(['padding (samples): ',num2str(round(max(smooth)/2))]);
0056     z=z(1:end-round(max(smooth)/2),:,:);
0057     z=[zeros(round(max(smooth)/4),size(z,2)); z ; zeros(round(max(smooth)/2)-round(max(smooth)/4),size(z,2))];
0058 end
0059     
0060

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