MATLAB's crosscorr function and R Studio ccf show different results
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I'm using MATLAB's crosscorr function and R Studio's ccf. For the same data, the results differ. It appears that the lag axis is flipped in one of them.
I've reproduced the crosscorr documentation example in both and this is what I see. The data is in the attached .txt file.
vs R Studio
Why is this happening? Thanks.
2 comentarios
Bjorn Gustavsson
el 14 de Dic. de 2020
They "simply" seems to be flipped. That most likely is because they define the lags in opposite direction. If that's the case you should find the information somewhere in the documentation.
Respuestas (1)
Bjorn Gustavsson
el 15 de Dic. de 2020
If you cannot find the information in the documentation, you'll have to go to the source. This is what I find in the xcorr function:
X = fft(x,m2,1);
Y = fft(y,m2,1);
if isreal(x) && isreal(y)
c1 = ifft(X.*conj(Y),[],1,'symmetric');
else
c1 = ifft(X.*conj(Y),[],1);
end
% Keep only the lags we want and move negative lags before positive
% lags.
c = [c1(m2 - mxl + (1:mxl)); c1(1:mxl+1)];
How that differs from the R-implementation I cannot tell. (But without any thinking) This looks like an fft-based convolution between x and y. Exactly which way around to go here requires attention to detail, but you can compare this with the R-version, and check which is what with the wikipedia-description: Cross-correlation.
HTH
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!