How can I use ‘randi’ function in MATLAB to generate a signal sequence s(t) which contains 1e6 samples which are either 0 or 1 and are equally probable. Any suggestions? Thanks!
1 Answer
Generate random integer uniformly distributed between 1 or 2. Then you can shift it to your liking.
X=randi(2,size,1)-1
-
$\begingroup$ Thanks for the answer! So I replace size with 1e6 and that would generate equally probable samples between 1 and 2? So, what about 0 and 1? $\endgroup$ Apr 17, 2021 at 16:32
-
1
-
$\begingroup$ Uhh Shoot missed that completely! I see! Thanks a lot for the help! $\endgroup$ Apr 17, 2021 at 16:34
-
1$\begingroup$ At first you generate a vector of your size of ones and twos then you shift it $\endgroup$ Apr 17, 2021 at 16:34
-
1$\begingroup$ You could do it much simpler (Directly) by
randi([0, 1], numSamples, 1);
. $\endgroup$– RoyiApr 24, 2021 at 11:51
X
toY
, how can you convert them to numbers in the rangeX+Z
toY+Z
? $\endgroup$x = rand(n,1) > 0.5;
would do it. $\endgroup$randi([0, 1], numSamples, 1);
. $\endgroup$