Question: % % Parameters N = 5 ; % Number of users L = 5 ; % Number of subcarriers B = 3 ; % Near

%% Parameters
N =5; % Number of users
L =5; % Number of subcarriers
B =3; % Near users
phi =2; % Far users
alpha = randi([0,1], L, N); % Power allocation for each user and subcarrier
PT =10; % Transmit power
n =2; % User of interest
hn = randn(L,1); % Channel coefficients for each subcarrier
sigma2=0.01; % Noise variance
S = randi([0,1], L, N); % Transmitted symbols for each user and subcarrier
g = ones(N,1); % Scaling factor
wn = sqrt(sigma2)* randn(L,1); % AWGN noise
sik = randi([0,1], N, L); % Modulated symbols for each user and subcarrier
% Preallocate for received signals
yn_scalar_C_NOMA = zeros(L,1);
yn_scalar_IM_NOMA_CR = zeros(L,1);
%% Loop through subcarriers: C-NOMA Received Signal Calculation
for k =1:L
% Intended signal for the nth user on the k-th subcarrier
intended_signal = hn(k)* sqrt(alpha(k, n)* PT)* sik(n, k);
% Interference signals from other users
interference_signal =0;
for i =1:N
if i ~= n
interference_signal = interference_signal +...
hn(k)* sqrt(alpha(k, i)* PT)* sik(i, k);
end
end
% Received signal with interference and noise (C-NOMA)
yn_scalar_C_NOMA(k)= intended_signal + interference_signal + wn(k);
end
%% IM-NOMA-CR Received Signal Calculation
for k =1:L
% Calculating x_k as per the equation
xk = sum(sqrt(alpha(k,1:B).'* PT).* sik(1:B, k))+...
sum(sqrt(alpha(k, B+1:N-phi).'* PT).* sik(B+1:N-phi, k));
% Calculating phi_k as per the equation
phik = sum(sqrt(alpha(k,1:B).'* PT).* sik(1:B, k))+...
sum(sqrt(alpha(k, B+1:N-phi).'* PT).* sik(B+1:N-phi, k))+...
exp(1j * pi /2)* sum(sqrt(alpha(k, N-phi+1:N).'* PT).* sik(N-phi+1:N, k));
% Received signal with noise (IM-NOMA-CR)
yn_scalar_IM_NOMA_CR(k)= hn(k)* xk + wn(k);
end
%% Maximum Likelihood (ML) Detection for IM-NOMA-CR
possible_symbols =[0,1]; % BPSK Symbols {0,1}
detected_symbols_ml_IM_NOMA_CR = zeros(L,1);
for k =1:L
min_distance = Inf; % Initialize with a high value
best_symbol =0;
% Search over all possible transmitted symbols
for x_candidate = possible_symbols
% Calculate Euclidean distance for each candidate
distance = abs(yn_scalar_IM_NOMA_CR(k)- hn(k)* x_candidate)^2;
% Find the symbol with minimum distance
if distance min_distance
min_distance = distance;
best_symbol = x_candidate;
end
end
% Assign detected symbol
detected_symbols_ml_IM_NOMA_CR(k)= best_symbol;
end
% Display the detected symbols for IM-NOMA-CR
disp('ML Detected Symbols for IM-NOMA-CR:');
disp(detected_symbols_ml_IM_NOMA_CR);
%% SNR vs BER Calculation
SNR_dB =0:5:50; % SNR values in dB
SNR_linear =10.^(SNR_dB /10); % Convert SNR to linear scale
% Calculate BER trends (replace with real logic if needed)
BER_C_NOMA =0.5./ SNR_linear; % C-NOMA BER trend
BER_IM_NOMA_CR =0.8./ SNR_linear; % IM-NOMA-CR BER trend
%% Plotting the BER Comparison Graph
figure;
semilogy(SNR_dB, BER_C_NOMA, '-g^', 'LineWidth', 1.5, 'DisplayName', 'C-NOMA ML All'); hold on;
semilogy(SNR_dB, BER_C_NOMA *1.1,'-ks', 'LineWidth', 1.5, 'DisplayName', 'C-NOMA ML Near');
semilogy(SNR_dB, BER_C_NOMA *0.9,'-bo', 'LineWidth', 1.5, 'DisplayName', 'C-NOMA ML Far');
semilogy(SNR_dB, BER_IM_NOMA_CR,'-r*', 'LineWidth', 1.5, 'DisplayName', 'IM-NOMA-CR ML All');
semilogy(SNR_dB, BER_IM_NOMA_CR *1.1,'-md', 'LineWidth', 1.5, 'DisplayName', 'IM-NOMA-CR ML Near');
semilogy(SNR_dB, BER_IM_NOMA_CR *0.9,'-cp', 'LineWidth', 1.5, 'DisplayName', 'IM-NOMA-CR ML Far');
hold off;
% Set axis labels and title
xlabel('SNR (dB)');
ylabel('BER');
title('BER Comparison between C-NOMA and IM-NOMA-CR');
legend('Location', 'southwest');
grid on;
In this i have used ML detector Now I want an matlab code using log likelihood detector and maximum ratio combining Detector.output should be the fig-4. you can use any AI tools but i want same graph as output.but graphs are different i will report.You can use any AI tools but graph is important
Fig. 4. BER comparison between C-NOMA and IM-NOMA-CR.
% % Parameters N = 5 ; % Number of users L = 5 ;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!