How can I update my values in this loop?
Show older comments
I am currently working on a code to analyse spectral efficiency of NOMA (considering rayleigh fading). But my values of Cn_2, Cn_3, appear not to change on every itreation, and therefore straight lines are being plotted (the red & blue lines). As shown in the figure below.
Can you please advise me on how to fix it.
Thank you.

clear all;
clc;
close all;
F = 10; %Noise Figure
B = 15000; %Bandwidth (HZ)
K = 1.38e-23; %Boltzmanns constant
Temp = 290; %Temperature (K)
No = K*Temp*B*F;
SNR = 1:0.5:20.5; %dB
count = 1;
for P=1:1:40 %W
P1=1/6.*P;
P2=1/3.*P;
P3=1/2.*P;
fun_1 = @(Z) (exp(-Z.*No./P1)./(1+Z)); %fun_1 = fun1_1.*fun2_1;
fun_2 = @(Z) (exp(-Z.*No./P2)./(1+Z).*(1./(1 + (P1./P2).*Z)));
fun_3 = @(Z) (exp(-Z.*No./P3)./(1+Z).*(1./(1 + (P1./P3).*Z)).*(1./(1 + (P2./P3).*Z)));
Cn_1(P) = log2(exp(integral(fun_1,0,Inf,'ArrayValued',true)));
Cn_2(P) = log2(exp(integral(fun_2,0,Inf,'ArrayValued',true)));
Cn_3(P) = log2(exp(integral(fun_3,0,Inf,'ArrayValued',true)));
end
hold on;
plot (SNR,Cn_1,'g');
plot (SNR,Cn_2,'r');
plot (SNR,Cn_3,'b');
grid on;
xlabel('SNR (dB)');
ylabel('Spectral Efficiency(bps/Hz)');
title('SPECTRAL EFFICIENCY AGAINST SNR');
2 Comments
Stepping through with the debugger and seeing what is happening and what the result of each line is each time round the loop is always the best way to solve these things.
The
(P1./P3)
type calculations will eliminate the loop variable P though since it just cancels out, so the impact of P will only be in the initial exponent term for each function
Eugene Fab
on 13 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!