author | John Abraham <john.abraham.in@gmail.com> |
Mon, 09 Oct 2017 09:45:32 -0700 | |
changeset 13111 | 68978885b6fc |
parent 9063 | 32755d0516f4 |
permissions | -rw-r--r-- |
8786
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
2 |
/* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
3 |
* Copyright (c) 2012 Telum (www.telum.ru) |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
4 |
* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
8 |
* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
13 |
* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
17 |
* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
18 |
* Author: Kirill Andreev <andreev@telum.ru> |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
19 |
*/ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
20 |
#include "ns3/core-module.h" |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
21 |
#include "ns3/mobility-module.h" |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
22 |
#include "ns3/jakes-propagation-loss-model.h" |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
23 |
#include <vector> |
9063
32755d0516f4
Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents:
8786
diff
changeset
|
24 |
#include <cmath> |
8786
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
25 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
26 |
using namespace ns3; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
27 |
/** |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
28 |
* \ingroup propagation |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
29 |
* \brief Constructs a JakesPropagationlossModel and print the loss value as a function of time into std::cout. |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
30 |
* Distribution and correlation statistics is compared woth a theoretical ones using R package (http://www.r-project.org/). |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
31 |
* Scripts are presented within comments. |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
32 |
*/ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
33 |
class JakesPropagationExample |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
34 |
{ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
35 |
public: |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
36 |
JakesPropagationExample (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
37 |
~JakesPropagationExample (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
38 |
private: |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
39 |
Ptr<PropagationLossModel> m_loss; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
40 |
Ptr<MobilityModel> m_firstMobility; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
41 |
Ptr<MobilityModel> m_secondMobility; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
42 |
Time m_step; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
43 |
EventId m_nextEvent; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
44 |
void Next (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
45 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
46 |
}; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
47 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
48 |
JakesPropagationExample::JakesPropagationExample () : |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
49 |
m_step (Seconds (0.0002)) //1/5000 part of the second |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
50 |
{ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
51 |
m_loss = CreateObject<JakesPropagationLossModel> (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
52 |
m_firstMobility = CreateObject<ConstantPositionMobilityModel> (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
53 |
m_secondMobility = CreateObject<ConstantPositionMobilityModel> (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
54 |
m_firstMobility->SetPosition (Vector (0, 0, 0)); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
55 |
m_secondMobility->SetPosition (Vector (10, 0, 0)); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
56 |
m_nextEvent = Simulator::Schedule (m_step, &JakesPropagationExample::Next, this); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
57 |
} |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
58 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
59 |
JakesPropagationExample::~JakesPropagationExample () |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
60 |
{ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
61 |
} |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
62 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
63 |
void JakesPropagationExample::Next () |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
64 |
{ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
65 |
m_nextEvent = Simulator::Schedule (m_step, &JakesPropagationExample::Next, this); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
66 |
std::cout << Simulator::Now ().GetMilliSeconds () << " " << m_loss->CalcRxPower (0, m_firstMobility, m_secondMobility) << std::endl; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
67 |
} |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
68 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
69 |
int main (int argc, char *argv[]) |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
70 |
{ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
71 |
Config::SetDefault ("ns3::JakesProcess::NumberOfOscillators", UintegerValue (100)); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
72 |
CommandLine cmd; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
73 |
cmd.Parse (argc, argv); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
74 |
JakesPropagationExample example; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
75 |
Simulator::Stop (Seconds (1000)); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
76 |
Simulator::Run (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
77 |
Simulator::Destroy (); |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
78 |
/* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
79 |
* R script for plotting a distribution: |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
80 |
data<-read.table ("data") |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
81 |
rayleigh<-(rnorm(1e6)^2+rnorm(1e6)^2)/2 |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
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)) |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
83 |
lines (c(-50, 50), c(-50, 50)) |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
84 |
abline (v=-50:50*2, h=-50:50*2, col="light grey") |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
85 |
*/ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
86 |
|
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
87 |
/* |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
88 |
* R script to plot autocorrelation function: |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
89 |
# Read amplitude distribution: |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
90 |
data<-10^(read.table ("data")$V2/20) |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
91 |
x<-1:2000/10 |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
92 |
acf (data, lag.max=200, main="Autocorrelation function of the improved Jakes model", xlab="Time x200 microseconds ", ylab="Autocorrelation") |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
93 |
# If we have a delta T = 1/5000 part of the second and doppler freq = 80 Hz |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
94 |
lines (x, besselJ(x*80*2*pi/5000, 0)^2) |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
95 |
abline (h=0:10/10, col="light grey") |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
96 |
*/ |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
97 |
return 0; |
8f366d5eee06
Bug 1140: fixed. New Jakes model has been implemented.
Kirill Andreev <andreev@telum.ru>
parents:
diff
changeset
|
98 |
} |