replacing xcorr x-axis lags with the original axis

9 次查看(过去 30 天)
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
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 个评论
Askic V
Askic V 2022-12-13
编辑:Askic V 2022-12-13
Well, you need to go back to the theory, definition and properties of crosscorrelation. Autocorrelation is basically cross correlation of the two identical signals (signal with itself).
Assuming we're talking about real functions i.e. real time signals then autocorrelation has two important properties:
  1. autocorrelation function R(τ)is an even function of delay parameter (τ)
  2. autocorrelation function has its max value at R(0)
The cross (auto) correlation function must have a duration longer that each of the signals!
To understand why is that, please have a look at the following animation and it should be clear to you:
t = 0:0.1:1;
u = 1*zeros(size(t));
u(t>0.5 & t <0.8)= 1;
nu = length(u)
nu = 11
z = xcorr(u,u);
nz = length(z)
nz = 21
c = xcorr(x,y) returns the cross-correlation sequence in a length 2*N-1 vector, where x and y are length N vectors (N>1). If x and y are not the same length, the shorter vector is zero-padded to the length of the longer vector.
Hussein Kokash
Hussein Kokash 2022-12-15
I will look further into it.
Thanks again for your help, appreciate it!

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by