How do I compute the p-value of the highest r-value from the function [c,lags]=xcorr(A,B)?

12 ビュー (過去 30 日間)
Sammy
Sammy 2023 年 6 月 15 日
コメント済み: Sammy 2023 年 6 月 16 日
When using the [c,lags]=xcorr(A,B) and [r,p]=corrcoef(A,B), the c and r values are different so I can't use both. What I would like to know is the p-value from the max value of c from xcorr. But I need to use xcorr for its lag and maxlag features. Thanks.

回答 (1 件)

Anush
Anush 2023 年 6 月 15 日
Hello Sammy,
To compute the p-value of the highest correlation value obtained from the xcorr() function, you can do the following:
[c, lags] = xcorr(A, B);
maxIndex = find(c == max(c));
maxLag = lags(maxIndex);
% Shift one of the signals by the maxLag
shiftedB = circshift(B, maxLag);
[r, p] = corrcoef(A, shiftedB);
This way you obtain the values of lag, maxlag and p-value from the max value of c from xcorr,
  1 件のコメント
Sammy
Sammy 2023 年 6 月 16 日
Hello, I still couldn't get the max c and r values to match so I can use its corresponding p-value. I think the code could also improve if you place an absolute value of c because there are times when it's value is nearest to negative 1. So...
maxIndex = find(c == max(c));
Thanks for the info by the way. (:

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

カテゴリ

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