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 advance x, i.e. remove intial samples (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 advance x, i.e. remove intial samples (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 
0016 if iscell(x)
0017     if ~iscell(y); error('!'); end
0018     xx={}; yy={};
0019     for iCell=1:numel(x)
0020         [xx{iCell},yy{iCell}]=nt_relshift(x{iCell},y{iCell},shift);
0021     end
0022     return
0023 end
0024 
0025 if ndims(x)==3;
0026     for iPage=1:size(x,3);
0027         [xx(:,:,iPage),yy(:,:,iPage)]=nt_relshift(x(:,:,iPage),y(:,:,iPage),shift);
0028     end
0029     return;
0030 end
0031 
0032 if ~isnumeric(x); error('!'); end
0033 if size(x,1)~=size(y,1); 
0034 %    warning(['x and y have different nrows: ', num2str([size(x,1), size(y,1)])]);
0035     m=min(size(x,1),size(y,1));
0036     x=x(1:m,:,:); 
0037     y=y(1:m,:,:);
0038     %error('!');
0039 end
0040 
0041 if shift ~= round(shift); error('fractionary shifts not yet implemented'); end
0042 
0043 if length(shift)==1
0044     if shift>0
0045         yy=y(1:end-shift,:);
0046         xx=x(shift+1:end,:);
0047     else
0048         yy=y(-shift+1:end,:);
0049         xx=x(1:end+shift,:);
0050     end   
0051 else
0052     xx=zeros(size(x,1), size(x,2), length(shift));    
0053     yy=zeros(size(y,1), size(y,2), length(shift));
0054     for iShift=1:length(shift)
0055         s=shift(iShift);
0056         if s>0
0057             yy(1:end-s,:,iShift)=y(1:end-s,:);
0058             xx(1:end-s,:,iShift)=x(s+1:end,:);
0059         else
0060             yy(1:end+s,:,iShift)=y(-s+1:end,:);
0061             xx(1:end+s,:,iShift)=x(1:end+s,:);
0062         end   
0063     end
0064 end
0065 
0066 if 0 
0067     x=sin(2*pi*3*(1:1000)'/1000);
0068     y=x;
0069     figure(1); clf;
0070     subplot 131;
0071     [xx,yy]=nt_relshift(x,y,100);
0072     plot([xx,yy])
0073     subplot 132; 
0074     [xx,yy]=nt_relshift(x,y,-100:10:100);
0075     plot(squeeze(xx));
0076     subplot 133; 
0077     plot(squeeze(yy));
0078 end
0079     
0080

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005