为什么使用 DFT 进行关联会给出不直观的结果?

发布于 2025-01-02 17:32:16 字数 328 浏览 0 评论 0原文

我试图通过 Matlab 中的 DFT(数字傅里叶变换)使用相关性来比较 2 个信号的相似程度,但相关函数给出的结果并不是真正可预测的。例如,如果我比较这两对信号:

  • 相关性 1 和 2
  • 相关性 3 和 4(自相关)

MATLAB 图截图

我预计“corr 3 和 4”情况下的相关峰值高于“corr 1 和 2”情况下的相关峰值。

我也尝试使信号“平均为零”,但这没有帮助。

这是预期的结果还是我错过了一些预处理等?

I was trying to compare how similar 2 signals using correlation via DFT (Digital Fourier Transform) in Matlab, but the correlation function gives not really predictable results. For example, if I compare those 2 pairs of signals :

  • correlation 1 and 2
  • correlation 3 and 4 (autocorrelation)

MATLAB figure screenshot

I would expect correlation peak in "corr 3 and 4" case higher than in "corr 1 and 2" case.

I as also tried to make signals "average to zero", but this did not help.

Is this the expected result or did I miss some preprocessing, etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2025-01-09 17:32:16

您需要标准化您的数据轨迹 - 即在关联之前将它们除以各自的积分。以下代码演示了当您标准化数据轨迹时,自相关确实为您提供了更大的值:

%# producing your data
trace1=(abs(linspace(-64,64,128))<20)*200;
trace2=trace1-(abs(linspace(-64,64,128))<10)*50;
figure;
subplot(321);
plot(trace1);
subplot(322);
plot(trace2);
subplot(323);
plot(xcorr(trace1,trace2))
title('unnormalized cross-correlation');
subplot(324);
plot(xcorr(trace2,trace2))
title('unnormalized autocorrelation');
%
%# what you should be doing:
subplot(325);
plot(xcorr(trace1/sum(trace1(:)),trace2/sum(trace2(:))))
title('normalized cross-correlation');
subplot(326);
plot(xcorr(trace2/sum(trace2(:)),trace2/sum(trace2(:))))
title('normalized autocorrelation');

导致

figure Screenshot - 使用生成上面的代码

我放大了峰值以显示归一化自相关具有比归一化互相关更高的峰值。

You need to normalize your data traces - i.e. divide them by their respective integrals before correlating. The following code demonstrates that when you normalize your data traces, the autocorrelation indeed gives you the larger value:

%# producing your data
trace1=(abs(linspace(-64,64,128))<20)*200;
trace2=trace1-(abs(linspace(-64,64,128))<10)*50;
figure;
subplot(321);
plot(trace1);
subplot(322);
plot(trace2);
subplot(323);
plot(xcorr(trace1,trace2))
title('unnormalized cross-correlation');
subplot(324);
plot(xcorr(trace2,trace2))
title('unnormalized autocorrelation');
%
%# what you should be doing:
subplot(325);
plot(xcorr(trace1/sum(trace1(:)),trace2/sum(trace2(:))))
title('normalized cross-correlation');
subplot(326);
plot(xcorr(trace2/sum(trace2(:)),trace2/sum(trace2(:))))
title('normalized autocorrelation');

leading to

figure screenshot - produced using the code above

where I zoomed in on the peaks to show the normalized autocorrelation has a higher peak than the normalized cross-correlation.

栖迟 2025-01-09 17:32:16

@Jonas,我无法找到如何插入图像并进行足够好的格式(对不起,这里是新手)评论你的答案,所以我将此评论保留为“答案”。

因此,我发现对于下图,您的方法给出了预期的结果:

在此处输入图像描述

如您所见 - 峰值自相关低于互相关。
我使用的代码如下:

trace1=(abs(linspace(-64,64,128))<20)*200;
trace2=trace1-(abs(linspace(-64,64,128))<10)*50;
trace1=trace1-(abs(linspace(-64,64,128))<10)*100;

subplot(321);
plot(trace1); grid on;
subplot(322); 
plot(trace2); grid on;
subplot(323);
plot(xcorr(trace1,trace2)); grid on;
title('unnormalized cross-correlation');
subplot(324);
plot(xcorr(trace2,trace2)); grid on;
title('unnormalized autocorrelation');

subplot(325);
plot(xcorr(trace1/sum(trace1(:)),trace2/sum(trace2(:)))); grid on;
title('normalized cross-correlation');
subplot(326);
plot(xcorr(trace2/sum(trace2(:)),trace2/sum(trace2(:)))); grid on;
title('normalized autocorrelation');

@Jonas, I was unable to find how to insert image and make good enough formatting (sorry, novice here) commenting your answer, so I am leaving this comment as "answer".

So, what I found that for following figures your method giving not expected results:

enter image description here

as you see - peak for auto-correlation is lower than for cross correlation.
Code which I used is below:

trace1=(abs(linspace(-64,64,128))<20)*200;
trace2=trace1-(abs(linspace(-64,64,128))<10)*50;
trace1=trace1-(abs(linspace(-64,64,128))<10)*100;

subplot(321);
plot(trace1); grid on;
subplot(322); 
plot(trace2); grid on;
subplot(323);
plot(xcorr(trace1,trace2)); grid on;
title('unnormalized cross-correlation');
subplot(324);
plot(xcorr(trace2,trace2)); grid on;
title('unnormalized autocorrelation');

subplot(325);
plot(xcorr(trace1/sum(trace1(:)),trace2/sum(trace2(:)))); grid on;
title('normalized cross-correlation');
subplot(326);
plot(xcorr(trace2/sum(trace2(:)),trace2/sum(trace2(:)))); grid on;
title('normalized autocorrelation');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文