12 views (last 30 days)

Show older comments

Hi,i want to find the throughput of N users which are from 1 to 20,I defined it in a vector beacuse i want to run 10000 times for single user up to 20 and used another loop within the loop,after calculating the Throughput i am adding it in count and saving in variable count beacuse of 10000values,the value of count is divided by no of simulations i have run and save in S for user 1 to 2 and in the end ploting it ,but i am getting a straight decreasing graph,can any body help me to find the mistake i am doing???

clear all

close all

clc

simulations=10000;

n_vec=1:2:20;

R=[];

for n=n_vec

count=0;

S=0;

for sim=1:simulations

B=0.3;

phi=(1-B)./n;

tau=B./n;

Bbn=20*1000;

Rbn = phi*Bbn;

BR=n.*Rbn;

PRn=0.0002224 ;

Ehn=(1-B-phi)*PRn;

Ptr=Ehn/tau;

Kn=0.6;

Bandwidth=100*1000;

Psi=Kn*Bandwidth;

No=-174;

hn=rand;

po=No/hn;

gema=1/po;

Rhn=tau*Psi*log2(1+gema*Ehn/tau);

TR=n.*Rhn;

RTotal=BR+TR;

count=count+RTotal;

end

S=count./simulations;

R=[R S];

end

plot(n_vec,R)

Jan
on 25 Jan 2019

Edited: Jan
on 25 Jan 2019

I cannot follow your explanations. I start with cleaning your code:

simulations = 10000;

n_vec = 1:2:20;

R = zeros(1, simulations); % Pre-allocate

% Move constants out of the loop:

B = 0.3;

PRn = 0.0002224 ;

Bbn = 20*1000;

Kn = 0.6;

Bandwidth = 100*1000;

Psi = Kn*Bandwidth;

No = -174;

for in = 1:numel(n_vec)

n = n_vec(in);

phi = (1 - B) ./ n;

tau = B ./ n;

Rbn = phi * Bbn;

BR = n .* Rbn;

Ehn = (1 - B - phi) * PRn;

Ptr = Ehn/tau;

count = 0;

for sim = 1:simulations

TR = n .* tau * Psi * log2(1 + rand * Ehn / tau / No);

RTotal = BR + TR;

count = count + RTotal;

end

S = count ./ simulations;

R(in) = S;

end

plot(n_vec, R)

Yes, this looks almost like a straight line, but is is none:

diff(R)

You see, the differences are from -0.076 to -0.085. This is exactly what the given code instructs Matlab to calculate. The effects of the rand value are damped massively, by dividing it by a large value and adding 1 - and by takeing the log2 afterwards:

TR = n .* tau * Psi * log2(1 + rand * Ehn / tau / No)

= n .* tau * Psi * log2(1 + rand * ([-5.9e-6 to -5.9e-5]))

So if the value of rand is 0 or 1 changes the value of TR marginally only.

There is no chance to guess, why you expect another result or why you assume, that there is a mistake.

Jan
on 28 Apr 2019

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

Start Hunting!