# replacing xcorr x-axis lags with the original axis

조회 수: 5(최근 30일)
Hussein Kokash 2022년 12월 12일
댓글: Hussein Kokash 2022년 12월 15일
Hello all,
Below is a plot of my (x,y) values and xcorr results:
data = dlmread('data.txt');
x = data(:,1);
y = data(:,2);
[Rx, lags] = xcorr(y);
subplot(2,1,1); plot(z, y, 'linewidth',1);
subplot(2,1,2); plot(lags, Rx, 'linewidth',1);
The results of xcorr shows a lags from -100 to 100.
Is there a way that I can use xcorr in such a way that the results of x-axis would span the same length as the original X values (x = data(:,1))?
(from 0 to 0.2)
I am interseted in getting the two-point correlation of the y values.
Note: I have attached the data file.
Thank you!

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

### 채택된 답변

Askic V 2022년 12월 13일
편집: Askic V 2022년 12월 13일
Is this something you search for?
data = dlmread('data.txt');
x = data(:,1);
y = data(:,2);
% Find dT i.e. step size
dt = (x(end)-x(1))/numel(x); % same as dt = x(2)-x(1)
[Rx, lags] = xcorr(y);
subplot(2,1,1); plot(x, y, 'linewidth',1);
subplot(2,1,2); plot(dt*lags, Rx, 'linewidth',1);
% if only t >0 is interesting (plot is symmetric)
figure; % new figure
time_t = dt*lags;
ind = time_t >= 0;
subplot(2,1,1); plot(x, y, 'linewidth',1);
subplot(2,1,2); plot(time_t(ind), Rx(ind), 'linewidth',1)
##### 댓글 수: 3표시 이전 댓글 수: 2숨기기 이전 댓글 수: 2
Hussein Kokash 2022년 12월 15일
I will look further into it.
Thanks again for your help, appreciate it!

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

### 범주

Find more on Correlation and Convolution in Help Center and File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by