필터 지우기
필터 지우기

Determine time lag from xcorr?

조회 수: 27 (최근 30일)
Alba Peris
Alba Peris 2022년 7월 16일
답변: Chunru 2022년 7월 17일
Hello everyone,
I am still trying to interpret the lag/timings of my own data.
My two vectors e.g A and B are both of length 26, since each data point corresponds to my time vector (in seconds)[0.18:0.01:0.43] also containing a total of 26 time points.
If conducting xcorr(A,B) gives me a peak R correlation at a lag e.g 8, then would my actual lag in the timeseries in seconds be 8*0.01 i.e a lag of 80 ms?
Thank you very much!

답변 (2개)

Chunru
Chunru 2022년 7월 16일
doc xcorr for details.
[r,lags] = xcorr(___)
% Find the peak or r
[pk, idx] = max(r); % for example
lags(idx)/fs % time lag in sec
  댓글 수: 1
Alba Peris
Alba Peris 2022년 7월 16일
If, for example, my data is as following:
clearvars; close all; clc
time = [0.18:0.01:0.43]; %my time vector in seconds i.e every time I have taken a data sample
%and obtained a corresponding value stored in vectors A and B.
n =1:26;
A = 0.84.^n;
B = circshift(A,5);
[c,lags] = xcorr(A,B);
figure; stem(lags,c)
[pk, idx] = max(c);
timelag = lags(idx); %My lag is -5
Would now my lag in seconds be -5*0.01 = 0.05 seconds?
I understand my fs for my vector time is 100 in the example I have given?
Sorry for the confusion. Thank you very much.

댓글을 달려면 로그인하십시오.


Chunru
Chunru 2022년 7월 17일
circshift with a positive shift number is to delay the signal A to form B.
Now exeamine the defination of xcorr in MATLAB:
Rxy(m)=E{x(n+m)y'(n)}=E{x(n)'y(nm)},
If the second signal y=B (or m is negative) is advanced, then it match with the first signal. So the tag at peak is negative.
clearvars; close all; clc
time = [0.18:0.01:0.43]; %my time vector in seconds i.e every time I have taken a data sample
%and obtained a corresponding value stored in vectors A and B.
n =1:26;
A = 0.84.^n;
B = circshift(A,5);
plot(time, A, 'r', time, B, 'b')
figure
[c,lags] = xcorr(A,B);
figure; stem(lags,c)
[pk, idx] = max(c);
timelag = lags(idx) %My lag is -5
timelag = -5

카테고리

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