MATLAB: How to test for correlation between digital data series

correlation

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

Best Answer

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);
Related Question