Loading...
Searching...
No Matches
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#include <cmath>
28#include <complex>
29#include <vector>
30
31NS_LOG_COMPONENT_DEFINE("SatLooModel");
32
33namespace ns3
34{
35
36NS_OBJECT_ENSURE_REGISTERED(SatLooModel);
37
38TypeId
40{
41 static TypeId tid =
42 TypeId("ns3::SatLooModel").SetParent<SatBaseFader>().AddConstructor<SatLooModel>();
43 return tid;
44}
45
47 : m_numOfStates(0),
48 m_currentSet(0),
50 m_looConf(nullptr),
52 m_uniformVariable(nullptr)
53{
54 NS_LOG_FUNCTION(this);
55
56 NS_FATAL_ERROR("SatLooModel::SatLooModel - Constructor not in use");
57}
58
59SatLooModel::SatLooModel(Ptr<SatLooConf> looConf,
60 uint32_t numOfStates,
61 uint32_t initialSet,
62 uint32_t initialState)
63 : m_numOfStates(numOfStates),
64 m_currentSet(initialSet),
65 m_currentState(initialState),
66 m_looConf(looConf),
68 m_uniformVariable(nullptr)
69{
70 NS_LOG_FUNCTION(this << numOfStates << " " << initialSet << " " << initialState);
71
73 m_normalRandomVariable = CreateObject<NormalRandomVariable>();
74 m_uniformVariable = CreateObject<UniformRandomVariable>();
75 m_uniformVariable->SetAttribute("Min", DoubleValue(-1.0 * M_PI));
76 m_uniformVariable->SetAttribute("Max", DoubleValue(M_PI));
77
80}
81
83{
84 NS_LOG_FUNCTION(this);
85
86 Reset();
87}
88
89void
91{
92 NS_LOG_FUNCTION(this);
93
94 Reset();
95 SatBaseFader::DoDispose();
96}
97
98void
100{
101 NS_LOG_FUNCTION(this);
102
103 m_looConf = nullptr;
104 m_normalRandomVariable = nullptr;
105 m_uniformVariable = nullptr;
106
107 if (!m_directSignalOscillators.empty())
108 {
109 for (uint32_t i = 0; i < m_numOfStates; i++)
110 {
111 if (!m_directSignalOscillators[i].empty())
112 {
113 m_directSignalOscillators[i].clear();
114 }
115 }
117 }
118
119 if (!m_multipathOscillators.empty())
120 {
121 for (uint32_t i = 0; i < m_numOfStates; i++)
122 {
123 if (!m_multipathOscillators[i].empty())
124 {
125 m_multipathOscillators[i].clear();
126 }
127 }
129 }
130
131 m_looParameters.clear();
132 m_sigma.clear();
133}
134
135void
137{
138 NS_LOG_FUNCTION(this);
139
140 for (uint32_t i = 0; i < m_numOfStates; i++)
141 {
142 std::vector<Ptr<SatFadingOscillator>> oscillators;
143
145 double phi = m_uniformVariable->GetValue();
147 double theta = m_uniformVariable->GetValue();
148 for (uint32_t j = 0; j < m_looParameters[i][3]; j++)
149 {
150 uint32_t n = j + 1;
154 double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_looParameters[i][3]);
156 double omega = 2.0 * M_PI * m_looParameters[i][5] * std::cos(alpha);
158
164 double amplitude =
166 amplitude = pow(10, amplitude / 10) / m_looParameters[i][3];
167
169 oscillators.push_back(CreateObject<SatFadingOscillator>(amplitude, phi, omega));
170 }
171 m_directSignalOscillators.push_back(oscillators);
172 }
173}
174
175void
177{
178 NS_LOG_FUNCTION(this);
179
180 for (uint32_t i = 0; i < m_numOfStates; i++)
181 {
182 std::vector<Ptr<SatFadingOscillator>> oscillators;
183
185 double phi = m_uniformVariable->GetValue();
187 double theta = m_uniformVariable->GetValue();
188 for (uint32_t j = 0; j < m_looParameters[i][4]; j++)
189 {
190 uint32_t n = j + 1;
194 double alpha = (2.0 * M_PI * n - M_PI + theta) / (4.0 * m_looParameters[i][4]);
196 double omega = 2.0 * M_PI * m_looParameters[i][6] * std::cos(alpha);
198 double psi = m_normalRandomVariable->GetValue();
199 std::complex<double> amplitude = std::complex<double>(std::cos(psi), std::sin(psi)) *
200 2.0 / std::sqrt(m_looParameters[i][4]);
202 oscillators.push_back(CreateObject<SatFadingOscillator>(amplitude, phi, omega));
203 }
204 m_multipathOscillators.push_back(oscillators);
205 }
206}
207
208double
210{
211 NS_LOG_FUNCTION(this);
212
213 double tempChannelGainDb = 10.0 * std::log10(GetChannelGain());
214 NS_LOG_INFO("Channel gain: " << tempChannelGainDb);
215 return tempChannelGainDb;
216}
217
218double
220{
221 NS_LOG_FUNCTION(this);
222
223 double timeInSeconds = Now().GetSeconds();
224
226 std::complex<double> directComplexGain =
228
230 std::complex<double> multipathComplexGain =
232 multipathComplexGain = multipathComplexGain * m_sigma[m_currentState];
233
235 std::complex<double> fadingGain = directComplexGain + multipathComplexGain;
236 return sqrt((pow(fadingGain.real(), 2) + pow(fadingGain.imag(), 2)));
237}
238
239std::complex<double>
240SatLooModel::GetOscillatorCosineWaveSum(std::vector<Ptr<SatFadingOscillator>> oscillator,
241 double timeInSeconds)
242{
243 NS_LOG_FUNCTION(this);
244
245 std::complex<double> complexSum = std::complex<double>(0, 0);
246
247 for (uint32_t i = 0; i < oscillator.size(); i++)
248 {
249 complexSum += oscillator[i]->GetCosineWaveValueAt(timeInSeconds);
250 }
251
252 return complexSum;
253}
254
255std::complex<double>
256SatLooModel::GetOscillatorComplexSum(std::vector<Ptr<SatFadingOscillator>> oscillator,
257 double timeInSeconds)
258{
259 NS_LOG_FUNCTION(this);
260
261 std::complex<double> complexSum = std::complex<double>(0, 0);
262
263 for (uint32_t i = 0; i < oscillator.size(); i++)
264 {
265 complexSum += oscillator[i]->GetComplexValueAt(timeInSeconds);
266 }
267
268 return complexSum;
269}
270
271void
272SatLooModel::UpdateParameters(uint32_t newSet, uint32_t newState)
273{
274 NS_LOG_FUNCTION(this << newSet << " " << newState);
275
276 if (m_currentSet != newSet)
277 {
278 ChangeSet(newSet, newState);
279 }
280
281 if (m_currentSet == newSet && m_currentState != newState)
282 {
283 ChangeState(newState);
284 }
285}
286
287void
288SatLooModel::ChangeSet(uint32_t newSet, uint32_t newState)
289{
290 NS_LOG_FUNCTION(this << newSet << " " << newState);
291
292 m_looParameters.clear();
293 m_looParameters = m_looConf->GetParameters(newSet);
294 m_currentSet = newSet;
295
296 ChangeState(newState);
297
298 if (!m_directSignalOscillators.empty())
299 {
300 for (uint32_t i = 0; i < m_numOfStates; i++)
301 {
302 if (!m_directSignalOscillators[i].empty())
303 {
304 m_directSignalOscillators[i].clear();
305 }
306 }
308 }
309
310 if (!m_multipathOscillators.empty())
311 {
312 for (uint32_t i = 0; i < m_numOfStates; i++)
313 {
314 if (!m_multipathOscillators[i].empty())
315 {
316 m_multipathOscillators[i].clear();
317 }
318 }
320 }
321
322 m_sigma.clear();
323
327}
328
329void
330SatLooModel::ChangeState(uint32_t newState)
331{
332 NS_LOG_FUNCTION(this << newState);
333
334 m_currentState = newState;
335}
336
337void
339{
340 NS_LOG_FUNCTION(this);
341
342 for (uint32_t i = 0; i < m_numOfStates; i++)
343 {
344 m_sigma.push_back(sqrt(0.5 * pow(10, (m_looParameters[i][2] / 10))));
345 }
346}
347
348} // namespace ns3
Class for Loo's model 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.
uint32_t m_currentSet
Current parameter set.
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.
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.
std::complex< double > GetOscillatorCosineWaveSum(std::vector< Ptr< SatFadingOscillator > > oscillator, double timeInSeconds)
Function for calculating cosine wave oscillator complex sum.
static TypeId GetTypeId(void)
NS-3 function for type id.
std::complex< double > GetOscillatorComplexSum(std::vector< Ptr< SatFadingOscillator > > oscillator, double timeInSeconds)
Function for calculating oscillator complex sum.
Ptr< SatLooConf > m_looConf
Loo's model configuration object.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.