![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/272763/image.png)
Cross-correlation questions
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cside
el 20 de Feb. de 2020
Comentada: Adam Danz
el 20 de Feb. de 2020
Hi, I have 2 spike trains and would like to use cross-correlation to find out their time lag. Are there any resources out there that may guide me on cross correlation and explain how to further interpret the results into smt useful? Also, I have a few questions.
1) why is it that there is still a peak r value with 2 spike trains that are not correlated?
2) Do I have to normalize the spike train?
3) xcorr gives me the r and lag value. But how may I utilize this information to make it useful? ie is it significant?
4) why is it that a xcorr value (i input what mathworks suggested xcorr(x,y), returns me a correlation sequence) can be >1/-1? shouldnt a r value be bounded within that range?
Thank you and i appreciate any help for a beginner here :)
0 comentarios
Respuesta aceptada
Adam Danz
el 20 de Feb. de 2020
Editada: Adam Danz
el 20 de Feb. de 2020
Perhaps working through one of the examples in the xcorr documentation would be helpful.
1) why is it that there is still a peak r value with 2 spike trains that are not correlated?
You can cross correlate any two vectors and there will be a maximum correlation at some time point (unless both vectors are flat).
Produce this plot, for example.
theta = linspace(0,2*pi,100);
x1 = sin(theta);
x2 = sin(1.2*theta);
[r, lags] = xcorr(x1,x2);
clf()
tiledlayout(2,1)
nexttile
hold on
plot(theta, x1, 'DisplayName', 'x1')
plot(theta, x2, 'DisplayName', 'x2')
legend()
nexttile
plot(lags,r, 'ks')
grid on
xlabel('lag')
ylabel('cross-corr')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/272763/image.png)
2) Do I have to normalize the spike train?
You don't have to but it might be a good idea to normalize the amplitudes, especially if you're comparing responses from two different sources (ie, two different neurons). I also advise you to look at the literature from your field to see the common approach taken.
3) xcorr gives me the r and lag value. But how may I utilize this information to make it useful? ie is it significant?
After you get the lag, use circshift to circularly shift the 2nd vector so that it aligns to the first vector at the maximum correlation. Plot out the shifted data so you can visually confirm that the shift was done correctly. Then use [rho,pval] = corr(X,Y) to compute the correlation and the corresponding p-value for the shifted vectors.
3 comentarios
Adam Danz
el 20 de Feb. de 2020
Editada: Adam Danz
el 20 de Feb. de 2020
Yes, you can use corrcoef, but if you're going to compare the results between xcorr and corrcoef, you'll need to understand how the two functions differ. David Goodmanson explains it well here:
Adam Danz
el 20 de Feb. de 2020
I also want to add that circularly shifting the data is useful if you're dealing with circular data. You might just need a linear shift of the data which would likely result in left and right components of the data that aren't paired due to the shift.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!