from
Coherently aligns data
by Joshua Carmichael
Aligns data according to cross-corr maxima
|
| [y,varargout]=xcorAlign(x) |
function [y,varargout]=xcorAlign(x)
% Aligns data according to cross correlation maximum.
% [y,varargout]=xcorAlign(x,varargin)
%
% USAGE:
% [dataout,lagout]=xcorAlign(data);
%
% If only 1 output is specified, then dataout (a matrix the same size as
% data) is returned.
%
% INPUT:
% data: a matrix of data vectors stored column-wise.
%
% OUTPUT:
% y: A matrix size(data) back.
% lagout: Optional. A vector of lag indices. These give the amount the
% column vectors of dataout are shifted with respect to the first
% column of data.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[M,N]=size(x);
y=x;
lagout=zeros(N,1);
%make infs zeros for computing purpose
x(isinf(x)) = 0;
%align against the first column vector
ftx1 = fft(x(:,2:end));
ftx2 = fft(x(:,1));
for k=2:N
xc = ifft(conj(ftx1(:,k-1)).*ftx2);
[m,i] = max(abs(xc));
y(:,k) = circshift(x(:,k),i);
lagout(k) =i;
end;
%asign output values
if(nargout==2);
varargout{1}=lagout;
end;
|
|
Contact us at files@mathworks.com