在Matlab中使用FFT计算自相关 [英] Calculate autocorrelation using FFT in Matlab

查看:742
本文介绍了在Matlab中使用FFT计算自相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些有关如何使用信号的fft,将实部乘以复共轭(傅立叶域),然后使用逆fft可以更有效地计算自相关的一些解释,但是我在实现时遇到了麻烦这是在Matlab中进行的,因为在详细级别上.

I've read some explanations of how autocorrelation can be more efficiently calculated using the fft of a signal, multiplying the real part by the complex conjugate (Fourier domain), then using the inverse fft, but I'm having trouble realizing this in Matlab because at a detailed level.

推荐答案

就像您说的那样,取fft并逐点乘以其复共轭,然后使用反fft(或者在两个信号互相关的情况下) :Corr(x,y) <=> FFT(x)FFT(y)*)

Just like you stated, take the fft and multiply pointwise 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 )

实际上,如果您看一下xcorr.m的代码,这就是它的作用(只是它必须处理填充,规范化,向量/矩阵输入等的所有情况)

In fact, if you look at the code of xcorr.m, that's exactly what it's doing (only it has to deal with all the cases of padding, normalizing, vector/matrix input, etc...)

这篇关于在Matlab中使用FFT计算自相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆