Cross-correlation plots and find the median

2 views (last 30 days)
Chi Pham
Chi Pham on 30 Oct 2019
Answered: Subhadeep Koley on 4 Nov 2019
I have 2 sets of data and I want to find the cross-correlation between them and plot it out. I want to first plot each of the trace and then find the median cross-correlation. However, I have not been able to do so. Here is my code.
figure
for i=1:26
subplot(3,9,i)
[c,lags] = xcorr(dataA(i), dataB(i));
stem(lags,c)
xlabel('lag')
ylabel('Cross-correlation')
end

Answers (1)

Subhadeep Koley
Subhadeep Koley on 4 Nov 2019
I assume that you are trying to find the median value for each of the cross-correlation vector and plot them along with the cross-correlation plot. The below code might help.
clear;clc;close all;
load data.mat
figure('units','normalized','outerposition',[0 0 1 1])
for i=1:26
subplot(3,9,i)
[c,lags] = xcorr(cell2mat(dataA(i)), cell2mat(dataB(i)));
c_median = median(c); % Finding the median correlation
stem(lags,c);
hold on;
plot(c_median,'ro','MarkerSize',8,'MarkerFaceColor','red')
xlabel('lag')
ylabel('Cross-correlation')
legend('Correlation','Median')
end
corr_median.png

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!