satellite-cno-estimator.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
22 
23 #include <ns3/log.h>
24 #include <ns3/simulator.h>
25 
26 #include <math.h>
27 #include <numeric>
28 
29 NS_LOG_COMPONENT_DEFINE("SatCnoEstimator");
30 
31 namespace ns3
32 {
33 
34 // interface class for C/N0 estimators
35 
36 // static uint32_t pair_add (uint32_t i, const std::pair<Time, uint32_t>& x)
37 //{
38 // return i + x.second;
39 // }
40 
42 {
43  NS_LOG_FUNCTION(this);
44 }
45 
47 {
48  NS_LOG_FUNCTION(this);
49 }
50 
51 void
53 {
54  NS_LOG_FUNCTION(this << sample);
55 
56  DoAddSample(sample);
57 }
58 
59 double
61 {
62  NS_LOG_FUNCTION(this);
63 
64  return DoGetCnoEstimation();
65 }
66 
67 // class for Basic C/N0 estimator
68 
70  : m_mode(LAST)
71 {
72  NS_LOG_FUNCTION(this);
73 }
74 
76  : m_window(window),
77  m_mode(mode)
78 
79 {
80  NS_LOG_FUNCTION(this);
81 }
82 
84 {
85  NS_LOG_FUNCTION(this);
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION(this << sample);
92 
93  switch (m_mode)
94  {
95  case LAST:
96  m_samples.clear();
97  m_samples.insert(std::make_pair(Simulator::Now(), sample));
98  break;
99 
100  case MINIMUM:
102  m_samples.insert(std::make_pair(Simulator::Now(), sample));
103  break;
104 
105  case AVERAGE:
107  m_samples.insert(std::make_pair(Simulator::Now(), sample));
108  break;
109 
110  default:
111  NS_FATAL_ERROR("Not supported estimation mode!!!");
112  break;
113  }
114 }
115 
116 double
118 {
119  NS_LOG_FUNCTION(this);
120 
121  double estimatedCno = NAN;
122 
124 
125  if (m_samples.empty() == false)
126  {
127  switch (m_mode)
128  {
129  case LAST:
130  estimatedCno = m_samples.begin()->second;
131  break;
132 
133  case MINIMUM:
134  for (SampleMap_t::const_iterator it = m_samples.begin(); it != m_samples.end(); it++)
135  {
136  if (std::isnan(estimatedCno) ||
137  ((!std::isnan(it->second)) && (it->second < estimatedCno)))
138  {
139  estimatedCno = it->second;
140  }
141  }
142  break;
143 
144  case AVERAGE:
145  estimatedCno = std::accumulate(m_samples.begin(),
146  m_samples.end(),
147  0.0,
149  m_samples.size();
150  break;
151 
152  default:
153  NS_FATAL_ERROR("Not supported estimation mode!!!");
154  break;
155  }
156  }
157 
158  return estimatedCno;
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION(this);
165  SampleMap_t::iterator itLastValid = m_samples.lower_bound(Simulator::Now() - m_window);
166 
167  m_samples.erase(m_samples.begin(), itLastValid);
168 }
169 
170 } // namespace ns3
void ClearOutdatedSamples()
Clear outdated samples from storage.
static double AddToSum(double currentSum, const std::pair< Time, double > &sample)
Method to add a sample value to current sum.
virtual void DoAddSample(double cno)
Add a C/N0 sample to estimator.
SatBasicCnoEstimator()
Default construct a SatCnoEstimator.
~SatBasicCnoEstimator()
Destroy a SatCnoEstimator.
virtual double DoGetCnoEstimation()
Estimate C/N0 value of the samples in window.
double GetCnoEstimation()
Estimate C/N0 value of the samples.
virtual void DoAddSample(double cno)=0
Add a C/N0 sample to estimator.
virtual double DoGetCnoEstimation()=0
Estimate C/N0 value of the samples.
EstimationMode_t
Definition of modes for estimator.
@ MINIMUM
Minimum value in the given window returned.
@ LAST
Last value in the given window returned.
@ AVERAGE
Average value in the given window returned.
virtual ~SatCnoEstimator()
Destroy a SatCnoEstimator.
void AddSample(double cno)
Add a C/N0 sample to estimator.
SatCnoEstimator()
Default construct a SatCnoEstimator.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.