How can I update my values in this loop?
2 views (last 30 days)
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
Adam
on 13 Mar 2019
Edited: Adam
on 13 Mar 2019
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
Accepted Answer
Adam Danz
on 13 Mar 2019
Edited: Adam Danz
on 13 Mar 2019
The values are updating. It's just that the values are very very close to each other and the much-larger y axis range is flattening them out. Here are the values of Cn_2 and Cn_3 when plotted by themselves.

If this is unexpected, my bet is that your functions aren't doing what they are intended to do. You're always providing a value of 0 as the single input to your anonymous functions. Is that intentional?
3 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!