signal processing
显示 更早的评论
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 个评论
Daniel Shub
2011-8-24
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
2011-8-24
Susan
2011-8-24
采纳的回答
更多回答(2 个)
Susan
2011-8-24
2 个评论
Jan
2011-8-24
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
2011-8-24
Jan
2011-8-24
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 个评论
Susan
2011-8-24
Daniel Shub
2011-8-24
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
2011-8-24
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
2011-8-24
类别
在 帮助中心 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!