A Discrete-Event Network Simulator
API
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"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("JakesProcess");
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>
42 {
43  return (m_amplitude * std::cos (at.GetSeconds () * m_omega + m_phase));
44 }
45 
47 
48 TypeId
50 {
51  static TypeId tid = TypeId ("ns3::JakesProcess")
52  .SetParent<Object> ()
53  .SetGroupName ("Propagation")
54  .AddConstructor<JakesProcess> ()
55  .AddAttribute ("DopplerFrequencyHz", "Corresponding doppler frequency[Hz]",
56  DoubleValue (80),
58  MakeDoubleChecker<double> (0.0, 1e4))
59  .AddAttribute ("NumberOfOscillators", "The number of oscillators",
60  UintegerValue (20),
62  MakeUintegerChecker<unsigned int> (4, 1000))
63  ;
64  return tid;
65 }
66 
67 void
69 {
70  Ptr<const JakesPropagationLossModel> jakes = propagationModel->GetObject<JakesPropagationLossModel> ();
71  NS_ASSERT_MSG (jakes != 0, "Jakes Process can work only with JakesPropagationLossModel!");
72  m_jakes = jakes;
73 
76 
78 }
79 
80 void
81 JakesProcess::SetNOscillators (unsigned int nOscillators)
82 {
83  m_nOscillators = nOscillators;
84 }
85 
86 void
87 JakesProcess::SetDopplerFrequencyHz (double dopplerFrequencyHz)
88 {
89  m_omegaDopplerMax = 2 * dopplerFrequencyHz * M_PI;
90 }
91 
92 void
94 {
96  // Initial phase is common for all oscillators:
97  double phi = m_jakes->GetUniformRandomVariable ()->GetValue ();
98  // Theta is common for all oscillators:
99  double theta = m_jakes->GetUniformRandomVariable ()->GetValue ();
100  for (unsigned int i = 0; i < m_nOscillators; i++)
101  {
102  unsigned int n = i + 1;
105  double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_nOscillators);
107  double omega = m_omegaDopplerMax * std::cos (alpha);
109  double psi = m_jakes->GetUniformRandomVariable ()->GetValue ();
110  std::complex<double> amplitude = std::complex<double> (std::cos (psi), std::sin (psi)) * 2.0 / std::sqrt (m_nOscillators);
112  m_oscillators.push_back (Oscillator (amplitude, phi, omega));
113  }
114 }
115 
117  m_omegaDopplerMax (0),
118  m_nOscillators (0)
119 {
120 }
121 
123 {
124  m_oscillators.clear ();
125 }
126 
127 void
129 {
130  m_jakes = 0;
131 }
132 
133 std::complex<double>
135 {
136  std::complex<double> sumAplitude = std::complex<double> (0, 0);
137  for (unsigned int i = 0; i < m_oscillators.size (); i++)
138  {
139  sumAplitude += m_oscillators[i].GetValueAt (Now ());
140  }
141  return sumAplitude;
142 }
143 
144 double
146 {
147  std::complex<double> complexGain = GetComplexGain ();
148  return (10 * std::log10 ((std::pow (complexGain.real (), 2) + std::pow (complexGain.imag (), 2)) / 2));
149 }
150 
151 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual ~JakesProcess()
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.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:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetPropagationLossModel(Ptr< const PropagationLossModel > model)
Set the propagation model using this class.
std::vector< Oscillator > m_oscillators
Vector of oscillators.
virtual void DoDispose()
Destructor implementation.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
This class Represents a single oscillator.
Definition: jakes-process.h:87
Oscillator(std::complex< double > amplitude, double initialPhase, double omega)
Initiate oscillator with complex amplitude, initial phase and rotation speed.
Hold an unsigned integer type.
Definition: uinteger.h:44
double GetChannelGainDb() const
Get the channel gain in dB.
double m_omegaDopplerMax
max rotation speed Doppler frequency
double m_omega
Rotation speed of the oscillator .
std::complex< double > GetComplexGain() const
Get the channel complex gain.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetDopplerFrequencyHz(double dopplerFrequencyHz)
Set the Doppler frequency.
unsigned int m_nOscillators
number of oscillators
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
static TypeId GetTypeId(void)
Get the type ID.
std::complex< double > GetValueAt(Time t) const
Get the complex amplitude at a given moment.
void ConstructOscillators()
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
A base class which provides memory management and object aggregation.
Definition: object.h:87
Ptr< const JakesPropagationLossModel > m_jakes
pointer to the propagation loss model
std::complex< double > m_amplitude
Complex number .
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
a Jakes narrowband propagation model.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
double m_phase
Phase of the oscillator.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetNOscillators(unsigned int nOscillators)
Set the number of Oscillators to use.
Implementation for a single path Stationary Jakes propagation loss model.
Definition: jakes-process.h:55