0001 function [xx,yy]=nt_relshift(x,y,shift)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin<3; error('!'); end
0015 if ~isnumeric(x); error('!'); end
0016 if size(x,1)~=size(y,1);
0017
0018 m=min(size(x,1),size(y,1));
0019 x=x(1:m,:,:);
0020 y=y(1:m,:,:);
0021
0022 end
0023
0024 if shift ~= round(shift); error('fractionary shifts not yet implemented'); end
0025
0026 if length(shift)==1
0027 if shift>0
0028 yy=y(1:end-shift,:);
0029 xx=x(shift+1:end,:);
0030 else
0031 yy=y(-shift+1:end,:);
0032 xx=x(1:end+shift,:);
0033 end
0034 else
0035 xx=zeros(size(x,1), size(x,2), length(shift));
0036 yy=zeros(size(y,1), size(y,2), length(shift));
0037 for iShift=1:length(shift)
0038 s=shift(iShift);
0039 if s>0
0040 yy(1:end-s,:,iShift)=y(1:end-s,:);
0041 xx(1:end-s,:,iShift)=x(s+1:end,:);
0042 else
0043 yy(1:end+s,:,iShift)=y(-s+1:end,:);
0044 xx(1:end+s,:,iShift)=x(1:end+s,:);
0045 end
0046 end
0047 end
0048
0049 if 0
0050 x=sin(2*pi*3*(1:1000)'/1000);
0051 y=x;
0052 figure(1); clf;
0053 subplot 131;
0054 [xx,yy]=nt_relshift(x,y,100);
0055 plot([xx,yy])
0056 subplot 132;
0057 [xx,yy]=nt_relshift(x,y,-100:10:100);
0058 plot(squeeze(xx));
0059 subplot 133;
0060 plot(squeeze(yy));
0061 end
0062
0063