1
votes

I would like to get a plot like this

enter image description here

which is generated in Gnuplot but plotting from a file.

The Gnuplot scrip that contains all the functions is the following:

set encoding iso_8859_1
set key right top font "Helvetica,17"
set ylabel "Received power, P_t (dBm)" font "Helvetica,18"
set xlabel "Separation distance, r (m)" font "Helvetica,18"
set xtics font "Helvetica,16"
set ytics font "Helvetica,16"
set size 1, 1.2
set terminal postscript color eps enhanced
set grid xtics ytics
set key spacing 1.5
set key box linestyle 1 width 3
set logscale x
set grid xtics mxtics
set output "link-up-test.eps"
h1=1.85
h2=0.5
r(x) = sqrt((h1 - h2)**2 + x**2 )
lmb = 300/865.7
H(x) = sqrt( 1- (4*h1*h2)/(x**2 + (h1 + h2)**2 ) )
theta(x) = 2*pi/lmb*( sqrt((h1 + h2)**2+x**2 ) - sqrt((h1 - h2)**2+ x**2) )
q_e(x) = H(x)**2*(sin(theta(x)))**2 + (1 - H(x)*cos(theta(x)))**2
P_x_G = 4
sigma = 1.94
invsqrt2pi = 0.398942280401433
normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2)
rnd(x) = 10**(-normal(x,0,sigma)/10)
pot_t(x) = 10*log10( 1000*(P_x_G*1.622*((300/lmb)**2) *0.5*1) / (((4*pi*r(x))**2) *1.2*1)*q_e(x)*rnd(x) )
plot [1:12][] pot_t(x) t "up"  w lines ls 1

With this script, I get the following plot

enter image description here

which is has similar form but it does not have the randomness os the function rnd(x) and it does not have the same levels in the y-axis.

I am missing something but I have checked several times the functions several times. I would like to know why is not the same figure.

Regards

2

2 Answers

2
votes

I would like to give my solution to this question. I have used the Box-Muller method to generate Gaussian samples.

h1=1.85
h2=0.5
r(x) = sqrt((h1 - h2)**2 + x**2 )
lmb = 300/865.7
H(x) = sqrt( 1- (4*h1*h2)/(x**2 + (h1 + h2)**2 ) )
theta(x) = 2*pi/lmb*( sqrt((h1 + h2)**2+x**2 ) - sqrt((h1 - h2)**2 + x**2) )
q_e(x) = H(x)**2*(sin(theta(x)))**2 + (1 - H(x)*cos(theta(x)))**2
P_G = 4

sigma = 1.94


normal(x,mu,sigma) = sqrt(-2.0 * log(rand(0))) * cos(2*pi * rand(0)) * sigma + mu
rnd(x) = 10**(-normal(x,0,sigma)/10)

pot_t(x) = 10*log10( 1000*(P_G*1.622*((lmb)**2) *0.5*1) / (((4*pi*r(x))**2) *1.2*1)*q_e(x)*rnd(x) )
set samples 1000
plot [1:12][] pot_t(x) t "up"  w lines ls 1

Which creates this plot:

enter image description here The samples are generated with the function normal(x, mu, sigma). There is only an issue with this solution When I plot with set logscale x the plot of points should be denser when the x-axis are more concentrated (see first plot above), but it seems that Gnuplot first makes the logscale of the x-axis and after that takes equidistant samples in figure dealing the log scale as a linear scale. I would appreciate if anyone could answer this or improve the solution.

Regards

1
votes

There is nothing random about your rnd(x) function. Just plot rnd(x) and you can see that. Why are you not using gnuplot's rand() function in conjunction with your normal distribution?