satellite-residual-interference-elimination.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 CNES
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: Mathias Ettinger <mettinger@toulouse.viveris.com>
19  */
20 
22 
24 #include "satellite-utils.h"
25 
26 #include <ns3/double.h>
27 #include <ns3/log.h>
28 #include <ns3/simulator.h>
29 
30 #include <cmath>
31 #include <limits>
32 #include <utility>
33 #include <vector>
34 
35 NS_LOG_COMPONENT_DEFINE("SatResidualInterferenceElimination");
36 
37 namespace ns3
38 {
39 
40 NS_OBJECT_ENSURE_REGISTERED(SatResidualInterferenceElimination);
41 
42 TypeId
44 {
45  static TypeId tid =
46  TypeId("ns3::SatResidualInterferenceElimination")
47  .SetParent<SatInterferenceElimination>()
48  .AddConstructor<SatResidualInterferenceElimination>()
49  .AddAttribute(
50  "SamplingError",
51  "Residual sampling error corresponding to E[g(τ)]/g(0) for the simulation",
52  DoubleValue(0.99),
54  MakeDoubleChecker<double>());
55 
56  return tid;
57 }
58 
59 TypeId
61 {
62  return GetTypeId();
63 }
64 
67  m_waveformConf(0),
68  m_samplingError(0.99)
69 {
70  NS_LOG_FUNCTION(this);
71 
72  NS_FATAL_ERROR("SatPhy default constructor is not allowed to use");
73 }
74 
76  Ptr<SatWaveformConf> waveformConf)
78  m_waveformConf(waveformConf),
79  m_samplingError(0.99)
80 {
81  NS_LOG_FUNCTION(this);
82 }
83 
85 {
86  NS_LOG_FUNCTION(this);
87 }
88 
89 void
91  Ptr<SatSignalParameters> packetInterferedWith,
92  Ptr<SatSignalParameters> processedPacket,
93  double EsNo,
94  bool isRegenerative)
95 {
96  NS_LOG_FUNCTION(this);
97 
98  return EliminateInterferences(packetInterferedWith,
99  processedPacket,
100  EsNo,
101  isRegenerative,
102  0.0,
103  1.0);
104 }
105 
106 void
108  Ptr<SatSignalParameters> packetInterferedWith,
109  Ptr<SatSignalParameters> processedPacket,
110  double EsNo,
111  bool isRegenerative,
112  double startTime,
113  double endTime)
114 {
115  NS_LOG_FUNCTION(this);
116 
117  NS_LOG_INFO("Removing interference power of packet from Beam[Carrier] "
118  << processedPacket->m_beamId << "[" << processedPacket->m_carrierId << "] between "
119  << startTime << " and " << endTime);
120  double oldIfPower;
121  double ifPowerToRemove;
124  double residualPower = GetResidualPower(processedPacket, EsNo);
125  double normalizedTime = 0.0;
126  std::vector<std::pair<double, double>> ifPowerPerFragment;
127 
128  if (isRegenerative)
129  {
130  oldIfPower = packetInterferedWith->GetInterferencePower();
131  ifPowerToRemove = processedPacket->m_rxPower_W;
132  ifPowerPerFragment = packetInterferedWith->GetInterferencePowerPerFragment();
133  }
134  else
135  {
136  oldIfPower = packetInterferedWith->GetInterferencePowerInSatellite();
137  ifPowerToRemove = processedPacket->GetRxPowerInSatellite();
138  ifPowerPerFragment = packetInterferedWith->GetInterferencePowerInSatellitePerFragment();
139  }
140 
141  for (std::pair<double, double>& ifPower : ifPowerPerFragment)
142  {
143  normalizedTime += ifPower.first;
144  if (startTime >= normalizedTime)
145  {
146  continue;
147  }
148  else if (endTime < normalizedTime)
149  {
150  break;
151  }
152 
153  ifPower.second -= ifPowerToRemove;
154  ifPower.second += residualPower;
155  if (std::abs(ifPower.second) < 1.0e-30) // std::numeric_limits<double>::epsilon ())
156  {
157  ifPower.second = 0.0;
158  }
159 
160  if (ifPower.second < 0)
161  {
162  NS_FATAL_ERROR("Negative interference");
163  }
164  }
165 
166  if (isRegenerative)
167  {
168  packetInterferedWith->SetInterferencePower(ifPowerPerFragment);
169  }
170  else
171  {
172  packetInterferedWith->SetInterferencePowerInSatellite(ifPowerPerFragment);
173  }
174 
175  NS_LOG_INFO("Interfered packet ifPower went from "
176  << oldIfPower << " to " << SatUtils::ScalarProduct(ifPowerPerFragment));
177 }
178 
179 double
180 SatResidualInterferenceElimination::GetResidualPower(Ptr<SatSignalParameters> processedPacket,
181  double EsNo)
182 {
183  NS_LOG_FUNCTION(this);
184 
185  NS_LOG_INFO("SatResidualInterferenceElimination::GetResidualPower");
186 
187  double ifPowerToRemove = processedPacket->GetRxPowerInSatellite();
188  uint32_t L = GetBurstLengthInSymbols(processedPacket->m_txInfo.waveformId);
189  double sigma_lambda_2 = 1.0 / (8.0 * L * EsNo);
190  double sigma_phy_2 = 1.0 / (2.0 * L * EsNo);
191  return (2.0 + sigma_lambda_2 - (2.0 * m_samplingError * std::exp(-sigma_phy_2 / 2.0))) *
192  ifPowerToRemove;
193 }
194 
195 } // namespace ns3
Abstract class defining interface for interference elimination calculation objects.
void EliminateInterferences(Ptr< SatSignalParameters > packetInterferedWith, Ptr< SatSignalParameters > processedPacket, double EsNo, bool isRegenerative)
Eliminate the residual power of interference for the given packets.
double GetResidualPower(Ptr< SatSignalParameters > processedPacket, double EsNo)
Calculate the residual power of interference for a given packet.
static double ScalarProduct(const std::vector< std::pair< double, double >> &vector)
Scalar product.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.