A Discrete-Event Network Simulator
API
okumura-hata-propagation-loss-model.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (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: Marco Miozzo <marco.miozzo@cttc.es>,
19  * Nicola Baldo <nbaldo@cttc.es>
20  *
21  */
22 #include "ns3/log.h"
23 #include "ns3/double.h"
24 #include "ns3/enum.h"
25 #include "ns3/mobility-model.h"
26 #include <cmath>
27 
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("OkumuraHataPropagationLossModel");
33 
34 NS_OBJECT_ENSURE_REGISTERED (OkumuraHataPropagationLossModel);
35 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::OkumuraHataPropagationLossModel")
42  .SetGroupName ("Propagation")
43  .AddConstructor<OkumuraHataPropagationLossModel> ()
44  .AddAttribute ("Frequency",
45  "The propagation frequency in Hz",
46  DoubleValue (2160e6),
48  MakeDoubleChecker<double> ())
49  .AddAttribute ("Environment",
50  "Environment Scenario",
54  SubUrbanEnvironment, "SubUrban",
55  OpenAreasEnvironment, "OpenAreas"))
56  .AddAttribute ("CitySize",
57  "Dimension of the city",
60  MakeEnumChecker (SmallCity, "Small",
61  MediumCity, "Medium",
62  LargeCity, "Large"));
63  return tid;
64 }
65 
68 {
69 }
70 
72 {
73 }
74 
75 double
77 {
78  double loss = 0.0;
79  double fmhz = m_frequency / 1e6;
80  double dist = a->GetDistanceFrom (b) / 1000.0;
81  if (m_frequency <= 1.500e9)
82  {
83  // standard Okumura Hata
84  // see eq. (4.4.1) in the COST 231 final report
85  double log_f = std::log10 (fmhz);
86  double hb = (a->GetPosition ().z > b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
87  double hm = (a->GetPosition ().z < b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
88  NS_ASSERT_MSG (hb > 0 && hm > 0, "nodes' height must be greater then 0");
89  double log_aHeight = 13.82 * std::log10 (hb);
90  double log_bHeight = 0.0;
91  if (m_citySize == LargeCity)
92  {
93  if (fmhz < 200)
94  {
95  log_bHeight = 8.29 * std::pow (log10 (1.54 * hm), 2) - 1.1;
96  }
97  else
98  {
99  log_bHeight = 3.2 * std::pow (log10 (11.75 * hm), 2) - 4.97;
100  }
101  }
102  else
103  {
104  log_bHeight = 0.8 + (1.1 * log_f - 0.7) * hm - 1.56 * log_f;
105  }
106 
107  NS_LOG_INFO (this << " logf " << 26.16 * log_f << " loga " << log_aHeight << " X " << (((44.9 - (6.55 * std::log10 (hb)) )) * std::log10 (a->GetDistanceFrom (b))) << " logb " << log_bHeight);
108  loss = 69.55 + (26.16 * log_f) - log_aHeight + (((44.9 - (6.55 * std::log10 (hb)) )) * std::log10 (dist)) - log_bHeight;
110  {
111  loss += -2 * (std::pow (std::log10 (fmhz / 28), 2)) - 5.4;
112  }
114  {
115  loss += -4.70 * std::pow (std::log10 (fmhz),2) + 18.33 * std::log10 (fmhz) - 40.94;
116  }
117 
118  }
119  else
120  {
121  // COST 231 Okumura model
122  // see eq. (4.4.3) in the COST 231 final report
123 
124  double log_f = std::log10 (fmhz);
125  double hb = (a->GetPosition ().z > b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
126  double hm = (a->GetPosition ().z < b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
127  NS_ASSERT_MSG (hb > 0 && hm > 0, "nodes' height must be greater then 0");
128  double log_aHeight = 13.82 * std::log10 (hb);
129  double log_bHeight = 0.0;
130  double C = 0.0;
131 
132  if (m_citySize == LargeCity)
133  {
134  log_bHeight = 3.2 * std::pow ((std::log10 (11.75 * hm)), 2);
135  C = 3;
136  }
137  else
138  {
139  log_bHeight = (1.1 * log_f - 0.7) * hm - (1.56 * log_f - 0.8);
140  }
141 
142  loss = 46.3 + (33.9 * log_f) - log_aHeight + (((44.9 - (6.55 * std::log10 (hb)) )) * std::log10 (dist)) - log_bHeight + C;
143  }
144  return loss;
145 }
146 
147 double
150  Ptr<MobilityModel> b) const
151 {
152  return (txPowerDbm - GetLoss (a, b));
153 }
154 
155 int64_t
157 {
158  return 0;
159 }
160 
161 
162 } // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Hold variables of type enum.
Definition: enum.h:55
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Vector GetPosition(void) 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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#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:88
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:42
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:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#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.
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:162