Explanation for the following code in python [closed]

x=2 *(rand(N) >= 0.5) - 1

Can someone please explain how the above expression corresponds to BPSK signal please?

• Do you know what rand(N) generates? – BlackMath Aug 2 '19 at 7:15
• Rule: General programming questions are off-topic here, but can be asked on Stack Overflow. There's nothing signal processing-wise in this question. – Marcus Müller Aug 5 '19 at 9:06

Deviating from dsp a bit, randn(N) may be function you are looking for (numpy.random.randn(N)). Coming to the question, yes randn will generate N gaussian distributed random values around 0. After that you are slicing (hard-decision) around 0.5 to get 0 or 1. These 0 or 1 will get converted to -1 or 1 (0 $$\rightarrow$$ -1 , 1 $$\rightarrow$$ 1) so you will have BPSK modulated symbols. (Since you chose 0.5 as the cutoff for deciding 0 or 1, this may result in more -1 symbols. You can chose 0 as the cutoff to get 1 or -1 with equal probability)