Home > NoiseTools > nt_whiten.m

# nt_whiten

## PURPOSE

[A,y]=nt_whiten(x,N) - whiten spectrally using pca

## SYNOPSIS

function [A,y]=nt_whiten(x,N)

## DESCRIPTION

    [A,y]=nt_whiten(x,N) - whiten spectrally using pca

      A: whitening matrix (to be applied to time-shifted x)
      y: whitened signal

      x: signal to whiten
      N: order (number of time shifts)

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_multishift z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix
- nt_pcarot [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance

This function is called by:

## SOURCE CODE

    0001 function [A,y]=nt_whiten(x,N)
    0002 %[A,y]=nt_whiten(x,N) - whiten spectrally using pca
    0003 %
    0004 %  A: whitening matrix (to be applied to time-shifted x)
    0005 %  y: whitened signal
    0006 %
    0007 %  x: signal to whiten
    0008 %  N: order (number of time shifts)
    0009 %
    0010
    0011 if nargin<2; error('!'); end
    0012
    0013 % calculate covariance across time shifts, looping over columns to save space
    0014 sz=size(x);
    0015 xx=reshape(x,sz(1),prod(sz(2:end)));
    0016 C=zeros(N); % covariance of time-shifted data
    0017 for iCol=1:size(xx,2);
    0018     xxx=nt_multishift(xx(:,iCol),0:N-1);
    0019     C=C+xxx'*xxx;
    0020 end
    0021 C=C/size(x,1);
    0022
    0023 % PCA, normalize, inverse
    0024 [A,evs]=nt_pcarot(C);
    0025 tmp=1./evs; a(find(evs<=0))=0;
    0026 A=A*diag(tmp)*pinv(A);
    0027
    0028 if nargout>1
    0029     % apply whitening matrix, keeping only 1st column
    0030     yy=zeros(size(xx));
    0031     for iCol=1:size(yy,2)
    0032         xxx=nt_multishift(xx(:,iCol),0:N-1);
    0033         yy(1:size(xxx,1),iCol)=xxx*A(:,1);
    0034     end
    0035     y=reshape(yy,[size(yy,1),sz(2:end)]);
    0036 end
    0037