Can we use xcorr() for continuous signals

조회 수: 8 (최근 30일)
Sadiq Akbar
Sadiq Akbar 2021년 5월 24일
편집: Omega 2025년 2월 10일 4:55
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.

답변 (1개)

Omega
Omega 2025년 2월 10일 4:42
편집: Omega 2025년 2월 10일 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:

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by