Onramp problem 14.1 and 14.2 plotting problems

On both of these examples I have inputted the correct code - when compared to the answer. However in both examples it still says that I have an incorrect code. What am I doing wrong? (there are four lines on the plot, s is on the y axis, and it is dashed!!

댓글 수: 3

May I know, what environment you are working on and also the system specifications to see if I could reproduce it on my end?
clc; clear variables; close all;
N = 10^5;
d1 = 0:10:100; d2 = 500; %Distances of users from base station (BS)
a1 = 0.75; a2 = 0.25; %Power allocation factors
eta = 4; %Path loss exponent
for d1=0:10:100
%Generate rayleigh fading coefficient for both users
h1 = sqrt(d1^-eta)*(randn(1,N)+1i*randn(1,N))/sqrt(2);
h2 = sqrt(d2^-eta)*(randn(1,N)+1i*randn(1,N))/sqrt(2);
end
g1 = (abs(h1)).^2;
g2 = (abs(h2)).^2;
Pt = 0:2:40; %Transmit power in dBm
pt = (10^-3)*10.^(Pt/10); %Transmit power in linear scale
BW = 10^6; %System bandwidth
No = -174 + 10*log10(BW); %Noise power (dBm)
no = (10^-3)*10.^(No/10); %Noise power (linear scale)
p = length(Pt);
p1 = zeros(1,length(Pt));
p2 = zeros(1,length(Pt));
d = length(d1);
rate1 = 1; rate2 = 2; %Target rate of users in bps/Hz
for u = 1:p
%Calculate SNRs
gamma_1 = a1*pt(u)*g1./(a2*pt(u)*g1+no);
gamma_12 = a1*pt(u)*g2./(a2*pt(u)*g2+no);
gamma_2 = a2*pt(u)*g2/no;
%Calculate achievable rates
R1 = log2(1+gamma_1);
R12 = log2(1+gamma_12);
R2 = log2(1+gamma_2);
%Find average of achievable rates
R1_av(u) = mean(R1);
R12_av(u) = mean(R12);
R2_av(u) = mean(R2);
%Check for outage
for k = 1:N
if R1(k) < rate1
p1(u) = p1(u)+1;
end
if (R12(k) < rate1)||(R2(k) < rate2)
p2(u) = p2(u)+1;
end
end
end
figure;
plot(d1, R1_av, 'linewidth', 1.5); hold on; grid on;
I want to plot the graph between d1 and R1_av but I am getting blank plot . Please help me
Thank you for getting back to me. I have had this problem a couple of times now with the onramp and the fundimentals. However, it seems that the system keeps something in its memory, so if i press the reset question button (which clears everything) then reput in the exact same code (using copy paste) it then works. Seems to be just a frustrating little bug - but might be worth making a bigger thing of the reset button so that folks know to use it.
Thanks
Heidi

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

답변 (1개)

ANKUR KUMAR
ANKUR KUMAR 2021년 2월 26일

2 개 추천

Few points I need to mention:
1) You are calculating R1_av as a function of u, so if you use the below chunk of code, it will plot the values of R1_av.
plot(1:p, R1_av, 'linewidth', 1.5); hold on; grid on;
2) I am amaze that why you wish to plot R1_av as a function of d1. d1 is Distances of users from base station. You are using the same variable in line 3 and line 6. Never do that. Never assign the pre assigned variable in a loop iterated variable, as it is not a good practice and hard to debug the code.

댓글 수: 2

Is there any possible way to plot the graph between d1 and R1_av? By modifying the code?
Why do you wish to plot d1 vs R1_av? Both are having different dimension, and that is why it is NOT possible to plot both. If still you wish to plot these two, you need to modify the code. First try to understand which variable R1_av dependent on? Dimension of both x and y variable MUST be same.

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

카테고리

도움말 센터File Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 2월 17일

댓글:

2021년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by