A Discrete-Event Network Simulator
API
okumura-hata-propagation-loss-model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (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: Marco Miozzo <marco.miozzo@cttc.es>,
18  * Nicola Baldo <nbaldo@cttc.es>
19  *
20  */
22 
23 #include "ns3/double.h"
24 #include "ns3/enum.h"
25 #include "ns3/log.h"
26 #include "ns3/mobility-model.h"
27 
28 #include <cmath>
29 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("OkumuraHataPropagationLossModel");
34 
35 NS_OBJECT_ENSURE_REGISTERED(OkumuraHataPropagationLossModel);
36 
37 TypeId
39 {
40  static TypeId tid =
41  TypeId("ns3::OkumuraHataPropagationLossModel")
43  .SetGroupName("Propagation")
44  .AddConstructor<OkumuraHataPropagationLossModel>()
45  .AddAttribute("Frequency",
46  "The propagation frequency in Hz",
47  DoubleValue(2160e6),
49  MakeDoubleChecker<double>())
50  .AddAttribute("Environment",
51  "Environment Scenario",
55  "Urban",
57  "SubUrban",
59  "OpenAreas"))
60  .AddAttribute(
61  "CitySize",
62  "Dimension of the city",
65  MakeEnumChecker(SmallCity, "Small", MediumCity, "Medium", LargeCity, "Large"));
66  return tid;
67 }
68 
71 {
72 }
73 
75 {
76 }
77 
78 double
80 {
81  double loss = 0.0;
82  double fmhz = m_frequency / 1e6;
83  double dist = a->GetDistanceFrom(b) / 1000.0;
84  if (m_frequency <= 1.500e9)
85  {
86  // standard Okumura Hata
87  // see eq. (4.4.1) in the COST 231 final report
88  double log_f = std::log10(fmhz);
89  double hb =
90  (a->GetPosition().z > b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
91  double hm =
92  (a->GetPosition().z < b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
93  NS_ASSERT_MSG(hb > 0 && hm > 0, "nodes' height must be greater then 0");
94  double log_aHeight = 13.82 * std::log10(hb);
95  double log_bHeight = 0.0;
96  if (m_citySize == LargeCity)
97  {
98  if (fmhz < 200)
99  {
100  log_bHeight = 8.29 * std::pow(log10(1.54 * hm), 2) - 1.1;
101  }
102  else
103  {
104  log_bHeight = 3.2 * std::pow(log10(11.75 * hm), 2) - 4.97;
105  }
106  }
107  else
108  {
109  log_bHeight = 0.8 + (1.1 * log_f - 0.7) * hm - 1.56 * log_f;
110  }
111 
112  NS_LOG_INFO(this << " logf " << 26.16 * log_f << " loga " << log_aHeight << " X "
113  << (((44.9 - (6.55 * std::log10(hb)))) * std::log10(a->GetDistanceFrom(b)))
114  << " logb " << log_bHeight);
115  loss = 69.55 + (26.16 * log_f) - log_aHeight +
116  (((44.9 - (6.55 * std::log10(hb)))) * std::log10(dist)) - log_bHeight;
118  {
119  loss += -2 * (std::pow(std::log10(fmhz / 28), 2)) - 5.4;
120  }
122  {
123  loss += -4.70 * std::pow(std::log10(fmhz), 2) + 18.33 * std::log10(fmhz) - 40.94;
124  }
125  }
126  else
127  {
128  // COST 231 Okumura model
129  // see eq. (4.4.3) in the COST 231 final report
130 
131  double log_f = std::log10(fmhz);
132  double hb =
133  (a->GetPosition().z > b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
134  double hm =
135  (a->GetPosition().z < b->GetPosition().z ? a->GetPosition().z : b->GetPosition().z);
136  NS_ASSERT_MSG(hb > 0 && hm > 0, "nodes' height must be greater then 0");
137  double log_aHeight = 13.82 * std::log10(hb);
138  double log_bHeight = 0.0;
139  double C = 0.0;
140 
141  if (m_citySize == LargeCity)
142  {
143  log_bHeight = 3.2 * std::pow((std::log10(11.75 * hm)), 2);
144  C = 3;
145  }
146  else
147  {
148  log_bHeight = (1.1 * log_f - 0.7) * hm - (1.56 * log_f - 0.8);
149  }
150 
151  loss = 46.3 + (33.9 * log_f) - log_aHeight +
152  (((44.9 - (6.55 * std::log10(hb)))) * std::log10(dist)) - log_bHeight + C;
153  }
154  return loss;
155 }
156 
157 double
160  Ptr<MobilityModel> b) const
161 {
162  return (txPowerDbm - GetLoss(a, b));
163 }
164 
165 int64_t
167 {
168  return 0;
169 }
170 
171 } // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:56
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Vector GetPosition() const
this class implements the Okumura Hata propagation loss model
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
EnvironmentType m_environment
Environment Scenario.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Models the propagation loss through a transmission medium.
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:43
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:205
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:163