A Discrete-Event Network Simulator
API
 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"
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>
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  .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
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 
75 
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
93 {
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 * std::cos (alpha);
108  double psi = m_jakes->GetUniformRandomVariable ()->GetValue ();
109  std::complex<double> amplitude = std::complex<double> (std::cos (psi), std::sin (psi)) * 2.0 / std::sqrt (m_nOscillators);
111  m_oscillators.push_back (Oscillator (amplitude, phi, omega));
112  }
113 }
114 
116  m_omegaDopplerMax (0),
117  m_nOscillators (0)
118 {
119 }
120 
122 {
123  m_oscillators.clear ();
124 }
125 
126 void
128 {
129  m_jakes = 0;
130 }
131 
132 std::complex<double>
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
145 {
146  std::complex<double> complexGain = GetComplexGain ();
147  return (10 * std::log10 ((std::pow (complexGain.real (), 2) + std::pow (complexGain.imag (), 2)) / 2));
148 }
149 
150 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
virtual ~JakesProcess()
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
std::vector< Oscillator > m_oscillators
Vector of oscillators:
Definition: jakes-process.h:87
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
double GetSeconds(void) const
Definition: nstime.h:272
Represents a single oscillator.
Definition: jakes-process.h:68
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:46
double GetChannelGainDb() const
Get Channel gain [dB].
double m_omegaDopplerMax
Definition: jakes-process.h:90
std::complex< double > GetComplexGain() const
void SetDopplerFrequencyHz(double dopplerFrequencyHz)
unsigned int m_nOscillators
Definition: jakes-process.h:91
#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:84
static TypeId GetTypeId(void)
std::complex< double > GetValueAt(Time t) const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
void ConstructOscillators()
a base class which provides memory management and object aggregation
Definition: object.h:64
Ptr< const JakesPropagationLossModel > m_jakes
Definition: jakes-process.h:93
Hold a floating point type.
Definition: double.h:41
a jakes narrowband propagation model.
a unique identifier for an interface.
Definition: type-id.h:49
void SetPropagationLossModel(Ptr< const PropagationLossModel >)
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void SetNOscillators(unsigned int nOscillators)
Implementation for a single path Stationary Jakes propagation loss model.
Definition: jakes-process.h:55