xcorr zero lag

Dear all, How can I use xcorr for 0 lags? In the test I'm running I don't want to 'slide' one sequence over another but keep them fixed. Thanks in advance. Happy new year! Diego

댓글 수: 3

Diego
Diego 2012년 1월 1일
This doesn't work
X1=xcorr(P,Q,0, 'coeff');
I need the signals to be superimposed but avoiding the sliding. Does this makes sense at all?
Diego
Diego 2012년 1월 1일
I'm correlating sequences of length 8.
Is this right?
Thanks,
Diego
the cyclist
the cyclist 2012년 1월 1일
I don't have the Signal Processing Toolbox, so I can't check myself, but the syntax in your first comment looks right to me. Can you give a more complete example of the code you have written, the result, and why specifically you believe it to be wrong (or not what you expect)?

댓글을 달려면 로그인하십시오.

답변 (1개)

Wayne King
Wayne King 2012년 1월 1일

0 개 추천

Hi Diego, Why doesn't this work?
[c,lags] = xcorr(randn(1000,1),rand(1000,1),0,'coeff');
This gives you exactly what you have described; the cross correlation between two input vectors at zero lag.
c is the value of the normalized cross correlation sequence at zero lag.

댓글 수: 4

Diego
Diego 2012년 1월 1일
Hi Wayne,
Thanks for your reply.
When I use 0 lags the plotted figures get side by side, not superimposed as when I don't declare the lags.
This is the code of the plot:
delay=d-max(length(P),length(Q));
figure,plot(P);
hold,plot([delay+1:length(P)+delay],Q,'r');
Happy new year!
Diego
Wayne King
Wayne King 2012년 1월 1일
you're not telling me what d means in the above. are P and Q different lengths? If they are, you can't use the 'coeff' option.
Diego
Diego 2012년 1월 1일
ughh I'm so sorry for omitting the information... the code just grows a lot and is a little messy at this time.
P and Q are the same length.
Thanks for your patience!
P=[M(l,i:i+rep-1)];
Q=[M(z,j:j+rep-1)];
[m,d]=max(X1);
Diego
Diego 2012년 1월 3일
It seems the problem was using the 'delay' for plotting.
I just removed it since at 0 lags it seems to be useless and the plot works as expected.
Many thanks,
Diego

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2012년 1월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by