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 #include <cmath>
26 #include <complex>
27 
28 namespace ns3
29 {
30 
31 NS_OBJECT_ENSURE_REGISTERED(SatRayleighModel);
32 NS_LOG_COMPONENT_DEFINE("SatRayleighModel");
33 
34 TypeId
36 {
37  static TypeId tid = TypeId("ns3::SatRayleighModel")
38  .SetParent<SatBaseFader>()
39  .AddConstructor<SatRayleighModel>();
40  return tid;
41 }
42 
44  : m_currentSet(),
45  m_currentState(),
46  m_rayleighConf()
47 {
48  NS_LOG_FUNCTION(this);
49 
50  NS_FATAL_ERROR("SatRayleighModel - Constructor not in use");
51 }
52 
53 SatRayleighModel::SatRayleighModel(Ptr<SatRayleighConf> rayleighConf,
54  uint32_t initialSet,
55  uint32_t initialState)
56  : m_currentSet(initialSet),
57  m_currentState(initialState),
58  m_rayleighConf(rayleighConf)
59 {
60  NS_LOG_FUNCTION(this);
61 
62  m_uniformVariable = CreateObject<UniformRandomVariable>();
63  m_uniformVariable->SetAttribute("Min", DoubleValue(-1.0 * M_PI));
64  m_uniformVariable->SetAttribute("Max", DoubleValue(M_PI));
65 
67 
69 }
70 
72 {
73  NS_LOG_FUNCTION(this);
74 
75  Reset();
76 }
77 
78 void
80 {
81  NS_LOG_FUNCTION(this);
82 
83  Reset();
84  SatBaseFader::DoDispose();
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION(this);
91 
92  m_rayleighConf = nullptr;
93  m_oscillators.clear();
94  m_uniformVariable = nullptr;
95 }
96 
97 void
99 {
100  NS_LOG_FUNCTION(this);
101 
103  double phi = m_uniformVariable->GetValue();
105  double theta = m_uniformVariable->GetValue();
106  for (uint32_t i = 0; i < m_rayleighParameters[0][1]; i++)
107  {
108  uint32_t n = i + 1;
112  double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_rayleighParameters[0][1]);
114  double omega = 2.0 * m_rayleighParameters[0][0] * M_PI * std::cos(alpha);
116  double psi = m_uniformVariable->GetValue();
117  std::complex<double> amplitude = std::complex<double>(std::cos(psi), std::sin(psi)) * 2.0 /
118  std::sqrt(m_rayleighParameters[0][1]);
120  m_oscillators.push_back(CreateObject<SatFadingOscillator>(amplitude, phi, omega));
121  }
122 }
123 
124 std::complex<double>
126 {
127  NS_LOG_FUNCTION(this);
128 
129  double timeInSeconds = Now().GetSeconds();
130 
131  std::complex<double> sumAmplitude = std::complex<double>(0, 0);
132  for (uint32_t i = 0; i < m_oscillators.size(); i++)
133  {
134  sumAmplitude += m_oscillators[i]->GetComplexValueAt(timeInSeconds);
135  }
136  return sumAmplitude;
137 }
138 
139 double
141 {
142  NS_LOG_FUNCTION(this);
143 
144  std::complex<double> complexGain = GetComplexGain();
145  double tempChannelGainDb =
146  (10 * std::log10((std::pow(complexGain.real(), 2) + std::pow(complexGain.imag(), 2)) / 2));
147  NS_LOG_INFO("Computed channel gain: " << tempChannelGainDb);
148  return tempChannelGainDb;
149 }
150 
151 double
153 {
154  NS_LOG_FUNCTION(this);
155 
156  std::complex<double> complexGain = GetComplexGain();
157 
158  double tempChannelGain =
159  ((std::pow(complexGain.real(), 2) + std::pow(complexGain.imag(), 2)) / 2);
160  NS_LOG_INFO("Computed channel gain: " << tempChannelGain);
161  return tempChannelGain;
162 }
163 
164 void
165 SatRayleighModel::UpdateParameters(uint32_t newSet, uint32_t newState)
166 {
167  NS_LOG_FUNCTION(this << newSet << " " << newState);
168  m_currentSet = newSet;
169  m_currentState = newState;
170 }
171 
172 } // 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.