Please someone help me check my code?..Thanks

1 次查看(过去 30 天)
e
for i=1:10000
dW = sqrt(var)*((randn(1,N)));
phi= [0,cumsum(dW)];
phi_t=2*pi*phi;
c_t=exp(j*phi_t);
phi_nTs_cum=phi_t(1:64);
c_t_sampled=exp(j*phi_nTs_cum);
end.
This was what i implemented could you check if i am correct.i just want 64 samples of phi_t every symbol duration after every loop.i am sceptical because i did not use the symbol duration in my code.please help?

采纳的回答

Image Analyst
Image Analyst 2014-3-28
Yes, lots of problems. First off, the "e" line will throw an exception if e has not been defined. Next, it's badly indented. Then, the period after the "end" will cause a syntax error. Then you used var in a bad way. Either you previously declared your own var, and didn't show us, thus destroying the built in var() function, or you're calling the built-in var() function with no arguments. Both are very bad.
This looks like some kind of a Monte Carlo experiment where you're running 10,000 experiments generating N random numbers each time. The whole thing could be vectorized and the for loop eliminated just by getting a 2D array of random numbers right at the start. But if you don't, you don't have any indexes on the values you calculate in the loop so they're just being overwritten every time, so what's the point of that? Try phi_t(i) instead of just plain phi_t.
Finally, don't use i (the imaginary variable) as a loop index. Use k or experiment or something else, preferably descriptive, instead of i.
  4 个评论
Emmanuel
Emmanuel 2014-3-28
This is very helpful.Thanks a million!,by the way var represents the variance of the random Gaussian signal with zero mean.
Image Analyst
Image Analyst 2014-3-28
You're welcome. I didn't know what you wanted j to be. If you want it to be the imaginary variable, assign it to sqrt(-1) instead of 5 like I did, and then you can plot the real and imaginary parts of c_t_sampled separately.

请先登录,再进行评论。

更多回答(0 个)

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by