Home > NoiseTools > nt_relshift.m

nt_relshift

PURPOSE ^

[xx,yy]=nt_relshift(x,y,shift,flag) - delay x relative to y

SYNOPSIS ^

function [xx,yy]=nt_relshift(x,y,shift)

DESCRIPTION ^

[xx,yy]=nt_relshift(x,y,shift,flag) - delay x relative to y 

  xx, yy: shifted matrices

  x,y: column matrices to shift
  shift: amount to delay x (can be negative or fractionary)
  
 If shift has multiple values, xx and yy are 3D matrices, one shift per
 page. Shifted data are zero-padded.

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [xx,yy]=nt_relshift(x,y,shift)
0002 %[xx,yy]=nt_relshift(x,y,shift,flag) - delay x relative to y
0003 %
0004 %  xx, yy: shifted matrices
0005 %
0006 %  x,y: column matrices to shift
0007 %  shift: amount to delay x (can be negative or fractionary)
0008 %
0009 % If shift has multiple values, xx and yy are 3D matrices, one shift per
0010 % page. Shifted data are zero-padded.
0011 %
0012 % NoiseTools
0013 
0014 if nargin<3; error('!'); end
0015 if ~isnumeric(x); error('!'); end
0016 if size(x,1)~=size(y,1); 
0017 %    warning(['x and y have different nrows: ', num2str([size(x,1), size(y,1)])]);
0018     m=min(size(x,1),size(y,1));
0019     x=x(1:m,:,:); 
0020     y=y(1:m,:,:);
0021     %error('!');
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

Generated on Mon 14-May-2018 09:45:18 by m2html © 2005