Matlab · Simulation · Wireless Communication

Uncoded BPSK Simulation using Matlab

Lets say, you send a text message to your girlfriend saying “Hey there!, would you like to go out for a drink?” In an ideal world, you would prefer that she receives exactly the same message. Now assume that this message is sent using a Binary Phase Shift Keying (BPSK) modulation and it travels through an AWGN channel. The corrupted message is then demodulated at the receiver, information bits are estimated and you would pray that the message is received error free. The system diagram as shown below.


If you compare it with the full system diagram shown in the previous post, you will see that many of the components have been removed. It is because, I want to talk about a very basic set up so that I can lay the foundation for more complex systems. Here I have assumed that

  1. No error correction code
  2. No pulse shaping: for simulation purpose, it is assumed that the received signal \boldsymbol{y}_k is the output of perfectly matched filter
  3. No carrier modulation: as it can be assumed that carrier modulation-demodulation processes cancel each other.
  4. Perfect synchronisation: it also assumed that samples \boldsymbol{y}_k are perfectly synchronised. (almost all of the papers in IEEE make this assumption)

For the simulation of this system, I have assumed that the user knows how to use Matlab. You can download the script from this link and run it in Matlab. If you do not have Matlab, you can download Octave which is free. Now, lets understand key components of the script.

The goal of the simulation of a communication is to obtain a plot of signal to noise ratio (SNR) vs. bit error rate (BER) , where you want to know how the BER varies as you change SNR. Ideally, the BER should decrease as you increase SNR.

Now, let me describe how to simulate a communication system. You need to first create a frame of information bits (a sequence of 1’s and 0’s, infoBits), map these bits to BPSK symbols (a sequence of +1’s and -1’s, infoSymbols), add AWGN noise (noise) with correct scaling and demodulate the corrupted signal (receivedSymbols). Finally, obtain the number of bits in error by comparing infoBits and finalBits. This entire sequence is written inside the “for loop” in the script.

The term correct scaling means that there are two ways in which you can say that the SNR is increasing. First is you keep the signal energy constant and decrease the noise energy or the second is that you increase the signal energy and keep the noise energy constant. In the script, I have used the first approach. So for each frame, the “for loop” runs for each value of SNR and the number of erroneous bits are stored in bitError variable.

You run the above procedure many times, so that you get better averaging, which is why I have put the code in a “while loop” and the stopping criteria for the while loop is that when the minimum of the totalErrors is above a certain threshold mcErrors, terminate the simulation. This is called Monte Carlo simulation.

This is a very simple communication system but the key point to understand is the scaling term sigma and how to calculate it. Lets say the energy of information sequence is \boldsymbol{E_b} and the energy of information symbols is \boldsymbol{E_s}. Then the relationship between \boldsymbol{E_b} and \boldsymbol{E_s} is

\boldsymbol{E_b} = \dfrac{\boldsymbol{E_s}}{\mathrm{log_2(M)}}

where M is the modulation index which is 2 for BPSK. Hence, for BPSK, \boldsymbol{E_b}\boldsymbol{E_s}. If we divide, the above equation by noise power spectral density N_O,

\dfrac{\boldsymbol{E_b}}{N_O} = \dfrac{\boldsymbol{E_s}}{\mathrm{log_2(M)} \cdot N_O}

Lets denote \frac{\boldsymbol{E_b}}{N_O} as SNR and N_O = 2\sigma^2, then we can re-write the equation as


and then finally,


where \boldsymbol{\mathrm{SNR}} is in linear scale (not log). The siumlated BER plot is shown below and compared with the theoretical BER plot obtained using the Q function.


As you can see that the above plot is like a “Waterfall” where the BER decreases (as expected) with increasing SNR. We can also observe that the simulated BER (in Blue) matches the theoretical BER (in Red). The above plot indicates that if the SNR is approx 6.8 dB then we can get 1 bit in error out of every 1000 bits.

The above BER plot is also called a lower bound, as for this AWGN channel and BPSK modulation, we cannot get better performance than this.

The next question is, what happens to our message, if it is passed through different values of SNR? Our original message is Hey there!, would you like to go out for a drink?

If the SNR was 0 dB, the received message would be He{ Th�be!, uould {muli+E`�o gm(mu| foP �!rhfk[

If the SNR was 2 dB, the received message would be H!y there!!would y�u like to0go out fmr a �rink?. It is slightly better.

If the SNR was 5 dB, the received message would be Hey there!, would you like to goout$fo� a drink?.

Finally, if the SNR was 7 dB, the received message would be Hey there!, would you like to go out for a drink?

YAY! So at 7 dB, we receive the message error free, which means that the SNR should be at least 7 dB or more.

Now, let’s have a look at how the received signal looks like. In reality, when you are working on systems, the plot of received signal will tell you a lot about how the system will eventually perform. The figure below shows the scatterplot of the received symbols for different values of SNR. As we can see that as the SNR increases, the separation boundary becomes more clear which in this case is (0,0). As we already know that for BPSK, the quadrature component is 0 and hence the decision boundary is located at 0 on the x-axis (In-phase). For example, at SNR = 0 dB, the symbols are scattered all over the place ranging from -4 to 4. As the SNR increases, e.g. SNR = 10 dB, we can see a very clear separation.


This is it for now. From this script alone, we can derive many statistics and analyse the system in different ways. I hope you enjoyed this post.

One thought on “Uncoded BPSK Simulation using Matlab

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s