フィルターのクリア

How do I test for correlation between digital data series?

2 ビュー (過去 30 日間)
Chris
Chris 2013 年 12 月 4 日
編集済み: Wayne King 2013 年 12 月 5 日
This may be a dumb question. I have two digital data series:
a = [-1 1 -1 -1 -1 1 1 -1 -1 -1 1 1]; b = [1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1];
What's the best way to determine whether they are correlated? Corr? Chi-square? If chi-square, how exactly (there are several functions)?
Thanks

採用された回答

Wayne King
Wayne King 2013 年 12 月 5 日
編集済み: Wayne King 2013 年 12 月 5 日
xcorr() is in the Signal Processing Toolbox. You can calculate the cross correlation in the frequency domain and then invert.
a = [-1 1 -1 -1 -1 1 1 -1 -1 -1 1 1];
b = [1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1];
npad = length(a)+length(b)-1;
crosspec = fft(a,npad).*conj(fft(b,npad));
xcr = fftshift(ifft(crosspec));
anorm = norm(a,2)^2;
bnorm = norm(b,2)^2;
xcr = xcr./sqrt(anorm*bnorm);
lags = -length(a)+1:length(a)-1;
stem(lags,xcr,'markerfacecolor',[0 0 1])
Or you can use corrcoef() -- again this is not the best for time series.
R = corrcoef(a,b);

その他の回答 (1 件)

Wayne King
Wayne King 2013 年 12 月 4 日
編集済み: Wayne King 2013 年 12 月 4 日
The best way is to compute the cross correlation sequence.
The reason you want to do that is with time series data, you want to account for the fact that the two series may differ only by a shift.
a = [-1 1 -1 -1 -1 1 1 -1 -1 -1 1 1]; b = [1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1];
[c,lags] = xcorr(a,b,'coeff');
stem(lags,c)
Look at some of the "Examples and How Tos" here
  1 件のコメント
Chris
Chris 2013 年 12 月 4 日
I get an error when I run that: "Undefined function 'xcorr' for input arguments of type 'char'." Still get an error even if I convert a & b to logicals.
Also, in my case there is no concern about a time shift, does that mean I can use some other method to test for correlation?

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

カテゴリ

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