How can I update my values in this loop?

조회 수: 2 (최근 30일)
Eugene Fab
Eugene Fab 2019년 3월 13일
댓글: Eugene Fab 2019년 3월 13일
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.
NOMA.PNG
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
Adam
Adam 2019년 3월 13일
편집: Adam 2019년 3월 13일
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
Eugene Fab 2019년 3월 13일
Thank you Adam.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 3월 13일
편집: Adam Danz 2019년 3월 13일
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
Adam Danz
Adam Danz 2019년 3월 13일
No problem!
Eugene Fab
Eugene Fab 2019년 3월 13일
Thanks again.
But can you help me clarify on this view, "You're always providing a value of 0 as the single input to your anonymous functions. Is that intentional?", because I can't seem to understand it.
Can you please help me with your email address so that I can share with you the formula am trying to implement.
Thank you Adam.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by