A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
jakes-process.cc
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 * std::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 
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 {
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 * 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 
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
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
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
keep track of time unit.
Definition: nstime.h:149
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
virtual void DoDispose()
double GetSeconds(void) const
Definition: nstime.h:262
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].
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:286
void ConstructOscillators()
a base class which provides memory management and object aggregation
Definition: object.h:63
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
Implementation for a single path Stationary Jakes propagation loss model.
Definition: jakes-process.h:55