A Discrete-Event Network Simulator
API
friis-spectrum-propagation-loss.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/mobility-model.h>
22 #include <ns3/friis-spectrum-propagation-loss.h>
23 #include <cmath> // for M_PI
24 
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (FriisSpectrumPropagationLossModel);
29 
30 
32 {
33 }
34 
36 {
37 }
38 
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::FriisSpectrumPropagationLossModel")
45  .SetGroupName ("Spectrum")
46  .AddConstructor<FriisSpectrumPropagationLossModel> ()
47  ;
48  return tid;
49 }
50 
51 
56 {
57  Ptr<SpectrumValue> rxPsd = Copy<SpectrumValue> (txPsd);
58  Values::iterator vit = rxPsd->ValuesBegin ();
59  Bands::const_iterator 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 
77 double
79 {
80  NS_ASSERT (d >= 0);
81 
82  if (d == 0)
83  {
84  return 1;
85  }
86 
87  NS_ASSERT (f > 0);
88  double loss_sqrt = (4 * M_PI * f * d) / 3e8;
89  double loss = loss_sqrt * loss_sqrt;
90 
91  if (loss < 1)
92  {
93  loss = 1;
94  }
95  return loss;
96 }
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 } // 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...
virtual Ptr< SpectrumValue > DoCalcRxPowerSpectralDensity(Ptr< const SpectrumValue > txPsd, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const
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:922
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.