miércoles, 25 de abril de 2012

Calculate autocorrelation using FFT in matlab

http://stackoverflow.com/questions/3949324/calculate-autocorrelation-using-fft-in-matlab

Just like you stated, take the fft and multiply by its complex conjugate, then use the inverse fft (or in the case of cross-correlation of two signals: Corr(x,y) <=> FFT(x)FFT(y)*)
x = rand(100,1);
len = length(x);
%# autocorrelation
nfft = 2^nextpow2(2*len-1);
r = ifft( fft(x,nfft) .* conj(fft(x,nfft)) );
%# rearrange and keep values corresponding to lags: -(len-1):+(len-1)
r = [r(end-len+2:end) ; r(1:len)];
%# compare with MATLAB's XCORR output
all( (xcorr(x)-r) < 1e-10 )

No hay comentarios:

Publicar un comentario