Time lag between 2 series: comparing xcorr max with corrcoef with different lags

2 ビュー (過去 30 日間)
I am trying to verify the output from xcorr wrt the lag with the highest correlation with the output from corrcoef with different lags which I adjust manually.
Xcorr gives a lag of 0 for the data below, however computing correlation coefficients with corrcoef for 0 lag vs one lag I get a higher correlation coefficient with one lag.
D=[16.654 16.056 15.424 13.91 12.974 12.765 10.846 10.42 10.009 10.827 10.666 8.946 7.775 6.612 ]
E=[64.714 61.045 55.842 51.799 50.836 53.916 52.721416 50.145 51.987 50.123 40.105 33.848 28.467 27.504 ]
I wonder if I am missing something and if yes any help or hint to find out what, would be great. Thanks,
Gad
  2 件のコメント
David Goodmanson
David Goodmanson 2017 年 12 月 16 日
Hi Gad,
For corrcoef, how are you working out the lags for D and E? I got the expected results when I tried this.
Gad Outmezguine
Gad Outmezguine 2017 年 12 月 16 日
Hi David, Thank you for taking the time to answer my question. With D and E and no lag I get corrcoef with r = 0.9137. When I use 1 time lag I use the following to check the correlation: E1=[64.714 61.045 55.842 51.799 50.836 53.916 52.721416 50.145 51.987 50.123 40.105 33.848 28.467 ] D1=[ 16.056 15.424 13.91 12.974 12.765 10.846 10.42 10.009 10.827 10.666 8.946 7.775 6.612 ]
and I get r of 0.9137 using corrcoef (D1,E1). If 0 time lag corresponds to the max correlation, I do not expect to have a higher r for corrcoef (D1,E1) than the one I get for corrcoef (D,D). Why I am checking with corrcoef ? because I have never used xcorr or finddelay before and I need to be sure for what I do.

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

採用された回答

Darshan Ramakant Bhat
Darshan Ramakant Bhat 2017 年 12 月 18 日
I am not sure if I understood your question completely. I sense that you are not expecting the higher correlation coefficient value for D1 and E1 since it is having a lag of one. But cross correlation coefficient doesn't completely depend on the value of max correlation. It is normalized by the standard deviation. I see that D1 and E1 will be having one less element than D & E, this might alter the standard deviation, intern correlation coefficient.
Following link gives formula to calculate the cross correlation: http://www.statisticshowto.com/probability-and-statistics/correlation-coefficient-formula/
MATLAB computes the same according to above formula, you can verify it using below script:
n = length(D1);
numerator =n*(sum(D1.*E1))-(sum(D1)*sum(E1));
denom = sqrt((n*sum(D1.^2)-(sum(D1))^2)-(n*sum(E1.^2)-(sum(E1))^2))
r = numerator/denom

その他の回答 (0 件)

カテゴリ

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