필터 지우기
필터 지우기

Cross Correlation between two ramp signals

조회 수: 3 (최근 30일)
James Greer
James Greer 2016년 4월 1일
답변: Harsh Kumar 2023년 7월 9일
Hello all,
Perhaps I have misunderstood how cross correlation works, nonetheless here is my problem:
I have two ramp signals, A and B, each have a slope of 1, A begins at time 0, and B begins 5 seconds later. I am using xcorr to correlate the two signals in order to find the lag. However, xcorr returns a graph which would indicate a lag of 0 time steps.
Does anyone know why this is?

답변 (1개)

Harsh Kumar
Harsh Kumar 2023년 7월 9일
Hi James ,
I understand that you are trying to calculate the Lag between two signals using 'xcorr' function.
You are getting '0' in result as you might be computing the lag at the maximam correlation point which is true indeed because the two signal are aligned perfectly at that point as can be seen from the attached graph as well.
Refer the code snippet and graph of 'correlation' vs 'Lag' to check that shows that lag is 0 when cross-correlation is maximam.
Also refer to the given documentaion for details :Documentation
% Define the time vector
t = 0:0.1:10;
% Define the ramp signals
A = t;
B = zeros(size(t));
B(t >= 5) = t(t >= 5) - 5;
% Perform cross-correlation
[R, lag] = xcorr(A, B);
% Plot the cross-correlation result
figure
stem(lag, R)
title('Cross-correlation between A and B')
xlabel('Lag')
ylabel('Correlation')
% Find the lag corresponding to the maximum correlation
[maxCorr, maxIdx] = max(R);
lagAtMaxCorr = lag(maxIdx);
disp(['The lag with maximum correlation is ', num2str(lagAtMaxCorr), ' time units.']);
The lag with maximum correlation is 0 time units.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by