A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
jakes-process.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>, Alexander Sofronov <sofronov@telum.ru>
18 */
19
20#include "jakes-process.h"
21
24
25#include "ns3/double.h"
26#include "ns3/log.h"
27#include "ns3/simulator.h"
28#include "ns3/uinteger.h"
29
30namespace ns3
31{
32
33NS_LOG_COMPONENT_DEFINE("JakesProcess");
34
35/// Represents a single oscillator
36JakesProcess::Oscillator::Oscillator(std::complex<double> amplitude,
37 double initialPhase,
38 double omega)
39 : m_amplitude(amplitude),
40 m_phase(initialPhase),
41 m_omega(omega)
42{
43}
44
45std::complex<double>
47{
48 return (m_amplitude * std::cos(at.GetSeconds() * m_omega + m_phase));
49}
50
52
55{
56 static TypeId tid = TypeId("ns3::JakesProcess")
58 .SetGroupName("Propagation")
59 .AddConstructor<JakesProcess>()
60 .AddAttribute("DopplerFrequencyHz",
61 "Corresponding doppler frequency[Hz]",
62 DoubleValue(80),
64 MakeDoubleChecker<double>(0.0, 1e4))
65 .AddAttribute("NumberOfOscillators",
66 "The number of oscillators",
67 UintegerValue(20),
69 MakeUintegerChecker<unsigned int>(4, 1000));
70 return tid;
71}
72
73void
75{
77 propagationModel->GetObject<JakesPropagationLossModel>();
78 NS_ASSERT_MSG(jakes, "Jakes Process can work only with JakesPropagationLossModel!");
79 m_jakes = jakes;
80
83
85}
86
87void
88JakesProcess::SetNOscillators(unsigned int nOscillators)
89{
90 m_nOscillators = nOscillators;
91}
92
93void
94JakesProcess::SetDopplerFrequencyHz(double dopplerFrequencyHz)
95{
96 m_omegaDopplerMax = 2 * dopplerFrequencyHz * M_PI;
97}
98
99void
101{
103 // Initial phase is common for all oscillators:
104 double phi = m_jakes->GetUniformRandomVariable()->GetValue();
105 // Theta is common for all oscillators:
106 double theta = m_jakes->GetUniformRandomVariable()->GetValue();
107 for (unsigned int i = 0; i < m_nOscillators; i++)
108 {
109 unsigned int n = i + 1;
110 /// 1. Rotation speed
111 /// 1a. Initiate \f[ \alpha_n = \frac{2\pi n - \pi + \theta}{4M}, n=1,2, \ldots,M\f], n is
112 /// oscillatorNumber, M is m_nOscillators
113 double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_nOscillators);
114 /// 1b. Initiate rotation speed:
115 double omega = m_omegaDopplerMax * std::cos(alpha);
116 /// 2. Initiate complex amplitude:
117 double psi = m_jakes->GetUniformRandomVariable()->GetValue();
118 std::complex<double> amplitude =
119 std::complex<double>(std::cos(psi), std::sin(psi)) * 2.0 / std::sqrt(m_nOscillators);
120 /// 3. Construct oscillator:
121 m_oscillators.emplace_back(amplitude, phi, omega);
122 }
123}
124
128{
129}
130
132{
133 m_oscillators.clear();
134}
135
136void
138{
139 m_uniformVariable = nullptr;
140 m_jakes = nullptr;
141}
142
143std::complex<double>
145{
146 std::complex<double> sumAmplitude = std::complex<double>(0, 0);
147 for (unsigned int i = 0; i < m_oscillators.size(); i++)
148 {
149 sumAmplitude += m_oscillators[i].GetValueAt(Now());
150 }
151 return sumAmplitude;
152}
153
154double
156{
157 std::complex<double> complexGain = GetComplexGain();
158 return (10 *
159 std::log10((std::pow(complexGain.real(), 2) + std::pow(complexGain.imag(), 2)) / 2));
160}
161
162} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Implementation for a single path Stationary Jakes propagation loss model.
Definition: jakes-process.h:57
Ptr< UniformRandomVariable > m_uniformVariable
random stream
void SetNOscillators(unsigned int nOscillators)
Set the number of Oscillators to use.
unsigned int m_nOscillators
number of oscillators
void SetDopplerFrequencyHz(double dopplerFrequencyHz)
Set the Doppler frequency.
std::vector< Oscillator > m_oscillators
Vector of oscillators.
~JakesProcess() override
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Get the type ID.
double GetChannelGainDb() const
Get the channel gain in dB.
double m_omegaDopplerMax
max rotation speed Doppler frequency
std::complex< double > GetComplexGain() const
Get the channel complex gain.
Ptr< const JakesPropagationLossModel > m_jakes
pointer to the propagation loss model
void SetPropagationLossModel(Ptr< const PropagationLossModel > model)
Set the propagation model using this class.
void ConstructOscillators()
Builds the object Oscillators.
a Jakes narrowband propagation model.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Oscillator(std::complex< double > amplitude, double initialPhase, double omega)
Initiate oscillator with complex amplitude, initial phase and rotation speed.
std::complex< double > GetValueAt(Time t) const
Get the complex amplitude at a given moment.