Loading...
Searching...
No Matches
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 <cmath>
27#include <math.h>
28#include <numeric>
29#include <stdint.h>
30#include <utility>
31
32NS_LOG_COMPONENT_DEFINE("SatCnoEstimator");
33
34namespace ns3
35{
36
37// interface class for C/N0 estimators
38
39// static uint32_t pair_add (uint32_t i, const std::pair<Time, uint32_t>& x)
40//{
41// return i + x.second;
42// }
43
45{
46 NS_LOG_FUNCTION(this);
47}
48
50{
51 NS_LOG_FUNCTION(this);
52}
53
54void
56{
57 NS_LOG_FUNCTION(this << sample);
58
59 DoAddSample(sample);
60}
61
62double
64{
65 NS_LOG_FUNCTION(this);
66
67 return DoGetCnoEstimation();
68}
69
70// class for Basic C/N0 estimator
71
73 : m_mode(LAST)
74{
75 NS_LOG_FUNCTION(this);
76}
77
79 : m_window(window),
80 m_mode(mode)
81
82{
83 NS_LOG_FUNCTION(this);
84}
85
87{
88 NS_LOG_FUNCTION(this);
89}
90
91void
93{
94 NS_LOG_FUNCTION(this << sample);
95
96 switch (m_mode)
97 {
98 case LAST:
99 m_samples.clear();
100 m_samples.insert(std::make_pair(Simulator::Now(), sample));
101 break;
102
103 case MINIMUM:
105 m_samples.insert(std::make_pair(Simulator::Now(), sample));
106 break;
107
108 case AVERAGE:
110 m_samples.insert(std::make_pair(Simulator::Now(), sample));
111 break;
112
113 default:
114 NS_FATAL_ERROR("Not supported estimation mode!!!");
115 break;
116 }
117}
118
119double
121{
122 NS_LOG_FUNCTION(this);
123
124 double estimatedCno = NAN;
125
127
128 if (m_samples.empty() == false)
129 {
130 switch (m_mode)
131 {
132 case LAST:
133 estimatedCno = m_samples.begin()->second;
134 break;
135
136 case MINIMUM:
137 for (SampleMap_t::const_iterator it = m_samples.begin(); it != m_samples.end(); it++)
138 {
139 if (std::isnan(estimatedCno) ||
140 ((!std::isnan(it->second)) && (it->second < estimatedCno)))
141 {
142 estimatedCno = it->second;
143 }
144 }
145 break;
146
147 case AVERAGE:
148 estimatedCno = std::accumulate(m_samples.begin(),
149 m_samples.end(),
150 0.0,
152 m_samples.size();
153 break;
154
155 default:
156 NS_FATAL_ERROR("Not supported estimation mode!!!");
157 break;
158 }
159 }
160
161 return estimatedCno;
162}
163
164void
166{
167 NS_LOG_FUNCTION(this);
168 SampleMap_t::iterator itLastValid = m_samples.lower_bound(Simulator::Now() - m_window);
169
170 m_samples.erase(m_samples.begin(), itLastValid);
171}
172
173} // 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.