A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
jakes-process.cc
Go to the documentation of this file.
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>, Alexander Sofronov <sofronov@telum.ru>
19
*/
20
21
#include "
jakes-process.h
"
22
#include "ns3/simulator.h"
23
#include "ns3/double.h"
24
#include "ns3/log.h"
25
#include "ns3/uinteger.h"
26
#include "
propagation-loss-model.h
"
27
#include "
jakes-propagation-loss-model.h
"
28
29
NS_LOG_COMPONENT_DEFINE
(
"JakesProcess"
);
30
31
namespace
ns3 {
32
34
JakesProcess::Oscillator::Oscillator
(std::complex<double> amplitude,
double
initialPhase,
double
omega) :
35
m_amplitude (amplitude),
36
m_phase (initialPhase),
37
m_omega (omega)
38
{}
39
40
std::complex<double>
41
JakesProcess::Oscillator::GetValueAt
(
Time
at)
const
42
{
43
return
(m_amplitude * cos (at.
GetSeconds
() * m_omega + m_phase));
44
}
45
46
NS_OBJECT_ENSURE_REGISTERED
(
JakesProcess
);
47
48
TypeId
49
JakesProcess::GetTypeId
()
50
{
51
static
TypeId
tid =
TypeId
(
"ns3::JakesProcess"
)
52
.
SetParent
<
Object
> ()
53
.AddConstructor<JakesProcess> ()
54
.AddAttribute (
"DopplerFrequencyHz"
,
"Corresponding doppler frequency[Hz]"
,
55
DoubleValue
(80),
56
MakeDoubleAccessor (&
JakesProcess::SetDopplerFrequencyHz
),
57
MakeDoubleChecker<double> (0.0, 1e4))
58
.AddAttribute (
"NumberOfOscillators"
,
"The number of oscillators"
,
59
UintegerValue
(20),
60
MakeUintegerAccessor (&
JakesProcess::SetNOscillators
),
61
MakeUintegerChecker<unsigned int> (4, 1000))
62
;
63
return
tid;
64
}
65
66
void
67
JakesProcess::SetPropagationLossModel
(
Ptr<const PropagationLossModel>
propagationModel)
68
{
69
Ptr<const JakesPropagationLossModel>
jakes = propagationModel->GetObject<
JakesPropagationLossModel
> ();
70
NS_ASSERT_MSG
(jakes != 0,
"Jakes Process can work only with JakesPropagationLossModel!"
);
71
m_jakes
= jakes;
72
73
NS_ASSERT
(
m_nOscillators
!= 0);
74
NS_ASSERT
(m_omegaDopplerMax != 0);
75
76
ConstructOscillators
();
77
}
78
79
void
80
JakesProcess::SetNOscillators
(
unsigned
int
nOscillators)
81
{
82
m_nOscillators
= nOscillators;
83
}
84
85
void
86
JakesProcess::SetDopplerFrequencyHz
(
double
dopplerFrequencyHz)
87
{
88
m_omegaDopplerMax = 2 * dopplerFrequencyHz *
JakesPropagationLossModel::PI
;
89
}
90
91
void
92
JakesProcess::ConstructOscillators
()
93
{
94
NS_ASSERT
(
m_jakes
);
95
// Initial phase is common for all oscillators:
96
double
phi =
m_jakes
->
GetUniformRandomVariable
()->
GetValue
();
97
// Theta is common for all oscillatoer:
98
double
theta =
m_jakes
->
GetUniformRandomVariable
()->
GetValue
();
99
for
(
unsigned
int
i = 0; i <
m_nOscillators
; i++)
100
{
101
unsigned
int
n = i + 1;
104
double
alpha = (2.0 *
JakesPropagationLossModel::PI
* n -
JakesPropagationLossModel::PI
+ theta) / (4.0 * m_nOscillators);
106
double
omega = m_omegaDopplerMax * cos (alpha);
108
double
psi =
m_jakes
->
GetUniformRandomVariable
()->
GetValue
();
109
std::complex<double> amplitude = std::complex<double> (cos (psi), sin (psi)) * 2.0 / sqrt (m_nOscillators);
111
m_oscillators.push_back (
Oscillator
(amplitude, phi, omega));
112
}
113
}
114
115
JakesProcess::JakesProcess
() :
116
m_omegaDopplerMax (0),
117
m_nOscillators
(0)
118
{
119
}
120
121
JakesProcess::~JakesProcess
()
122
{
123
m_oscillators.clear ();
124
}
125
126
void
127
JakesProcess::DoDispose
()
128
{
129
m_jakes
= 0;
130
}
131
132
std::complex<double>
133
JakesProcess::GetComplexGain
()
const
134
{
135
std::complex<double> sumAplitude = std::complex<double> (0, 0);
136
for
(
unsigned
int
i = 0; i < m_oscillators.size (); i++)
137
{
138
sumAplitude += m_oscillators[i].GetValueAt (
Now
());
139
}
140
return
sumAplitude;
141
}
142
143
double
144
JakesProcess::GetChannelGainDb
()
const
145
{
146
std::complex<double> complexGain =
GetComplexGain
();
147
return
(10 * log10 ((pow (complexGain.real (), 2) + pow (complexGain.imag (), 2)) / 2));
148
}
149
150
}
// namespace ns3
src
propagation
model
jakes-process.cc
Generated on Tue Oct 9 2012 16:45:45 for ns-3 by
1.8.1.2