satellite-loo-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 
21 #include "satellite-loo-model.h"
22 
23 #include "satellite-utils.h"
24 
25 #include <ns3/log.h>
26 
27 NS_LOG_COMPONENT_DEFINE("SatLooModel");
28 
29 namespace ns3
30 {
31 
32 NS_OBJECT_ENSURE_REGISTERED(SatLooModel);
33 
34 TypeId
36 {
37  static TypeId tid =
38  TypeId("ns3::SatLooModel").SetParent<SatBaseFader>().AddConstructor<SatLooModel>();
39  return tid;
40 }
41 
43  : m_numOfStates(0),
44  m_currentSet(0),
45  m_currentState(0),
46  m_looConf(NULL),
47  m_normalRandomVariable(NULL),
48  m_uniformVariable(NULL)
49 {
50  NS_LOG_FUNCTION(this);
51 
52  NS_FATAL_ERROR("SatLooModel::SatLooModel - Constructor not in use");
53 }
54 
55 SatLooModel::SatLooModel(Ptr<SatLooConf> looConf,
56  uint32_t numOfStates,
57  uint32_t initialSet,
58  uint32_t initialState)
59  : m_numOfStates(numOfStates),
60  m_currentSet(initialSet),
61  m_currentState(initialState),
62  m_looConf(looConf),
63  m_normalRandomVariable(NULL),
64  m_uniformVariable(NULL)
65 {
66  NS_LOG_FUNCTION(this << numOfStates << " " << initialSet << " " << initialState);
67 
69  m_normalRandomVariable = CreateObject<NormalRandomVariable>();
70  m_uniformVariable = CreateObject<UniformRandomVariable>();
71  m_uniformVariable->SetAttribute("Min", DoubleValue(-1.0 * M_PI));
72  m_uniformVariable->SetAttribute("Max", DoubleValue(M_PI));
73 
76 }
77 
79 {
80  NS_LOG_FUNCTION(this);
81 
82  Reset();
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION(this);
89 
90  Reset();
91  SatBaseFader::DoDispose();
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION(this);
98 
99  m_looConf = NULL;
100  m_normalRandomVariable = NULL;
101  m_uniformVariable = NULL;
102 
103  if (!m_directSignalOscillators.empty())
104  {
105  for (uint32_t i = 0; i < m_numOfStates; i++)
106  {
107  if (!m_directSignalOscillators[i].empty())
108  {
109  m_directSignalOscillators[i].clear();
110  }
111  }
113  }
114 
115  if (!m_multipathOscillators.empty())
116  {
117  for (uint32_t i = 0; i < m_numOfStates; i++)
118  {
119  if (!m_multipathOscillators[i].empty())
120  {
121  m_multipathOscillators[i].clear();
122  }
123  }
124  m_multipathOscillators.clear();
125  }
126 
127  m_looParameters.clear();
128  m_sigma.clear();
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION(this);
135 
136  for (uint32_t i = 0; i < m_numOfStates; i++)
137  {
138  std::vector<Ptr<SatFadingOscillator>> oscillators;
139 
141  double phi = m_uniformVariable->GetValue();
143  double theta = m_uniformVariable->GetValue();
144  for (uint32_t j = 0; j < m_looParameters[i][3]; j++)
145  {
146  uint32_t n = j + 1;
150  double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_looParameters[i][3]);
152  double omega = 2.0 * M_PI * m_looParameters[i][5] * std::cos(alpha);
154 
160  double amplitude =
162  amplitude = pow(10, amplitude / 10) / m_looParameters[i][3];
163 
165  oscillators.push_back(CreateObject<SatFadingOscillator>(amplitude, phi, omega));
166  }
167  m_directSignalOscillators.push_back(oscillators);
168  }
169 }
170 
171 void
173 {
174  NS_LOG_FUNCTION(this);
175 
176  for (uint32_t i = 0; i < m_numOfStates; i++)
177  {
178  std::vector<Ptr<SatFadingOscillator>> oscillators;
179 
181  double phi = m_uniformVariable->GetValue();
183  double theta = m_uniformVariable->GetValue();
184  for (uint32_t j = 0; j < m_looParameters[i][4]; j++)
185  {
186  uint32_t n = j + 1;
190  double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_looParameters[i][4]);
192  double omega = 2.0 * M_PI * m_looParameters[i][6] * std::cos(alpha);
194  double psi = m_normalRandomVariable->GetValue();
195  std::complex<double> amplitude = std::complex<double>(std::cos(psi), std::sin(psi)) *
196  2.0 / std::sqrt(m_looParameters[i][4]);
198  oscillators.push_back(CreateObject<SatFadingOscillator>(amplitude, phi, omega));
199  }
200  m_multipathOscillators.push_back(oscillators);
201  }
202 }
203 
204 double
206 {
207  NS_LOG_FUNCTION(this);
208 
209  double tempChannelGainDb = 10.0 * std::log10(GetChannelGain());
210  NS_LOG_INFO("Channel gain: " << tempChannelGainDb);
211  return tempChannelGainDb;
212 }
213 
214 double
216 {
217  NS_LOG_FUNCTION(this);
218 
219  double timeInSeconds = Now().GetSeconds();
220 
222  std::complex<double> directComplexGain =
224 
226  std::complex<double> multipathComplexGain =
228  multipathComplexGain = multipathComplexGain * m_sigma[m_currentState];
229 
231  std::complex<double> fadingGain = directComplexGain + multipathComplexGain;
232  return sqrt((pow(fadingGain.real(), 2) + pow(fadingGain.imag(), 2)));
233 }
234 
235 std::complex<double>
236 SatLooModel::GetOscillatorCosineWaveSum(std::vector<Ptr<SatFadingOscillator>> oscillator,
237  double timeInSeconds)
238 {
239  NS_LOG_FUNCTION(this);
240 
241  std::complex<double> complexSum = std::complex<double>(0, 0);
242 
243  for (uint32_t i = 0; i < oscillator.size(); i++)
244  {
245  complexSum += oscillator[i]->GetCosineWaveValueAt(timeInSeconds);
246  }
247 
248  return complexSum;
249 }
250 
251 std::complex<double>
252 SatLooModel::GetOscillatorComplexSum(std::vector<Ptr<SatFadingOscillator>> oscillator,
253  double timeInSeconds)
254 {
255  NS_LOG_FUNCTION(this);
256 
257  std::complex<double> complexSum = std::complex<double>(0, 0);
258 
259  for (uint32_t i = 0; i < oscillator.size(); i++)
260  {
261  complexSum += oscillator[i]->GetComplexValueAt(timeInSeconds);
262  }
263 
264  return complexSum;
265 }
266 
267 void
268 SatLooModel::UpdateParameters(uint32_t newSet, uint32_t newState)
269 {
270  NS_LOG_FUNCTION(this << newSet << " " << newState);
271 
272  if (m_currentSet != newSet)
273  {
274  ChangeSet(newSet, newState);
275  }
276 
277  if (m_currentSet == newSet && m_currentState != newState)
278  {
279  ChangeState(newState);
280  }
281 }
282 
283 void
284 SatLooModel::ChangeSet(uint32_t newSet, uint32_t newState)
285 {
286  NS_LOG_FUNCTION(this << newSet << " " << newState);
287 
288  m_looParameters.clear();
289  m_looParameters = m_looConf->GetParameters(newSet);
290  m_currentSet = newSet;
291 
292  ChangeState(newState);
293 
294  if (!m_directSignalOscillators.empty())
295  {
296  for (uint32_t i = 0; i < m_numOfStates; i++)
297  {
298  if (!m_directSignalOscillators[i].empty())
299  {
300  m_directSignalOscillators[i].clear();
301  }
302  }
304  }
305 
306  if (!m_multipathOscillators.empty())
307  {
308  for (uint32_t i = 0; i < m_numOfStates; i++)
309  {
310  if (!m_multipathOscillators[i].empty())
311  {
312  m_multipathOscillators[i].clear();
313  }
314  }
315  m_multipathOscillators.clear();
316  }
317 
318  m_sigma.clear();
319 
322  CalculateSigma();
323 }
324 
325 void
326 SatLooModel::ChangeState(uint32_t newState)
327 {
328  NS_LOG_FUNCTION(this << newState);
329 
330  m_currentState = newState;
331 }
332 
333 void
335 {
336  NS_LOG_FUNCTION(this);
337 
338  for (uint32_t i = 0; i < m_numOfStates; i++)
339  {
340  m_sigma.push_back(sqrt(0.5 * pow(10, (m_looParameters[i][2] / 10))));
341  }
342 }
343 
344 } // namespace ns3
Base class for faders such as the Rayleigh fader.
double GetChannelGain()
Function for returning the channel gain.
double GetChannelGainDb()
Function for returning the channel gain in dB.
SatLooModel()
Constructor.
void ChangeState(uint32_t newState)
Function for setting the state.
void UpdateParameters(uint32_t set, uint32_t state)
Function for updating the parameter set and state.
Ptr< UniformRandomVariable > m_uniformVariable
Uniform distribution random variable.
std::vector< std::vector< double > > m_looParameters
Loo's model parameters.
std::complex< double > GetOscillatorComplexSum(std::vector< Ptr< SatFadingOscillator >> oscillator, double timeInSeconds)
Function for calculating oscillator complex sum.
uint32_t m_currentSet
Current parameter set.
std::complex< double > GetOscillatorCosineWaveSum(std::vector< Ptr< SatFadingOscillator >> oscillator, double timeInSeconds)
Function for calculating cosine wave oscillator complex sum.
void CalculateSigma()
Function for calculating sigma for different states.
uint32_t m_numOfStates
Number of states.
void ChangeSet(uint32_t newSet, uint32_t newState)
Function for setting the parameter set and state.
uint32_t m_currentState
Current state.
void Reset()
Clear used variables.
std::vector< std::vector< Ptr< SatFadingOscillator > > > m_multipathOscillators
Multipath oscillators.
void ConstructMultipathOscillators()
Function for constructing multipath oscillators.
std::vector< double > m_sigma
Multipath power converted to linear units.
~SatLooModel()
Destructor.
void ConstructDirectSignalOscillators()
Function for constructing direct signal oscillators.
Ptr< NormalRandomVariable > m_normalRandomVariable
Normal distribution random variable.
void DoDispose()
Do needed dispose actions.
std::vector< std::vector< Ptr< SatFadingOscillator > > > m_directSignalOscillators
Direct signal oscillators.
static TypeId GetTypeId(void)
NS-3 function for type id.
Ptr< SatLooConf > m_looConf
Loo's model configuration object.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.