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!