Correlation of similar Signals

6 views (last 30 days)
Sam Hurrell
Sam Hurrell on 17 Nov 2022
Answered: Mathieu NOE on 18 Nov 2022
I have 2 signals on the same time axis: an ideal signal and the actual signal received. I have used the 'xcorr' function for these signals and produced a graph (as per the MATLAB help centre for xcorr), but I don't understand how this answers how closely correlated these signals are at any given time. What I'd like is to produce a graph of correlation coefficient for both signals across time, rather than an overall value as 'corrcoef'. How can this be done, or should I use the corrcoef function for sections in time rather than overall?

Accepted Answer

Mathieu NOE
Mathieu NOE on 18 Nov 2022
hello
maybe this ?
define a buffer lenth and an overlap (here I took the max possible overlap) and use corrcoef (take the non diagonal term)
% dummy data
n=1000;
t= 1:n;
x = sin(8*pi*t./max(t))+0.1*rand(1,n);
y = sin(8*pi*t./max(t)+0.25)+0.5+0.1*rand(1,n);
mybuffer = 100; % nb of samples in one buffer (buffer size)
overlap = mybuffer-1; % overlap expressed in samples
%%%% main loop %%%%
m = length(x);
shift = mybuffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-mybuffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ mybuffer-1,m);
time_index(ci) = floor((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
M = corrcoef(x(start_index:stop_index),y(start_index:stop_index));
corcoefficient(ci) = M(2,1);
end
t2 = t(time_index);
figure(1),
plot(t,x,t,y,t2,corcoefficient,'-+r');
legend('signal x ','signal y ','cor coefficient');

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by