A Discrete-Event Network Simulator
API
jakes-propagation-model-example.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Telum (www.telum.ru)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Kirill Andreev <andreev@telum.ru>
18  */
19 #include "ns3/core-module.h"
20 #include "ns3/jakes-propagation-loss-model.h"
21 #include "ns3/mobility-module.h"
22 
23 #include <cmath>
24 #include <vector>
25 
26 using namespace ns3;
27 
35 {
36  public:
39 
40  private:
49  void Next();
50 };
51 
53  : m_step(Seconds(0.0002)) // 1/5000 part of the second
54 {
55  m_loss = CreateObject<JakesPropagationLossModel>();
56  m_firstMobility = CreateObject<ConstantPositionMobilityModel>();
57  m_secondMobility = CreateObject<ConstantPositionMobilityModel>();
58  m_firstMobility->SetPosition(Vector(0, 0, 0));
59  m_secondMobility->SetPosition(Vector(10, 0, 0));
60  m_nextEvent = Simulator::Schedule(m_step, &JakesPropagationExample::Next, this);
61 }
62 
64 {
65 }
66 
67 void
69 {
70  m_nextEvent = Simulator::Schedule(m_step, &JakesPropagationExample::Next, this);
71  std::cout << Simulator::Now().As(Time::MS) << " "
72  << m_loss->CalcRxPower(0, m_firstMobility, m_secondMobility) << std::endl;
73 }
74 
75 int
76 main(int argc, char* argv[])
77 {
78  Config::SetDefault("ns3::JakesProcess::NumberOfOscillators", UintegerValue(100));
79  CommandLine cmd(__FILE__);
80  cmd.Parse(argc, argv);
82  Simulator::Stop(Seconds(1000));
83  Simulator::Run();
84  Simulator::Destroy();
85  /*
86  * R script for plotting a distribution:
87  data<-read.table ("data")
88  rayleigh<-(rnorm(1e6)^2+rnorm(1e6)^2)/2
89  qqplot(10*log10(rayleigh), data$V2, main="QQ-plot for improved Jakes model", xlab="Reference
90  Rayleigh distribution [power, dB]", ylab="Sum-of-sinusoids distribution [power, dB]",
91  xlim=c(-45, 10), ylim=c(-45, 10)) lines (c(-50, 50), c(-50, 50)) abline (v=-50:50*2,
92  h=-50:50*2, col="light grey")
93  */
94 
95  /*
96  * R script to plot autocorrelation function:
97  # Read amplitude distribution:
98  data<-10^(read.table ("data")$V2/20)
99  x<-1:2000/10
100  acf (data, lag.max=200, main="Autocorrelation function of the improved Jakes model", xlab="Time
101  x200 microseconds ", ylab="Autocorrelation") # If we have a delta T = 1/5000 part of the second
102  and doppler freq = 80 Hz lines (x, besselJ(x*80*2*pi/5000, 0)^2) abline (h=0:10/10, col="light
103  grey")
104  */
105  return 0;
106 }
Constructs a JakesPropagationlossModel and print the loss value as a function of time into std::cout.
Ptr< MobilityModel > m_secondMobility
second Mobility
Ptr< MobilityModel > m_firstMobility
first Mobility
Ptr< PropagationLossModel > m_loss
loss
Parse command-line arguments.
Definition: command-line.h:232
An identifier for simulation events.
Definition: event-id.h:55
void SetPosition(const Vector &position)
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
Hold an unsigned integer type.
Definition: uinteger.h:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:890
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:40