![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1198263/image.png)
Correlation of similar Signals
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sam Hurrell
il 17 Nov 2022
Risposto: Mathieu NOE
il 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?
0 Commenti
Risposta accettata
Mathieu NOE
il 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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1198263/image.png)
% 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');
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!