Can we use xcorr() for continuous signals
8 views (last 30 days)
Show older comments
If we have two continuous signals as below: Then can we use xcorr() to find the correlation between them?
close all; clc; clearvars;
w = [pi/4 pi/4 pi/2]'; % Frequency
P = length(w); % Number of signals
N=10; % Number of data points in the generated signals
S=2*exp(1j*(w*(1:N))); % Three signals generated
x=S(1,:);
y=S(2,:);
[Cxy,F] = mscohere(x,y) % Coherence between x and y signals computed
figure('name', 'Coherence')
plot(F,Cxy)
title('Magnitude-Squared Coherence')
xlabel('Frequency (Hz)')
grid
[r,lags] = xcorr(x,y)
When two signals have different frequenies, they are called Uncorrelated signals.Likewise same frequency signals are called correlated signals.
Similarly when two signals start from same point, then they are coherent signals but if they start from different point, then they are non-coherent signals. In the above command [Cxy,F] = mscohere(x,y)
what is Cxy and what is F. Where is the starting point of the two signals stored here?
Likwise where is the frequency stored in the command [r,lags] = xcorr(x,y) as it finds correlation.
0 Comments
Answers (1)
Omega
on 10 Feb 2025 at 4:42
Edited: Omega
on 10 Feb 2025 at 4:55
Hi Sadiq,
In MATLAB, the "xcorr()" function is generally used for discrete signals rather than continuous ones. However, if you sample your continuous signal, you can use "xcorr()" to find the cross-correlation between them.
Coherence
[Cxy,F] = mscohere(x,y)
Coherence is a frequency-domain measure that shows how well two signals are linearly related at different frequencies, "Cxy" stores the magnitude-squared coherence between signals "x" and "y".
"F" is the vector of frequencies at which the coherence is computed. However, it doesn't directly provide information about the starting points of signals.
Cross-correlation
[r,lags] = xcorr(x,y)
Cross-correlation ("r") can give information about the time delay (lag) between two signals ("x" and "y"), showing their similarity as a function of the lag. "lags" are the time-delays at which the cross-correlation is computed.
While it doesn't directly store starting points or frequencies, you can analyze the cross-correlation sequence (r) and lags to understand the time-domain relationship.
In summary, the starting points of signals are not directly stored in either "mscohere()" or "xcorr()". To determine the starting points of signals, you would need to analyze them separately.
You can learn more about the Coherence and Cross-correlation by going through the following MathWorks documentaion links:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!