Cross correlation of several rows within a matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hola!
I have a matrix of 10 column, each column has measurements at different times. I have a second matrix also of 10 columns, each consisting of measurements at different times.
I want to carry out cross correlations of every combination within this matrix. Example, xcorr row 1 matrix 1 with row 1 of matrix 2, then row 1 of matrix 1 of row 2 of matrix 2 and so on. I would like correlations and time lag for each and every combination of columns.
I currently do this, but it means I have to do each row seperatly which is very time consuming.
[xc,lags] = xcorr(matrix1(:,1),matrix(:,2));
[~,I] = max(abs(xc));figure;
plot(lags,xc); legend(sprintf('Time delay %d',lags(I))); title('Column 1 matrix 1 xcorr with Column 2 matrix 2')
Gracias todos, Ben :)
0 comentarios
Respuestas (1)
Maneet Kaur Bagga
el 10 de Oct. de 2024
Hi,
As per my understanding you are performing the cross-correlation for each coloumn pair manually for two matrices, for which the "xcorr" function is running separately for each pair of coloumns. This process is time consuming, given the large number of column combinations (10 in each matrix).
Unfortunately, the "xcorr" function cannot be vectorized for multiple column operations to run at once. To reduce the time overhead, instead of plotting each combination in real time you can store the data and plot it after all the computations are completed.
Also, as a possible workaround you can use the "Parallel Computing Toolbox" to parallelize the loops using "parfor" to speed up the cross-correlation computations. Please refer to the following code snippet for better understanding.
parfor i = 1:numColumns
for j = 1:numColumns
[xc, lags] = xcorr(matrix1(:, i), matrix2(:, j));
[~, I] = max(abs(xc));
xcorrResults{i, j} = xc;
lagResults{i, j} = lags;
maxLagResults(i, j) = lags(I);
end
end
Hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!