How to know which Signal is delayed !

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);

Risposte (1)

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 Commenti

Susan
Susan il 22 Ago 2011
Yeah I thought the sign should tell me but the fact that for all my sample data I had a large positive number made me not very confident of the way I've done things, however the code works with artificial data so I suppose the methods works. Is there a chance that even though the methods works with artificial data(data we know the delay) it wouldn't work for a real data or it wont be efficient for it?
Susan
Susan il 22 Ago 2011
I actually tried to swap x,y so to check If I will get negative answer but I got a complete different answer??
You could visually inspect your data to get a sense whether the result is in the ballpark.
Susan
Susan il 23 Ago 2011
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?

Accedi per commentare.

Richiesto:

il 22 Ago 2011

Community Treasure Hunt

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

Start Hunting!

Translated by