Strange results with xcorr

31 ビュー (過去 30 日間)
Guilherme T Silva
Guilherme T Silva 2016 年 10 月 13 日
コメント済み: Michael King 2019 年 3 月 1 日
Hi,
I'm running the following script to calculate the cross-correlation between two signals:
s1 = sig.signals.values(:,1,5);
s2 = ref.signals.values(:,1,5);
C = xcorr(s1,s2);
figure; subplot(2,1,1); plot([s1 s2]); subplot(2,1,2); plot(C);
Unfortunately, instead of the expected result I get maximum cross-correlation on the frame size (1024 samples), like shown in the figure:
Any clue on what's going on?
Thanks, Guilherme
  1 件のコメント
Michael King
Michael King 2019 年 3 月 1 日
Did you ever find a suitable solition to your question? I have found that detrending with the detrend function did not help with the issue you presented above that I was also having.
Michael

サインインしてコメントする。

回答 (3 件)

Erick Oberstar
Erick Oberstar 2018 年 7 月 25 日
XCORR wants zero mean inputs - remove the DC offset and I suspect your results will be more inline with what you expect. You may also try passing in the 'unbiased' flag
  3 件のコメント
ES_Thorny
ES_Thorny 2018 年 12 月 6 日
I have a similar problem.
I have to compute the cross-correlation between two transient signals with non-zero mean. As they represent transient phenomena, it doesn't make sense to me to subtract the mean value The objective is to compute the time delay between the maximum of the two signals. The signals are not exactly correlated-similar, but I guess this is always the case ...
If i try to compute the time delay using XCORR, I get close results to what I expect (i.e the time delay checked visually by checking where the maximum of the two signals are) only using the UNBIASED options.
Why is that? Does the unbiased routine subtract the mean values from both my signals?
Please let me know what you think.
Regards,
E
Michael King
Michael King 2019 年 3 月 1 日
Did you find a suitable solution to your question? I have the same issue that Guilherme T Silva posted on 14 Oct 2016. And I have tried to use the detrend function without success, which I think was suggested by Erick Oberstar on 25 Jul 2018 and Pistachio on 14 Nov 2018

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 10 月 13 日
I'm not sure what you were expecting. It looks reasonable to me. What were you expecting? As the signals slide past, they first start to overlaps at -1/2 the frame width, then the overlap gets more and more until they completely overlap, at a shift of the frame width, then the start to separate and the sum of the products decreases until they finally completely separate at 1.5 times the frame width. Then, since MATLAB can't have negative indexes, the shift of -1/2 the frame width will show up at index 1, and the correlation at a shift of 1.5 times the frame width will happen at twice the frame width. Were you expecting something different? Like you wanted to see ripples on the triangle or didn't expect to even see a triangle at all? Please explain what is strange to you.
  2 件のコメント
Guilherme T Silva
Guilherme T Silva 2016 年 10 月 14 日
I was expecting to see a peak around 35, which is the number of samples one signal appears to be lagged from the other. My main goal is to detect this number.
Image Analyst
Image Analyst 2016 年 10 月 14 日
Try subtracting off the mean before you correlate. The problem is that your signal is on huge offsets, so essentially you're practically convolving two very tall step (rect) functions. And as you know, the convolution (correlation) of two rect functions is a triangle. That's like the first thing they teach when they teach convolution to you.

サインインしてコメントする。


Honglei Chen
Honglei Chen 2016 年 10 月 14 日
You may want to get the lags from xcorr too so you can plot the correlation over lags.
[C,lags] = xcorr(s1,s2);
plot(lags, C)
HTH

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by