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 
49 TypeId
51 {
52  static TypeId tid = TypeId ("ns3::JakesProcess")
53  .SetParent<Object> ()
54  .AddConstructor<JakesProcess> ()
55  .AddAttribute ("DopplerFrequencyHz", "Corresponding doppler frequency[Hz]",
56  DoubleValue (80),
57  MakeDoubleAccessor (&JakesProcess::SetDopplerFrequencyHz),
58  MakeDoubleChecker<double> (0.0, 1e4))
59  .AddAttribute ("NumberOfOscillators", "The number of oscillators",
60  UintegerValue (20),
61  MakeUintegerAccessor (&JakesProcess::SetNOscillators),
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 
75  NS_ASSERT (m_omegaDopplerMax != 0);
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 * JakesPropagationLossModel::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 oscillatoer:
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 * JakesPropagationLossModel::PI * n - JakesPropagationLossModel::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
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
virtual ~JakesProcess()
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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:274
NS_LOG_COMPONENT_DEFINE("JakesProcess")
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].
std::complex< double > GetComplexGain() const
void SetDopplerFrequencyHz(double dopplerFrequencyHz)
unsigned int m_nOscillators
Definition: jakes-process.h:91
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
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:63
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:611
void SetNOscillators(unsigned int nOscillators)
Implementation for a single path Stationary Jakes propagation loss model.
Definition: jakes-process.h:55