0001 function z=nt_multishift(x,shifts,amplitudes)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
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