I want to plot the graph between d1 and R1_av but I am getting blank plot . Please help me
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Walter Roberson
le 26 Fév 2021
for d1=0:10:100
d1 is left as a scalar after you use it as a loop control variable.
5 commentaires
MSA
le 27 Fév 2021
Code:
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
d1=0:10:100;
g1 = (abs(h1)).^2;
g2 = (abs(h2)).^2;
Pt = 0:4: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;
Voir également
Catégories
En savoir plus sur Equivalent Baseband Simulation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!