plotting xcorr

2 次查看(过去 30 天)
Diego
Diego 2011-12-28
Dear all, I found the following code in one of the posts for plotting the xcorr. I don't understand very well how to handle the plotting, I have to say. The thing is, the second plot is shifted to the left one unit. I can make it fit by adding 1 to the delay, but I think this is not appropriate since the delay between 2 equal sequences should be 0(???). I would appreciate if somebody can explain me how this works and what is the right way to make the 2 sequences fit. Thanks, Diego
MATLAB code
X1=xcorr(seq1,seq2,'coeff');
[m,d]=max(X1);
display(max(X1));
delay=d-max(length(seq1),length(seq2));
display(delay);
figure,plot(seq1);
hold,plot([delay:length(seq2)+delay-1],seq2,'r');
grid on
  1 个评论
Diego
Diego 2011-12-28
Is this ok???
hold,plot([delay+1:length(seq2)+delay],seq2,'r');

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2011-12-28
plot(seq1) is implicitly plot(1:length(seq1), seq1) . And that starts at 1. A delay of 0 should thus start at position 1 if it is to match the first seq1 position, so you should indeed be adding 1 to your [delay:length(seq2)+delay-1]
  1 个评论
Diego
Diego 2011-12-28
Thank you very much Walter.
Best,
Diego

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by