How to know which Signal is delayed !

3 次查看(过去 30 天)
Susan
Susan 2011-8-22
Dear all, I have my code below for real data samples. I already tested the xcorr delay calculation method with different data and it produced the right answer but with the real data, I am not sure how to know after calculating the delay which of the two signal is the delayed version of the other?
x = sample1(:,1);
X = (x).';
y = sample2(:,1);
Y = (y).';
figure;
clf
subplot(3,1,1);
[xi,f]=ksdensity(X);
plot(f,xi);
line(repmat(X,2,1),repmat([0;0.1*max(xi)],1,length(X)),'color','r' );
subplot(3,1,2);
[xi,f]=ksdensity(Y);
plot(f,xi);
line(repmat(Y,2,1),repmat([0;0.1*max(xi)],1,length(Y)),'color','r' );
[Rxx,lags] = xcorr(X,Y);
[Z,delay] = max(Rxx);
lags(delay);

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-8-22
Susan, Others don't have your data sample1 and sample2 so won't be able to look at your data. Would the sign of lags(delay), be positive or negative, tell you whether Y is the delay of X, or X is the delay of Y?
y is 10 steps lag behind x, when running
[Rxx, lags] = xcorr(x, y);
[Y, I] = max(Rxx);
lags(I)
It returns -10, meaning y is 10 steps lag behind x
If you run
[Rxx, lags] = xcorr(y, x);%switch order of x and y
[Y, I] = max(Rxx);
lags(I)
It returns 10, meaning x is 10 steps ahead of y
  4 个评论
Fangjun Jiang
Fangjun Jiang 2011-8-23
You could visually inspect your data to get a sense whether the result is in the ballpark.
Susan
Susan 2011-8-23
It would not be accurate but the fact that swapping both x,y gives different results I think its a sign the delay calculated is not right.. Any idea where I am going wrong?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by