Why is xcorr getting this very simple case "wrong"?

4 ビュー (過去 30 日間)
Mitch Hezel
Mitch Hezel 2021 年 2 月 11 日
コメント済み: the cyclist 2021 年 9 月 12 日
I'm sure it's just me, but I have
a = [1 2 3 4 5 4 3 2 1];
b = [0 1 2 3 4 5 4 3 2];
[c,lags] = xcorr(detrend(a,0), detrend(b,0), 'normalized');
Then i try
lags(c == max(c))
%ans 0
Why doesn't xcorr believe the lag should be 1 sample?

採用された回答

the cyclist
the cyclist 2021 年 2 月 12 日
I didn't figure this out with certainty, but if you take a look at the "More About" section of the documentation for xcorr, it mentions that xcorr can only approximate the true cross-correlation if an infinite-length signal, due to the finite length of the input vector. So, I think what is happening is that the end effects are overwhelming the "true" lag result.
I confirmed this by using
a = repmat(a,5,1);
b = repmat(b,5,1);
to get more extended signal, and you do see the lag=-1 dominate.
FYI, using
stem(lags,c)
is a good way to visualize the results.
  2 件のコメント
Adib Yusof
Adib Yusof 2021 年 9 月 12 日
Thank you @the cyclist for the insight. Did you actually mean
a = repmat(a,1,5);
b = repmat(b,1,5);
to get horizontally extended signal? Thanks!
the cyclist
the cyclist 2021 年 9 月 12 日
Yes I did.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by