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,amplitudes)

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)
   amplitudes: row vector of amplitudes to apply to shifted data
 
 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,amplitudes)
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 %   amplitudes: row vector of amplitudes to apply to shifted data
0009 %
0010 % X is shifted column by column (all shifts of 1st column, then all
0011 % shifts of second column, etc).
0012 %
0013 % X may be 1D, 2D or 3D. See also convmtx.
0014 %
0015 % NoiseTools
0016 
0017 if nargin<3; amplitudes=[]; end
0018 if nargin<2; error('!'); end
0019 if size(x,1)<max(shifts); error('shifts should be no larger than nrows'); end
0020 if min(shifts)<0; error('shifts should be nonnegative'); end
0021 shifts=shifts(:)';
0022 nshifts=numel(shifts);
0023 if nshifts==1 && shifts(1)==0; 
0024     if ~isempty(amplitudes); z=x*amplitudes(1); else; z=x; end
0025     return
0026 end
0027 
0028 % array of shift indices
0029 N=size(x,1)-max(shifts); 
0030 shiftarray=nt_vecadd(nt_vecmult(ones(N,nshifts),shifts),(1:N)');
0031 [m,n,o]=size(x);
0032 z=zeros(N,n*nshifts,o);
0033 
0034 if ~isempty(amplitudes)
0035     amplitudes=amplitudes(:)';
0036     if numel(amplitudes)~=numel(shifts); error('amplitudes and shifts should have same numel'); end
0037     for k=1:o
0038         for j=0:n-1
0039             y=x(:,j+1,k);
0040             z(:,j*nshifts+1: j*nshifts+nshifts,k)=nt_vecmult(y(shiftarray),amplitudes);
0041         end
0042     end
0043 else
0044     for k=1:o
0045         for j=0:n-1
0046             y=x(:,j+1,k);
0047             z(:,j*nshifts+1: j*nshifts+nshifts,k)=y(shiftarray);
0048         end
0049     end
0050 end
0051

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