satellite-rayleigh-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
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: Frans Laakso <frans.laakso@magister.fi>
19  */
20 
22 
23 #include <ns3/log.h>
24 
25 namespace ns3
26 {
27 
28 NS_OBJECT_ENSURE_REGISTERED(SatRayleighModel);
29 NS_LOG_COMPONENT_DEFINE("SatRayleighModel");
30 
31 TypeId
33 {
34  static TypeId tid = TypeId("ns3::SatRayleighModel")
35  .SetParent<SatBaseFader>()
36  .AddConstructor<SatRayleighModel>();
37  return tid;
38 }
39 
41  : m_currentSet(),
42  m_currentState(),
43  m_rayleighConf()
44 {
45  NS_LOG_FUNCTION(this);
46 
47  NS_FATAL_ERROR("SatRayleighModel - Constructor not in use");
48 }
49 
50 SatRayleighModel::SatRayleighModel(Ptr<SatRayleighConf> rayleighConf,
51  uint32_t initialSet,
52  uint32_t initialState)
53  : m_currentSet(initialSet),
54  m_currentState(initialState),
55  m_rayleighConf(rayleighConf)
56 {
57  NS_LOG_FUNCTION(this);
58 
59  m_uniformVariable = CreateObject<UniformRandomVariable>();
60  m_uniformVariable->SetAttribute("Min", DoubleValue(-1.0 * M_PI));
61  m_uniformVariable->SetAttribute("Max", DoubleValue(M_PI));
62 
64 
66 }
67 
69 {
70  NS_LOG_FUNCTION(this);
71 
72  Reset();
73 }
74 
75 void
77 {
78  NS_LOG_FUNCTION(this);
79 
80  Reset();
81  SatBaseFader::DoDispose();
82 }
83 
84 void
86 {
87  NS_LOG_FUNCTION(this);
88 
89  m_rayleighConf = NULL;
90  m_oscillators.clear();
91  m_uniformVariable = NULL;
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION(this);
98 
100  double phi = m_uniformVariable->GetValue();
102  double theta = m_uniformVariable->GetValue();
103  for (uint32_t i = 0; i < m_rayleighParameters[0][1]; i++)
104  {
105  uint32_t n = i + 1;
109  double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_rayleighParameters[0][1]);
111  double omega = 2.0 * m_rayleighParameters[0][0] * M_PI * std::cos(alpha);
113  double psi = m_uniformVariable->GetValue();
114  std::complex<double> amplitude = std::complex<double>(std::cos(psi), std::sin(psi)) * 2.0 /
115  std::sqrt(m_rayleighParameters[0][1]);
117  m_oscillators.push_back(CreateObject<SatFadingOscillator>(amplitude, phi, omega));
118  }
119 }
120 
121 std::complex<double>
123 {
124  NS_LOG_FUNCTION(this);
125 
126  double timeInSeconds = Now().GetSeconds();
127 
128  std::complex<double> sumAmplitude = std::complex<double>(0, 0);
129  for (uint32_t i = 0; i < m_oscillators.size(); i++)
130  {
131  sumAmplitude += m_oscillators[i]->GetComplexValueAt(timeInSeconds);
132  }
133  return sumAmplitude;
134 }
135 
136 double
138 {
139  NS_LOG_FUNCTION(this);
140 
141  std::complex<double> complexGain = GetComplexGain();
142  double tempChannelGainDb =
143  (10 * std::log10((std::pow(complexGain.real(), 2) + std::pow(complexGain.imag(), 2)) / 2));
144  NS_LOG_INFO("Computed channel gain: " << tempChannelGainDb);
145  return tempChannelGainDb;
146 }
147 
148 double
150 {
151  NS_LOG_FUNCTION(this);
152 
153  std::complex<double> complexGain = GetComplexGain();
154 
155  double tempChannelGain =
156  ((std::pow(complexGain.real(), 2) + std::pow(complexGain.imag(), 2)) / 2);
157  NS_LOG_INFO("Computed channel gain: " << tempChannelGain);
158  return tempChannelGain;
159 }
160 
161 void
162 SatRayleighModel::UpdateParameters(uint32_t newSet, uint32_t newState)
163 {
164  NS_LOG_FUNCTION(this << newSet << " " << newState);
165  m_currentSet = newSet;
166  m_currentState = newState;
167 }
168 
169 } // namespace ns3
Base class for faders such as the Rayleigh fader.
Ptr< SatRayleighConf > m_rayleighConf
Rayleigh configuration object.
uint32_t m_currentSet
Current parameter set.
uint32_t m_currentState
Current state.
std::vector< Ptr< SatFadingOscillator > > m_oscillators
Vector of oscillators.
void DoDispose()
Do needed dispose actions.
void UpdateParameters(uint32_t set, uint32_t state)
Function for updating the parameter set and state.
std::vector< std::vector< double > > m_rayleighParameters
Rayleigh model parameters.
double GetChannelGainDb()
Function for returning the channel gain in dB.
void Reset()
Clear used variables.
Ptr< UniformRandomVariable > m_uniformVariable
Uniform distribution random variable.
void ConstructOscillators()
Function for constructing the oscillators.
static TypeId GetTypeId(void)
NS-3 function for type id.
double GetChannelGain()
Function for returning the channel gain.
std::complex< double > GetComplexGain()
Function for calculating the oscillator complex gain.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.