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)

## 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)

     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:

- nt_multishift z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix
- nt_vecadd y=nt_vecadd(x,v) - add vector to all rows or columns of matrix
- nt_vecmult y=nt_vecmult(x,v) - multiply all rows or columns of matrix by vector

This function is called by:

- nt_cov [c,tw]=nt_cov(x,shifts,w) - time shift covariance
- nt_multishift z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix
- nt_pca [z,idx]=nt_pca(x,shifts,nkeep,threshold,w) - time-shift pca
- nt_pca_kmeans [topcs,pwr]=nt_pca_kmeans(x,nkeep) - PCA preceded by kmeans for speed
- nt_tsr [y,idx,w]=nt_tsr(x,ref,shifts,wx,wref,keep,thresh) - time-shift regression (TSPCA)
- nt_tsr_nodemean [y,idx,w]=nt_tsr_nodemean(x,ref,shifts,wx,wref,keep,thresh) - time-shift regression (TSPCA)
- nt_tsxcov [c,tw]=nt_tsxcov(x,y,shifts,w) - cross-covariance of X and time-shifted Y
- nt_whiten [A,y]=nt_whiten(x,N) - whiten spectrally using pca
- nt_xcov [c,tw]=nt_xcov(x,y,shifts,w) - cross-covariance of X and time-shifted Y

## SOURCE CODE

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