A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
jakes-propagation-model-example.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Telum (www.telum.ru)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Kirill Andreev <andreev@telum.ru>
19  */
20 #include "ns3/core-module.h"
21 #include "ns3/mobility-module.h"
22 #include "ns3/jakes-propagation-loss-model.h"
23 #include <vector>
24 #include <cmath>
25 
26 using namespace ns3;
34 {
35 public:
38 private:
40  Ptr<MobilityModel> m_firstMobility;
41  Ptr<MobilityModel> m_secondMobility;
42  Time m_step;
43  EventId m_nextEvent;
44  void Next ();
45 
46 };
47 
48 JakesPropagationExample::JakesPropagationExample () :
49  m_step (Seconds (0.0002)) //1/5000 part of the second
50 {
51  m_loss = CreateObject<JakesPropagationLossModel> ();
52  m_firstMobility = CreateObject<ConstantPositionMobilityModel> ();
53  m_secondMobility = CreateObject<ConstantPositionMobilityModel> ();
54  m_firstMobility->SetPosition (Vector (0, 0, 0));
55  m_secondMobility->SetPosition (Vector (10, 0, 0));
56  m_nextEvent = Simulator::Schedule (m_step, &JakesPropagationExample::Next, this);
57 }
58 
59 JakesPropagationExample::~JakesPropagationExample ()
60 {
61 }
62 
63 void JakesPropagationExample::Next ()
64 {
65  m_nextEvent = Simulator::Schedule (m_step, &JakesPropagationExample::Next, this);
66  std::cout << Simulator::Now ().GetMilliSeconds () << " " << m_loss->CalcRxPower (0, m_firstMobility, m_secondMobility) << std::endl;
67 }
68 
69 int main (int argc, char *argv[])
70 {
71  Config::SetDefault ("ns3::JakesProcess::NumberOfOscillators", UintegerValue (100));
72  CommandLine cmd;
73  cmd.Parse (argc, argv);
75  Simulator::Stop (Seconds (1000));
76  Simulator::Run ();
77  Simulator::Destroy ();
78  /*
79  * R script for plotting a distribution:
80  data<-read.table ("data")
81  rayleigh<-(rnorm(1e6)^2+rnorm(1e6)^2)/2
82  qqplot(10*log10(rayleigh), data$V2, main="QQ-plot for improved Jakes model", xlab="Reference Rayleigh distribution [power, dB]", ylab="Sum-of-sinusoids distribution [power, dB]", xlim=c(-45, 10), ylim=c(-45, 10))
83  lines (c(-50, 50), c(-50, 50))
84  abline (v=-50:50*2, h=-50:50*2, col="light grey")
85  */
86 
87  /*
88  * R script to plot autocorrelation function:
89  # Read amplitude distribution:
90  data<-10^(read.table ("data")$V2/20)
91  x<-1:2000/10
92  acf (data, lag.max=200, main="Autocorrelation function of the improved Jakes model", xlab="Time x200 microseconds ", ylab="Autocorrelation")
93  # If we have a delta T = 1/5000 part of the second and doppler freq = 80 Hz
94  lines (x, besselJ(x*80*2*pi/5000, 0)^2)
95  abline (h=0:10/10, col="light grey")
96  */
97  return 0;
98 }
keep track of time unit.
Definition: nstime.h:149
a 3d vector
Definition: vector.h:31
Hold an unsigned integer type.
Definition: uinteger.h:46
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
Definition: command-line.h:50
void SetPosition(const Vector &position)
Constructs a JakesPropagationlossModel and print the loss value as a function of time into std::cout...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
an identifier for simulation events.
Definition: event-id.h:46
void Parse(int argc, char *argv[]) const
Definition: command-line.cc:84