A Discrete-Event Network Simulator
API
friis-spectrum-propagation-loss.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 CTTC
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Nicola Baldo <nbaldo@cttc.es>
18  */
19 
21 
23 
24 #include <ns3/mobility-model.h>
25 
26 #include <cmath> // for M_PI
27 
28 namespace ns3
29 {
30 
31 NS_OBJECT_ENSURE_REGISTERED(FriisSpectrumPropagationLossModel);
32 
34 {
35 }
36 
38 {
39 }
40 
41 TypeId
43 {
44  static TypeId tid = TypeId("ns3::FriisSpectrumPropagationLossModel")
46  .SetGroupName("Spectrum")
47  .AddConstructor<FriisSpectrumPropagationLossModel>();
48  return tid;
49 }
50 
56 {
57  Ptr<SpectrumValue> rxPsd = Copy<SpectrumValue>(params->psd);
58  auto vit = rxPsd->ValuesBegin();
59  auto fit = rxPsd->ConstBandsBegin();
60 
61  NS_ASSERT(a);
62  NS_ASSERT(b);
63 
64  double d = a->GetDistanceFrom(b);
65 
66  while (vit != rxPsd->ValuesEnd())
67  {
68  NS_ASSERT(fit != rxPsd->ConstBandsEnd());
69  *vit /= CalculateLoss(fit->fc, d); // Prx = Ptx / loss
70  ++vit;
71  ++fit;
72  }
73  return rxPsd;
74 }
75 
76 double
78 {
79  NS_ASSERT(d >= 0);
80 
81  if (d == 0)
82  {
83  return 1;
84  }
85 
86  NS_ASSERT(f > 0);
87  double loss_sqrt = (4 * M_PI * f * d) / 3e8;
88  double loss = loss_sqrt * loss_sqrt;
89 
90  if (loss < 1)
91  {
92  loss = 1;
93  }
94  return loss;
95 }
96 
97 int64_t
99 {
100  return 0;
101 }
102 
103 } // namespace ns3
double f(double x, void *params)
Definition: 80211b.c:70
Friis spectrum propagation loss model.
double CalculateLoss(double f, double d) const
Return the propagation loss L according to a simplified version of Friis' formula in which antenna ga...
Ptr< SpectrumValue > DoCalcRxPowerSpectralDensity(Ptr< const SpectrumSignalParameters > params, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
spectrum-aware propagation loss model
Bands::const_iterator ConstBandsEnd() const
Values::iterator ValuesBegin()
Bands::const_iterator ConstBandsBegin() const
Values::iterator ValuesEnd()
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.