Skip to content

Instantly share code, notes, and snippets.

@vighneshbirodkar
Created August 20, 2013 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vighneshbirodkar/6285802 to your computer and use it in GitHub Desktop.
Save vighneshbirodkar/6285802 to your computer and use it in GitHub Desktop.
A simulation of Log Normal Shadowing based Path Loss.
/**
Program to simlulate Log Normal Shadowing
Program generates data in "plot.dat" file which can be plottes using gnuplot
*Compile with
g++ lns.cpp -o lns -std=c++11
*Plot with
plot "plot.dat" ;set xlabel "Seperation";set ylabel "Path Loss"
*/
#include<iostream>
#include<fstream>
#include<cmath>
#include<random>
#define N 1000 // desired simulations
#define MAX 20 //maximum distance
using namespace std;
int main( void ){
float mean = 0.0; //mean for Gaussian Random Variable
float stdDev = 10.0; // Std. Deviation for Gaussian Random Variable
float PL; // Path loss
float PL0; //path loss at d0
float gamma=2;//path loss exponent
int i;
int d0 = 10;//minimum distance
float xg;
float randomDistance;//randomly generated distance
ofstream file;
file.open("plot.dat");
default_random_engine generator;
normal_distribution<float> distribution(mean,stdDev);
uniform_real_distribution<float> floatDistribution(d0,MAX);
for(i=0;i<N;i++)
{
randomDistance = floatDistribution(generator);
xg = distribution(generator);
PL = PL0 + 10*gamma*log((randomDistance)/d0) + xg;
file<< d0+i << "\t\t" << PL<<endl;
}
file.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment