Home > NoiseTools > nt_multishift.m

nt_multishift

PURPOSE ^

z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix

SYNOPSIS ^

function z=nt_multishift(x,shifts)

DESCRIPTION ^

z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix

   y: result

   x: matrix to shift
   shifts: array of shifts (must be nonnegative)
 
 X is shifted column by column (all shifts of 1st column, then all
 shifts of second column, etc).
 
 X may be 1D, 2D or 3D. See also convmtx.

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function z=nt_multishift(x,shifts)
0002 %z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix
0003 %
0004 %   y: result
0005 %
0006 %   x: matrix to shift
0007 %   shifts: array of shifts (must be nonnegative)
0008 %
0009 % X is shifted column by column (all shifts of 1st column, then all
0010 % shifts of second column, etc).
0011 %
0012 % X may be 1D, 2D or 3D. See also convmtx.
0013 %
0014 % NoiseTools
0015 
0016 if nargin<2; error('!'); end
0017 
0018 if iscell(x)
0019     for iCell=1:length(x);
0020         z{iCell}=nt_multishift(x{iCell},shifts);
0021     end
0022     return;
0023 end
0024 
0025 if size(x,1)<max(shifts); error('shifts should be no larger than nrows'); end
0026 if min(shifts)<0; error('shifts should be nonnegative'); end
0027 shifts=shifts(:)';
0028 nshifts=numel(shifts);
0029 if nshifts==1 && shifts(1)==0; 
0030     z=x;
0031     return
0032 end
0033 
0034 % array of shift indices
0035 N=size(x,1)-max(shifts); 
0036 shiftarray=nt_vecadd(nt_vecmult(ones(N,nshifts),shifts),(1:N)');
0037 [m,n,o]=size(x);
0038 z=zeros(N,n*nshifts,o);
0039 
0040 for k=1:o
0041     for j=0:n-1
0042         y=x(:,j+1,k);
0043         z(:,j*nshifts+1: j*nshifts+nshifts,k)=y(shiftarray);
0044     end
0045 end
0046

Generated on Tue 27-Nov-2018 11:03:00 by m2html © 2005