0
$\begingroup$

I am sorry if I say any thing silly. I have a vector x below and trying to implement correlation with itself (lets say x2) in Simulink, but getting error. I am getting all zeros in result of my output vector. Kindly can some one please help me out in it. Thanks in advance.

ts=1*10^-9;
t=0*10^-9:ts:150*10^-9;
fc=1*10^6;
yi=154*10^-9:ts:2000*10^-9;
y=yi*0;
xi=2*sin(2*pi*fc*t);
x=[xi y];
x2=x;
z=xcorr(x2,x);
$\endgroup$
  • 2
    $\begingroup$ You don't show us what xi is, but y is definitely zero. I would guess that xi is also zero. $\endgroup$ – Matt L. Nov 23 '15 at 11:21
  • $\begingroup$ @MattL. Thanks for your comment.I am so sorry I forgot to add xi its given now.Its not zero. xi=2*sin(2*pifct); $\endgroup$ – Haider Nov 23 '15 at 15:48
2
$\begingroup$

The edited code in your question should not result in an all-zero vector. Of course, since x contains many zeros, the autocorrelation also has many zeros, but it's non-zero in its center portion (i.e., around index $2000$).

Also note that you don't need to define a second identical vector to compute the autocorrelation. You can use the command z = xcorr(x);

| improve this answer | |
$\endgroup$
  • $\begingroup$ L, I really appreciate your comment.My question is how I can save the output argument of Xcorr in Simulink.Which box/fnc I should use in Simulink to save the cross correlation output please.Thanks $\endgroup$ – Haider Nov 24 '15 at 8:55
  • 1
    $\begingroup$ @Haider: You're welcome, but this question is totally different from the one above. Has your original question been answered? If yes, you can accept the answer by clicking the check mark, or ask for clarification in a comment. If you have another question then you can ask it on this site or maybe on stackoverflow if it's only about software. I'm afraid I can't help you with Simulink, only with Matlab and DSP related questions. $\endgroup$ – Matt L. Nov 24 '15 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.