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:

  1. Let us do downlink transmission from base station (BS) to two users.
  2. We are not using any path loss models and we assume that both users are located at equal distances from the BS.
  3. We are assuming an AWGN channel
  4. We are going to use BPSK modulation for both users
  5. 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
  1. 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
  2. Do BPSK modulation to the above generated data. The operation 2*k-1 will give the BSPK modulated symbol for data bit k
  3. Do superpostion coding. That is, compute x = √a1x1 + √a2x2
  4. Iterate steps 4 to 7 for every SNR
  5. 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.
  6. For user 1, perform direct BPSK demodulation of y1 to get x1.
  7. For user 2, first perform direct BPSK demodulation of y2 to get x1.
  8. Remodulate x1 into a BPSK signal as x'1 = 2x1 - 1
  9. Multiply the estimate obtained in the previous step by √a1 and subtract it from y. That is, do rem = y - √a1x'1
  10. Perform direct BPSK demodulation of rem to obtain x2
  11. Compare the decoded bits with the transmitted bits to estimate BER using the inbuilt biterr() function of MATLAB.
  12. 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!

Comments

  1. Thank you very much for this tutorial. This is truly helpful. I look forward to further Matlab tutorials in NOMA and 5G.

    ReplyDelete
    Replies
    1. Hi dolphix! More posts on NOMA and 5G using MATLAB are on the way. Thanks for your support!

      Delete
    2. Joe,can you come up with this scenario assisted with IRS now.please

      Delete
  2. hi ! ,can you help me on how to plot the change of BER value depending on different power coefficients for different SNR values in noma?

    Thank you in advance !

    ReplyDelete
    Replies
    1. Hi yagmur!
      Please refer to this link: https://ecewireless.blogspot.com/2020/04/how-does-power-allocation-affect-noma.html
      Hope you find it useful.

      Delete
    2. hi joe,
      can you share ur email id

      Delete
  3. What will be the mean and variance of the additive Gaussian noise awgn(x,SNR(u),'measured') ?

    ReplyDelete
    Replies
    1. The 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.

      Delete
    2. Sorry 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) ?

      Can 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 )

      Delete
    3. 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.

      Also 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..

      Delete
    4. "so that we get the desired SNR" this sentence explain everything :D

      The 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 !

      Delete
  4. How can we obtain SNR values on the receiver side for each user?

    ReplyDelete
    Replies
    1. Considering 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).

      Here 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.

      Delete
  5. 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?

    ReplyDelete
    Replies
    1. Hi amit!
      If 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

      Delete
    2. 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 ???

      Delete
  6. thank 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.
    One more request is if its possible to have NOMA for multiple users? Like more than two at a time?

    ReplyDelete
    Replies
    1. Thanks for the kind words amit!
      It is possible to have multiple users in NOMA. We will cover that in a future post. Thanks for your support!

      Delete
  7. 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

    ReplyDelete
    Replies
    1. Hi! At what point are you stuck? Are you stuck in deciphering the equations? Or are you getting errors in code?

      If 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..

      Delete
    2. Both the ways iam stuck . I have sent you a detailed mail . Please do look into it and let me know .Thank you

      Delete
    3. Sure. I'll look into it and get back to you.

      Delete
  8. hello 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 .

    ReplyDelete
    Replies
    1. Hi Rania, if you can send your code to my mail (electronicswithme@gmail.com), I will take a look at it and let you know...

      Delete
  9. Thank you so much for this simplification

    ReplyDelete
  10. thanks Joe!.. You not only just helped me... but made my life easier... i wont bore you with the details. But thanks a ton!

    ReplyDelete
  11. sir, if I need to add noise to AWGN channel what change should i need to make in this code and
    sir can you help me to do BER vs SNR for 2 users using Rayleigh fading under this same assumptions?

    ReplyDelete
  12. dear Joe,
    Kindly your support as usual and Please Please send me SCMA code at below mail as soon possible,Please.

    ki.su01994@gmail.com

    ReplyDelete
    Replies
    1. Hi Kinanaa, unfortunately, I don't have code for SCMA right now.

      Delete
  13. can you plz explain how to combined both NOMA and PNC techniques? and to implement it's code?

    ReplyDelete
    Replies
    1. Hi, NOMA with Physical layer Network Coding looks interesting. We'll cover that in a future post

      Delete
  14. You are the best keep it going, if you have time maybe make a YouTube channel

    ReplyDelete

  15. Why 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

    ReplyDelete
    Replies
    1. Hi asasasa,
      The 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.

      Delete
  16. hi joe
    is far user Bit error rate(ber) better than near user ?

    ReplyDelete
    Replies
    1. Hi Abdelbasset, far user has poor BER than the near user.

      In 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.

      Delete
    2. Thank you so much Joe for this valuable information. but why when we increase power for both user ber decrease?

      Delete
  17. rely ur effort is so much helpful. thank you for the post u made.

    ReplyDelete
  18. very interesting topic
    its better if you store all matlab file in one zip for NOMA and like to others
    Thank you

    ReplyDelete
    Replies
    1. Hi get, glad to know you found the blog helpful.
      Thank you :)

      Delete
  19. 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.

    ReplyDelete
  20. Hi Joe, can you share codes for sum rate maximization??? plz help me

    ReplyDelete
  21. Hi Joe. Thanks for your help. Your post is very helpful.

    ReplyDelete
  22. hello 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 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 ???

    ReplyDelete
  23. 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

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to simulate BER, capacity and outage probability of NOMA (Rayleigh fading) using MATLAB?

How to do power allocation in NOMA? (with fairness to far/weak user)