This blog is my second blog about digital communication system simulation. In this blog, I will simulate a QPSK uncoded communication system (AWGN channel) with Matlab. I try to do it step by step following the Monte Carlo method.
1 | Algorithm: MonteCarloSimulation |
Steps of the simulation
GenerateRandomBits
It is straightforward to generate random bits with Matlab with the function randi, which can generate uniformly distributed random integers. Here I use the row vector form to represent the information bits.
1 | transmittedBits = randi([0, 1], 1, numBitsPerBlock); |
ModulateData
In this step, we need to map the information bits to the QPSK signal. The details of QPSK can be found in the previous blog.
1 | % QPSK Modulator |
SimulateChannel
Here we need to simulate the complex AWGN channel. The mathematical model is easy to understand but there are some details to be careful in the implementation.
$$
\text{SNR}, \text{signalPower} \to N_0 \to \text{receivedSignal}
$$
In order to make the awgn channel general for both normalized and non-normalized signal power, we need to calculate the signal power first. Then we can calculate the noise power spectral density $N_0$ from the SNR (linear scale) and the average signal power. After that, we need to generate the complex Gaussian noise with the variance of $\sqrt{\frac{N_0}{2}}$ and add it to the transmitted signal to get the received signal.
1 | function receivedSignal = add_awgn_noise(transmittedSymbols, signalToNoiseRatioDb) |
DemodulateSignal
For QPSK, the demodulation is very simple. We just need to check the real and imaginary parts of the received signal and make a decision.
1 | % QPSK Demodulator |
CountErrors
This is the core part of the Monte Carlo method. In the Monte Carlo iteration while loop, we need to count the number of errors by comparing the information bits and the detected (demodulated) bits in a block-by-block manner.
If the accumulated errors is enough for our simulation or we have processed enough blocks, we can stop the iteration and calculate the final simulated Bit Error Rate (BER).
Remark: By using Monte Carlo method, we can get the average BER of our communication system. The results is of statistical confidence if we have enough error events and trials.
1 | % ...inside the Monte Carlo iteration loop... |
Theoretical BER
We want to validate our simulated results with the theoretical BER of QPSK. The theoretical BER of QPSK in AWGN channel is given by:
$$
P_e = Q\left(\sqrt{\frac{2E_b}{N_0}}\right)
$$
Remark: The BER is related the specific labelling scheme of the QPSK constellation. This BER is for the Gray-labelling scheme. For detailed derivation, please refer to Proakis’s book Chapter 4.3.
In Matlab, we can use the function qfunc to denote the Q-function. The Theoretical BER is calculated as follows:
1 | % Theoretical Performance Bound |
Remember that when we calculate the theoretical BER, we need to convert the EbN0 from dB to linear. But for plotting, we can use the dB scale for better visibility.
Plot Results
I personally think that a carefully designed plot is the most powerful way to visualize the simulation results. Here I use the semilogy function to plot the BER vs Eb/N0 in Figure 1.
1 | % Performance Visualization |
Remark: You can find the complete code in this Github repository.
The final BER plot (simulated v.s. theoretical) is shown as follows:
Remark: The simulation results are consistent with the theoretical bound. The Monte Carlo simulation is accurate and reliable.