How to simulate a simple NOMA system (AWGN) using MATLAB?
Simulation of BER of Non orthogonal multiple access (NOMA) in AWGN channel - MATLAB code with explanation
You can download the MATLAB code directly here.
In the previous two posts, we took a toy example to understand the concept of NOMA and to prove to ourselves that NOMA indeed works as expected. As we said before, NOMA uses superposition coding at the transmitter end and successive interference cancellation at the receiver end.
In this post, we will see how to simulate a simple two user NOMA system using MATLAB. We will be plotting the BER performance of NOMA in an additive white gaussian noise (AWGN) channel. The AWGN assumption here is made to keep things simple so that we can pay more attention to the actual skeleton of NOMA implementation. We will improve on this model and do the similar exercise over a Rayleigh fading channel in the next post. The MATLAB code used in this example is available for download here.
See this post on How to do power allocation in NOMA?
Assumptions
Here are the assumptions we are going to make:
- Let us do downlink transmission from base station (BS) to two users.
- We are not using any path loss models and we assume that both users are located at equal distances from the BS.
- We are assuming an AWGN channel
- We are going to use BPSK modulation for both users
- Since we are using BPSK, we are going to consider only the in-phase/real component of complex AWGN.
A few pointers about these assumptions: (i) In real time systems, NOMA performs better when one of the users is closer to the BS (also called the near/strong user) and the other user is far away (far/weak user). But in our case, for the sake of simplicity, let's assume users are equidistant from the base station. We will see that NOMA works even under this assumption. (ii) The AWGN assumption is not valid in real time applications. The wireless channel is more complicated due to multipath propagation and fading. We will see how to simulate NOMA for Rayleigh fading channel in a later post. (iii) It is also possible to use different modulation schemes for different users.
System Model
Our network will look like this:
We have a base station (BS) at the center. It is transmitting simultaneously to two users, user 1 and user 2, using the same frequency carrier by applying NOMA.
Notation
- x1 - data to be sent to user 1
- x2 - data to be sent to user 2
- a1 = 0.75 - power weight given to user 1
- a2 = 0.25 - power weight given to user 2
Implementation in MATLAB
We will dive in directly to the implementation part here. To understand the working of NOMA, please refer the previous posts on superposition coding and successive interference cancellation- Generate random binary data for user 1 and user 2. For random binary data generation, we can use the inbuilt MATLAB function called randi(). randi([0 1],1,N) will generate a binary sequence of length N
- Do BPSK modulation to the above generated data. The operation 2*k-1 will give the BSPK modulated symbol for data bit k
- Do superpostion coding. That is, compute x = √a1x1 + √a2x2 Iterate steps 4 to 7 for every SNR
- Add AWGN. The awgn(x,SNR_dB,'measured') function can be used here. After addition of awgn, we have the received signal, y1 = x + n1 for user 1 and, y2 = x + n2 for user 2.
- For user 1, perform direct BPSK demodulation of y1 to get x1.
- For user 2, first perform direct BPSK demodulation of y2 to get x1.
- Remodulate x1 into a BPSK signal as x'1 = 2x1 - 1
- Multiply the estimate obtained in the previous step by √a1 and subtract it from y. That is, do rem = y - √a1x'1
- Perform direct BPSK demodulation of rem to obtain x2
- Compare the decoded bits with the transmitted bits to estimate BER using the inbuilt biterr() function of MATLAB.
- Plot the BER vs SNR curves.
The BER curves look like this:
We can observe the waterfall trend. Also, we observe that user 2 has slightly higher BER than user 1, especially in the low SNR regime. This is because user 2 has to do SIC. While performing SIC, user 2 must first estimate user 1's data from y. If this estimate is wrong, then, this error will reflect in the decoding of its own information because the wrong data would be subtracted from y. In other words, user 2 must decode both user 1's data and its own data correctly. Any error in decoding user 1's data or its own data will impact its BER. That is why user 2 experiences higher BER than user 1.
MATLAB code
Here is the MATLAB code used in this example. You can also download it as a .m file here.
clc; clear variables; close all;
N = 10^5; %Number of monte carlo simulations
SNR = 0:30; %SNR range in dB
snr = db2pow(SNR); %SNR range in linear scale
%Generate random data bits for transmission
x1 = randi([0 1],1,N); %Data bits of user 1
x2 = randi([0 1],1,N); %Data bits of user 2
%Do BPSK modulation of data
xmod1 = 2*x1 - 1;
xmod2 = 2*x2 - 1;
%Set power weights for users
a1 = 0.75; a2 = 0.25;
%Do superposition coding
x = sqrt(a1)*xmod1 + sqrt(a2)*xmod2;
%Add AWGN to x (Transmit x through an AWGN channel)
for u = 1:length(snr)
y1 = awgn(x,SNR(u),'measured'); %Received signal at user 1 corrupted by AWGN
y2 = awgn(x,SNR(u),'measured'); %Received signal at user 2 corrupted by AWGN
%AT USER 1
%Direct decoding of x from y1
x1_hat = ones(1,N); %just a buffer
x1_hat(y1 < 0) = 0; %AT USER 2 %Direct decoding of x from y2 x11_est = ones(1,N); %just a buffer x11_est(y2 < 0) = 0; %Estimate user 1's signal first x11_est(x11_est == 0) = -1; %Remodulate user 1's signal %Subtract remodulated x11_est component from y2 rem = y2 - sqrt(a1)*x11_est; %Decode x2 from rem x2_hat = zeros(1,N); x2_hat(rem>0) = 1;
%Estimate BER
ber1(u) = biterr(x1,x1_hat)/N;
ber2(u) = biterr(x2,x2_hat)/N;
end
%plot BER curves
semilogy(SNR, ber1, 'linewidth', 1.5); hold on;
semilogy(SNR, ber2, 'linewidth', 1.5); grid on;
legend('User 1 \alpha_1 = 0.75','User 2 \alpha_2 = 0.25');
xlabel('SNR (dB)');
ylabel('BER');
title('BER graph for NOMA in AWGN channel');
In our next post, we will see BER simulation of NOMA in a Rayleigh fading channel, where the users have different channels and are located at different distances from the BS, which is a more realistic case. Thank you!
Thank you very much for this tutorial. This is truly helpful. I look forward to further Matlab tutorials in NOMA and 5G.
ReplyDeleteHi dolphix! More posts on NOMA and 5G using MATLAB are on the way. Thanks for your support!
DeleteJoe,can you come up with this scenario assisted with IRS now.please
Deletehi ! ,can you help me on how to plot the change of BER value depending on different power coefficients for different SNR values in noma?
ReplyDeleteThank you in advance !
Hi yagmur!
DeletePlease refer to this link: https://ecewireless.blogspot.com/2020/04/how-does-power-allocation-affect-noma.html
Hope you find it useful.
hi joe,
Deletecan you share ur email id
Thank you very much !
ReplyDeleteWhat will be the mean and variance of the additive Gaussian noise awgn(x,SNR(u),'measured') ?
ReplyDeleteThe mean would be zero. The awgn function first measures the power (P) of x. Then the value of noise variance is calculated as P/SNR(u). For this calculation, P and SNR(u) are converted to linear scale.
DeleteSorry for this stupid question but what would be the motivation for generating an AWGN noise with noise variance equal to (Power of x)/SNR(u) ?
DeleteCan we just generate a simple AWGN noise sample N(0,1) instead ?
(My guts feeling is that it is a little bit difficult to have the normalized symbol energy E{x^2} = 1 so we need to use the 'measured' option in the awgn() function to add some kind of normalization for us )
Noise variance is equal to noise power right? We want enough noise power to be added to the signal so that we get the desired SNR. [specified by awgn(x, SNR, 'measured')]. If the signal power is P, then we will get the desired SNR only if the noise power is P/SNR.
DeleteAlso the matlab documentation says that if the 'measured' argument is used, the awgn() function first measures the signal power (P) before adding noise.
Hope it helps..
"so that we get the desired SNR" this sentence explain everything :D
DeleteThe usage of awgn(x,SNR(u),'measured') is an excellent piece of Matlab code.
If I dont use it I have to manually calculate the quantity of noise power that need to be added to the signal in order to achieve the desired SNR
This process might prone to some error because the power of the signal x may varied differently !!!
Thank you !
How can we obtain SNR values on the receiver side for each user?
ReplyDeleteConsidering a Rayleigh fading channel, receive SINR for the far user would be 10*log10(a_f*p(u)*mean(|h_f|^2)/(a_n*p(u)*mean(|h_f|^2) + sigma^2)). And for the near user, 10*log10(a_n*p(u)*mean(|h_n|^2)/sigma^2).
DeleteHere a_n, a_f are respectively the power allocation coefficients of the near and far user.
p(u) is the transmit power,
h_n, h_f are the channel coefficients of the near and far users.
sigma^2 is the noise variance.
When I try to use QPSK as modulation using inbuilt MATLAB command, in my graph the slope for user 1 is always a straight line. Any idea why is that?
ReplyDeleteHi amit!
DeleteIf you used rayleigh fading, there maybe some problem in equalization.
If user 1 has to do SIC, he has to remodulate the user 2 signal before subtracting.
But i am not sure because i dont know all the details about your code.
If you can mail me the code electronicswithme@gmail.com i will take a look and let you know
I am working with QPSK and i have a lot of problems i do not understand how does the NOMA with SIC work in QPSK can you help me ???
Deletethank you so much for your help. You are the only one on internet who is explaining NOMA so perfectly well. Hope you will continue more.
ReplyDeleteOne more request is if its possible to have NOMA for multiple users? Like more than two at a time?
Thanks for the kind words amit!
DeleteIt is possible to have multiple users in NOMA. We will cover that in a future post. Thanks for your support!
Hi . Iam doing my thesis on NOMA and iam quite stuck . My thesis is about improving the physical layer security using active jamming signals . So the source sends the messages to two users and and eavesdropper secretly listens them .The users here act in full duplex mode as they receive the signals from the source and also send jamming signals to the eavesdropper just to confuse it . Iam quite stuck with equations and clueless on what to do next . I hope you help me out
ReplyDeleteHi! At what point are you stuck? Are you stuck in deciphering the equations? Or are you getting errors in code?
DeleteIf you can detail your problem to this mail electronicswithme@gmail.com
I can look into it.. But I am not "expert" in NOMA... But I can give it a try..
Both the ways iam stuck . I have sent you a detailed mail . Please do look into it and let me know .Thank you
DeleteSure. I'll look into it and get back to you.
Deletehello sir thank you very much, your work is amazing i have seen that you are replying for every one sending you a message that's so kind sir thanks a lot , i am working about NOMA my code is about NOMA with 2 users + AWGN (0 main unit variance ) + Rayleigh distribution (0 main segma^2 as a variance ) + QPSK modulation i want to plot ( BER vs SNR ) i am having some problems can you help me plz ??? my email is (rkheddara@gmail.com) the problem is in the SIC operation and the Rayleigh distribution thanks .
ReplyDeleteHi Rania, if you can send your code to my mail (electronicswithme@gmail.com), I will take a look at it and let you know...
Deletei will thanksssss
DeleteThank you so much for this simplification
ReplyDeletethanks Joe!.. You not only just helped me... but made my life easier... i wont bore you with the details. But thanks a ton!
ReplyDeleteYou're welcome!
Deletesir, if I need to add noise to AWGN channel what change should i need to make in this code and
ReplyDeletesir can you help me to do BER vs SNR for 2 users using Rayleigh fading under this same assumptions?
dear Joe,
ReplyDeleteKindly your support as usual and Please Please send me SCMA code at below mail as soon possible,Please.
ki.su01994@gmail.com
Hi Kinanaa, unfortunately, I don't have code for SCMA right now.
Deletecan you plz explain how to combined both NOMA and PNC techniques? and to implement it's code?
ReplyDeleteHi, NOMA with Physical layer Network Coding looks interesting. We'll cover that in a future post
DeleteYou are the best keep it going, if you have time maybe make a YouTube channel
ReplyDeleteThank you so much!
Delete
ReplyDeleteWhy is the second user doing SIC?(For example, given more weight to x1 (i.e., a1> a2), directly decoding x gives x1) help me i don't understand
Hi asasasa,
DeleteThe x1 term will be dominating in the received signal (since a1>a2). So user 2 has to directly decode x1 first and then do SIC to recover x2.
hi joe
ReplyDeleteis far user Bit error rate(ber) better than near user ?
Hi Abdelbasset, far user has poor BER than the near user.
DeleteIn this particular post, we've not brought in the distance factor. Both users are equidistant from the BS. That's why the graphs are like this.
The distance factor is included in the following post: https://ecewireless.blogspot.com/2020/04/how-to-simulate-ber-capacity-and-outage.html). You can see that the far user has poor BER
Hope this helps.
Thank you so much Joe for this valuable information. but why when we increase power for both user ber decrease?
Deleterely ur effort is so much helpful. thank you for the post u made.
ReplyDeletevery interesting topic
ReplyDeleteits better if you store all matlab file in one zip for NOMA and like to others
Thank you
Hi get, glad to know you found the blog helpful.
DeleteThank you :)
hi Joe, I get all your post helpful. Can we use NOMA for visible light communication system? if you have lecture for this to it can help.
ReplyDeleteHi Joe, can you share codes for sum rate maximization??? plz help me
ReplyDeleteHi Joe. Thanks for your help. Your post is very helpful.
ReplyDeletehello sir thank you very much, your work is amazing i have seen that you are replying for every one sending you a message that's so kind sir thanks a lot ,
ReplyDeletei am working about NOMA my code is about NOMA with 2 users + AWGN for different types of modulation BPSK, QPSK, 16QAM and so on.
when i implement NOMA with 16QAM modulation, the BER performance is not well.
Could you help me plz ???
hello sir , my thesis about performance of DPSK transdermal optical wireless and i derived the closed for equations of SNR, outage probability , outage rate and capacity and i need help in matlab code
ReplyDeleteThis comment has been removed by the author.
ReplyDelete