21 #include "jakes-process.h"
22 #include "ns3/simulator.h"
23 #include "ns3/double.h"
25 #include "ns3/uinteger.h"
26 #include "propagation-loss-model.h"
27 #include "jakes-propagation-loss-model.h"
35 m_amplitude (amplitude),
36 m_phase (initialPhase),
41 JakesProcess::Oscillator::GetValueAt (
Time at)
const
43 return (m_amplitude * std::cos (at.
GetSeconds () * m_omega + m_phase));
49 JakesProcess::GetTypeId ()
53 .AddConstructor<JakesProcess> ()
54 .AddAttribute (
"DopplerFrequencyHz",
"Corresponding doppler frequency[Hz]",
56 MakeDoubleAccessor (&JakesProcess::SetDopplerFrequencyHz),
57 MakeDoubleChecker<double> (0.0, 1e4))
58 .AddAttribute (
"NumberOfOscillators",
"The number of oscillators",
60 MakeUintegerAccessor (&JakesProcess::SetNOscillators),
61 MakeUintegerChecker<unsigned int> (4, 1000))
67 JakesProcess::SetPropagationLossModel (Ptr<const PropagationLossModel> propagationModel)
69 Ptr<const JakesPropagationLossModel> jakes = propagationModel->GetObject<JakesPropagationLossModel> ();
70 NS_ASSERT_MSG (jakes != 0,
"Jakes Process can work only with JakesPropagationLossModel!");
80 JakesProcess::SetNOscillators (
unsigned int nOscillators)
82 m_nOscillators = nOscillators;
86 JakesProcess::SetDopplerFrequencyHz (
double dopplerFrequencyHz)
88 m_omegaDopplerMax = 2 * dopplerFrequencyHz * JakesPropagationLossModel::PI;
96 double phi = m_jakes->GetUniformRandomVariable ()->GetValue ();
98 double theta = m_jakes->GetUniformRandomVariable ()->GetValue ();
99 for (
unsigned int i = 0; i < m_nOscillators; i++)
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));
115 JakesProcess::JakesProcess () :
116 m_omegaDopplerMax (0),
121 JakesProcess::~JakesProcess()
123 m_oscillators.clear ();
133 JakesProcess::GetComplexGain ()
const
135 std::complex<double> sumAplitude = std::complex<double> (0, 0);
136 for (
unsigned int i = 0; i < m_oscillators.size (); i++)
138 sumAplitude += m_oscillators[i].GetValueAt (
Now ());
146 std::complex<double> complexGain = GetComplexGain ();
147 return (10 * std::log10 ((std::pow (complexGain.real (), 2) + std::pow (complexGain.imag (), 2)) / 2));
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
double GetSeconds(void) const
Represents a single oscillator.
Oscillator(std::complex< double > amplitude, double initialPhase, double omega)
Initiate oscillator with complex amplitude, initial phase and rotation speed.
Hold an unsigned integer type.
double GetChannelGainDb() const
Get Channel gain [dB].
#define NS_ASSERT_MSG(condition, message)
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
void ConstructOscillators()
a base class which provides memory management and object aggregation
Hold an floating point type.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Implementation for a single path Stationary Jakes propagation loss model.