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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@telum.ru>, Alexander Sofronov <sofronov@telum.ru>
7 */
8
9#include "jakes-process.h"
10
13
14#include "ns3/double.h"
15#include "ns3/log.h"
16#include "ns3/simulator.h"
17#include "ns3/uinteger.h"
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("JakesProcess");
23
24/// Represents a single oscillator
25JakesProcess::Oscillator::Oscillator(std::complex<double> amplitude,
26 double initialPhase,
27 double omega)
28 : m_amplitude(amplitude),
29 m_phase(initialPhase),
30 m_omega(omega)
31{
32}
33
34std::complex<double>
36{
37 return (m_amplitude * std::cos(at.GetSeconds() * m_omega + m_phase));
38}
39
41
44{
45 static TypeId tid = TypeId("ns3::JakesProcess")
47 .SetGroupName("Propagation")
48 .AddConstructor<JakesProcess>()
49 .AddAttribute("DopplerFrequencyHz",
50 "Corresponding doppler frequency[Hz]",
51 DoubleValue(80),
54 .AddAttribute("NumberOfOscillators",
55 "The number of oscillators",
56 UintegerValue(20),
59 return tid;
60}
61
62void
64{
66 propagationModel->GetObject<JakesPropagationLossModel>();
67 NS_ASSERT_MSG(jakes, "Jakes Process can work only with JakesPropagationLossModel!");
68 m_jakes = jakes;
69
72
74}
75
76void
77JakesProcess::SetNOscillators(unsigned int nOscillators)
78{
79 m_nOscillators = nOscillators;
80}
81
82void
83JakesProcess::SetDopplerFrequencyHz(double dopplerFrequencyHz)
84{
85 m_omegaDopplerMax = 2 * dopplerFrequencyHz * M_PI;
86}
87
88void
90{
92 // Initial phase is common for all oscillators:
93 double phi = m_jakes->GetUniformRandomVariable()->GetValue();
94 // Theta is common for all oscillators:
95 double theta = m_jakes->GetUniformRandomVariable()->GetValue();
96 for (unsigned int i = 0; i < m_nOscillators; i++)
97 {
98 unsigned int n = i + 1;
99 /// 1. Rotation speed
100 /// 1a. Initiate \f[ \alpha_n = \frac{2\pi n - \pi + \theta}{4M}, n=1,2, \ldots,M\f], n is
101 /// oscillatorNumber, M is m_nOscillators
102 double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_nOscillators);
103 /// 1b. Initiate rotation speed:
104 double omega = m_omegaDopplerMax * std::cos(alpha);
105 /// 2. Initiate complex amplitude:
106 double psi = m_jakes->GetUniformRandomVariable()->GetValue();
107 std::complex<double> amplitude =
108 std::complex<double>(std::cos(psi), std::sin(psi)) * 2.0 / std::sqrt(m_nOscillators);
109 /// 3. Construct oscillator:
110 m_oscillators.emplace_back(amplitude, phi, omega);
111 }
112}
113
119
124
125void
127{
128 m_uniformVariable = nullptr;
129 m_jakes = nullptr;
130}
131
132std::complex<double>
134{
135 std::complex<double> sumAmplitude = std::complex<double>(0, 0);
136 for (unsigned int i = 0; i < m_oscillators.size(); i++)
137 {
138 sumAmplitude += m_oscillators[i].GetValueAt(Now());
139 }
140 return sumAmplitude;
141}
142
143double
145{
146 std::complex<double> complexGain = GetComplexGain();
147 return (10 *
148 std::log10((std::pow(complexGain.real(), 2) + std::pow(complexGain.imag(), 2)) / 2));
149}
150
151} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Implementation for a single path Stationary Jakes propagation loss model.
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:78
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
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.