A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cosine-antenna-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 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
22#include "antenna-model.h"
23
24#include <ns3/double.h>
25#include <ns3/log.h>
26
27#include <cmath>
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("CosineAntennaModel");
33
34NS_OBJECT_ENSURE_REGISTERED(CosineAntennaModel);
35
36TypeId
38{
39 static TypeId tid =
40 TypeId("ns3::CosineAntennaModel")
42 .SetGroupName("Antenna")
43 .AddConstructor<CosineAntennaModel>()
44 .AddAttribute("VerticalBeamwidth",
45 "The 3 dB vertical beamwidth (degrees). A beamwidth of 360 deg "
46 "corresponds to constant gain",
47 DoubleValue(360),
50 MakeDoubleChecker<double>(0, 360))
51 .AddAttribute("HorizontalBeamwidth",
52 "The 3 dB horizontal beamwidth (degrees). A beamwidth of 360 deg "
53 "corresponds to constant gain",
54 DoubleValue(120),
57 MakeDoubleChecker<double>(0, 360))
58 .AddAttribute("Orientation",
59 "The angle (degrees) that expresses the orientation of the antenna on "
60 "the x-y plane relative to the x axis",
61 DoubleValue(0.0),
64 MakeDoubleChecker<double>(-360, 360))
65 .AddAttribute("MaxGain",
66 "The gain (dB) at the antenna boresight (the direction of maximum gain)",
67 DoubleValue(0.0),
69 MakeDoubleChecker<double>());
70 return tid;
71}
72
73double
75{
76 NS_LOG_FUNCTION(beamwidthDegrees);
77
78 // The formula in obtained by inverting the power pattern P(alpha) in a single direction,
79 // while imposing that P(alpha0/2) = 0.5 = -3 dB, with respect to the exponent
80 // See CosineAntennaModel::GetGainDb for more information.
81 //
82 // The undetermined case of alpha0=360 is treated separately.
83 double exponent;
84 if (beamwidthDegrees == 360.0)
85 {
86 exponent = 0.0;
87 }
88 else
89 {
90 exponent = -3.0 / (20 * std::log10(std::cos(DegreesToRadians(beamwidthDegrees / 4.0))));
91 }
92
93 return exponent;
94}
95
96double
98{
99 NS_LOG_FUNCTION(exponent);
100
101 // The formula in obtained by inverting the power pattern P(alpha) in a single direction,
102 // while imposing that P(alpha0/2) = 0.5 = -3 dB, with respect to the beamwidth.
103 // See CosineAntennaModel::GetGainDb for more information.
104 double beamwidthRadians = 4 * std::acos(std::pow(0.5, 1 / (2 * exponent)));
105 return RadiansToDegrees(beamwidthRadians);
106}
107
108void
109CosineAntennaModel::SetVerticalBeamwidth(double verticalBeamwidthDegrees)
110{
111 NS_LOG_FUNCTION(this << verticalBeamwidthDegrees);
112 m_verticalExponent = GetExponentFromBeamwidth(verticalBeamwidthDegrees);
113}
114
115void
116CosineAntennaModel::SetHorizontalBeamwidth(double horizontalBeamwidthDegrees)
117{
118 NS_LOG_FUNCTION(this << horizontalBeamwidthDegrees);
119 m_horizontalExponent = GetExponentFromBeamwidth(horizontalBeamwidthDegrees);
120}
121
122double
124{
126}
127
128double
130{
132}
133
134void
135CosineAntennaModel::SetOrientation(double orientationDegrees)
136{
137 NS_LOG_FUNCTION(this << orientationDegrees);
138 m_orientationRadians = DegreesToRadians(orientationDegrees);
139}
140
141double
143{
145}
146
147double
149{
150 NS_LOG_FUNCTION(this << a);
151
152 // make sure phi is in (-pi, pi]
154
155 NS_LOG_LOGIC(a);
156
157 // The element power gain is computed as a product of cosine functions on the two axis
158 // The power pattern of the element is equal to:
159 // P(az,el) = cos(az/2)^2m * cos(pi/2 - incl/2)^2n,
160 // where az is the azimuth angle, and incl is the inclination angle.
161 double gain = (std::pow(std::cos(a.GetAzimuth() / 2), 2 * m_horizontalExponent)) *
162 (std::pow(std::cos((M_PI / 2 - a.GetInclination()) / 2), 2 * m_verticalExponent));
163 double gainDb = 10 * std::log10(gain);
164
165 NS_LOG_LOGIC("gain = " << gainDb << " + " << m_maxGain << " dB");
166 return gainDb + m_maxGain;
167}
168
169} // namespace ns3
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:246
void SetAzimuth(double azimuth)
Setter for azimuth angle.
Definition: angles.cc:226
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
interface for antenna radiation pattern models
Definition: antenna-model.h:55
Cosine Antenna Model.
double m_maxGain
antenna gain in dB towards the main orientation
void SetHorizontalBeamwidth(double horizontalBeamwidthDegrees)
Set the horizontal 3 dB beamwidth (bilateral) of the cosine antenna model.
double GetHorizontalBeamwidth() const
Get the horizontal 3 dB beamwidth of the cosine antenna model.
double GetGainDb(Angles a) override
this method is expected to be re-implemented by each antenna model
double GetOrientation() const
Get the horizontal orientation of the antenna element.
static double GetBeamwidthFromExponent(double exponent)
Compute the beamwidth of the cosine antenna model from the exponent.
static double GetExponentFromBeamwidth(double beamwidthDegrees)
Compute the exponent of the cosine antenna model from the beamwidth.
static TypeId GetTypeId()
Get the type ID.
double GetVerticalBeamwidth() const
Get the vertical 3 dB beamwidth of the cosine antenna model.
double m_verticalExponent
exponent of the vertical direction
void SetVerticalBeamwidth(double verticalBeamwidthDegrees)
Set the vertical 3 dB beamwidth (bilateral) of the cosine antenna model.
void SetOrientation(double orientationDegrees)
Set the horizontal orientation of the antenna element.
double m_orientationRadians
orientation in radians in the horizontal direction (bearing)
double m_horizontalExponent
exponent of the horizontal direction
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45