Time lag between 2 series: comparing xcorr max with corrcoef with different lags
3 次查看(过去 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
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.
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!