A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
okumura-hata-propagation-loss-model.cc
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 
28 #include "okumura-hata-propagation-loss-model.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("OkumuraHataPropagationLossModel");
31 
32 namespace ns3 {
33 
34 NS_OBJECT_ENSURE_REGISTERED (OkumuraHataPropagationLossModel);
35 
36 
37 TypeId
38 OkumuraHataPropagationLossModel::GetTypeId (void)
39 {
40  static TypeId tid = TypeId ("ns3::OkumuraHataPropagationLossModel")
41 
42  .SetParent<PropagationLossModel> ()
43 
44  .AddAttribute ("Frequency",
45  "The propagation frequency in Hz",
46  DoubleValue (2160e6),
47  MakeDoubleAccessor (&OkumuraHataPropagationLossModel::m_frequency),
48  MakeDoubleChecker<double> ())
49 
50  .AddAttribute ("Environment",
51  "Environment Scenario",
52  EnumValue (UrbanEnvironment),
53  MakeEnumAccessor (&OkumuraHataPropagationLossModel::m_environment),
54  MakeEnumChecker (UrbanEnvironment, "Urban",
55  SubUrbanEnvironment, "SubUrban",
56  OpenAreasEnvironment, "OpenAreas"))
57 
58  .AddAttribute ("CitySize",
59  "Dimension of the city",
60  EnumValue (LargeCity),
61  MakeEnumAccessor (&OkumuraHataPropagationLossModel::m_citySize),
62  MakeEnumChecker (SmallCity, "Small",
63  MediumCity, "Medium",
64  LargeCity, "Large"));
65 
66  return tid;
67 }
68 
69 double
71 {
72  double loss = 0.0;
73  double fmhz = m_frequency / 1e6;
74  double dist = a->GetDistanceFrom (b) / 1000.0;
75  if (m_frequency <= 1.500e9)
76  {
77  // standard Okumura Hata
78  // see eq. (4.4.1) in the COST 231 final report
79  double log_f = std::log10 (fmhz);
80  double hb = (a->GetPosition ().z > b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
81  double hm = (a->GetPosition ().z < b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
82  NS_ASSERT_MSG (hb > 0 && hm > 0, "nodes' height must be greater then 0");
83  double log_aHeight = 13.82 * std::log10 (hb);
84  double log_bHeight = 0.0;
85  if (m_citySize == LargeCity)
86  {
87  if (fmhz < 200)
88  {
89  log_bHeight = 8.29 * std::pow (log10 (1.54 * hm), 2) - 1.1;
90  }
91  else
92  {
93  log_bHeight = 3.2 * std::pow (log10 (11.75 * hm), 2) - 4.97;
94  }
95  }
96  else
97  {
98  log_bHeight = 0.8 + (1.1 * log_f - 0.7) * hm - 1.56 * log_f;
99  }
100 
101  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);
102  loss = 69.55 + (26.16 * log_f) - log_aHeight + (((44.9 - (6.55 * std::log10 (hb)) )) * std::log10 (dist)) - log_bHeight;
103  if (m_environment == SubUrbanEnvironment)
104  {
105  loss += -2 * (std::pow (std::log10 (fmhz / 28), 2)) - 5.4;
106  }
107  else if (m_environment == OpenAreasEnvironment)
108  {
109  loss += -4.70 * std::pow (std::log10 (fmhz),2) + 18.33 * std::log10 (fmhz) - 40.94;
110  }
111 
112  }
113  else
114  {
115  // COST 231 Okumura model
116  // see eq. (4.4.3) in the COST 231 final report
117 
118  double log_f = std::log10 (fmhz);
119  double hb = (a->GetPosition ().z > b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
120  double hm = (a->GetPosition ().z < b->GetPosition ().z ? a->GetPosition ().z : b->GetPosition ().z);
121  NS_ASSERT_MSG (hb > 0 && hm > 0, "nodes' height must be greater then 0");
122  double log_aHeight = 13.82 * std::log10 (hb);
123  double log_bHeight = 0.0;
124  double C = 0.0;
125 
126  if (m_citySize == LargeCity)
127  {
128  log_bHeight = 3.2 * std::pow ((std::log10 (11.75 * hm)), 2);
129  C = 3;
130  }
131  else
132  {
133  log_bHeight = 1.1 * log_f - 0.7 * hm - (1.56 * log_f - 0.8);
134  }
135 
136  loss = 46.3 + (33.9 * log_f) - log_aHeight + (((44.9 - (6.55 * std::log10 (hb)) )) * std::log10 (dist)) - log_bHeight + C;
137  }
138  return loss;
139 }
140 
141 double
142 OkumuraHataPropagationLossModel::DoCalcRxPower (double txPowerDbm,
144  Ptr<MobilityModel> b) const
145 {
146  return (txPowerDbm - GetLoss (a, b));
147 }
148 
149 int64_t
151 {
152  return 0;
153 }
154 
155 
156 } // namespace ns3
double GetDistanceFrom(Ptr< const MobilityModel > position) const
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
Vector GetPosition(void) const
#define NS_LOG_INFO(msg)
Definition: log.h:264
double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
double z
Definition: vector.h:57