フィルターのクリア

Determine time lag from xcorr?

28 ビュー (過去 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 Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by