signal processing
Show older comments
Hello all, I am still struggling with this and I don't know why its producing wrong answer. I have my two signals and I want to produce the delay time between the two signals and see if they both originate from the same source or not so delay time is not known and the two signals might not be from the same source..I have many source data and I need to do it for any two then calculate the delay time.the problem is that I only get large positive numbers for the delay and if I swap x,y in the xcorr argument I get totally different answer and I believe I should get the same answer as the x,y but opposite sign (minus/positive)...
Thank you all in advance,
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);
3 Comments
Daniel Shub
on 24 Aug 2011
Can your provide a short (maybe length 10 or so) example of sample1 and sample2 in which you do not get what you expect?
Susan
on 24 Aug 2011
Susan
on 24 Aug 2011
Accepted Answer
More Answers (2)
Susan
on 24 Aug 2011
2 Comments
Jan
on 24 Aug 2011
Daniel's code compare the results of XCORR if the inputs are swapped. He shows, that except for the reverted order and some rounding errors, the inputs are equal.
You can be sure that MATLAB is not confused by your source files. It does exactly what you told it to do. It MATLAB does "something else", it recieved different input data. Therefore its answer is not wrong, but your expectations. A general suggestion for such situations is a coffee break.
Susan
on 24 Aug 2011
Jan
on 24 Aug 2011
Did you get the point about FLIPLR?
"I believe I should get the same answer as the x,y but opposite
sign (minus/positive)"
But in addition the replies of xcorr(X,Y) and xcorr(Y,X) are reverted.
4 Comments
Susan
on 24 Aug 2011
Daniel Shub
on 24 Aug 2011
I think my answer answered the question you asked and that this is an unrelated question. Please ask it as a new one so others can follow, contribute, and learn. If you do not think your original question has been answered, please comment in the appropriate answer.
Jan
on 24 Aug 2011
See: "help hold".
If you have a question concerning plotting, it is always a good idea to type "help plot" and look in the "See also:" list at the bottom. This list is created very carefully to assist beginners and advanced MATLAB users.
Susan
on 24 Aug 2011
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!