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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
10
11#include "antenna-model.h"
12
13#include <ns3/double.h>
14#include <ns3/log.h>
15
16#include <cmath>
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("CosineAntennaModel");
22
23NS_OBJECT_ENSURE_REGISTERED(CosineAntennaModel);
24
25TypeId
27{
28 static TypeId tid =
29 TypeId("ns3::CosineAntennaModel")
31 .SetGroupName("Antenna")
32 .AddConstructor<CosineAntennaModel>()
33 .AddAttribute("VerticalBeamwidth",
34 "The 3 dB vertical beamwidth (degrees). A beamwidth of 360 deg "
35 "corresponds to constant gain",
36 DoubleValue(360),
40 .AddAttribute("HorizontalBeamwidth",
41 "The 3 dB horizontal beamwidth (degrees). A beamwidth of 360 deg "
42 "corresponds to constant gain",
43 DoubleValue(120),
47 .AddAttribute("Orientation",
48 "The angle (degrees) that expresses the orientation of the antenna on "
49 "the x-y plane relative to the x axis",
50 DoubleValue(0.0),
54 .AddAttribute("MaxGain",
55 "The gain (dB) at the antenna boresight (the direction of maximum gain)",
56 DoubleValue(0.0),
59 return tid;
60}
61
62double
64{
65 NS_LOG_FUNCTION(beamwidthDegrees);
66
67 // The formula in obtained by inverting the power pattern P(alpha) in a single direction,
68 // while imposing that P(alpha0/2) = 0.5 = -3 dB, with respect to the exponent
69 // See CosineAntennaModel::GetGainDb for more information.
70 //
71 // The undetermined case of alpha0=360 is treated separately.
72 double exponent;
73 if (beamwidthDegrees == 360.0)
74 {
75 exponent = 0.0;
76 }
77 else
78 {
79 exponent = -3.0 / (20 * std::log10(std::cos(DegreesToRadians(beamwidthDegrees / 4.0))));
80 }
81
82 return exponent;
83}
84
85double
87{
88 NS_LOG_FUNCTION(exponent);
89
90 // The formula in obtained by inverting the power pattern P(alpha) in a single direction,
91 // while imposing that P(alpha0/2) = 0.5 = -3 dB, with respect to the beamwidth.
92 // See CosineAntennaModel::GetGainDb for more information.
93 double beamwidthRadians = 4 * std::acos(std::pow(0.5, 1 / (2 * exponent)));
94 return RadiansToDegrees(beamwidthRadians);
95}
96
97void
98CosineAntennaModel::SetVerticalBeamwidth(double verticalBeamwidthDegrees)
99{
100 NS_LOG_FUNCTION(this << verticalBeamwidthDegrees);
101 m_verticalExponent = GetExponentFromBeamwidth(verticalBeamwidthDegrees);
102}
103
104void
105CosineAntennaModel::SetHorizontalBeamwidth(double horizontalBeamwidthDegrees)
106{
107 NS_LOG_FUNCTION(this << horizontalBeamwidthDegrees);
108 m_horizontalExponent = GetExponentFromBeamwidth(horizontalBeamwidthDegrees);
109}
110
111double
116
117double
122
123void
124CosineAntennaModel::SetOrientation(double orientationDegrees)
125{
126 NS_LOG_FUNCTION(this << orientationDegrees);
127 m_orientationRadians = DegreesToRadians(orientationDegrees);
128}
129
130double
135
136double
138{
139 NS_LOG_FUNCTION(this << a);
140
141 // make sure phi is in (-pi, pi]
143
144 NS_LOG_LOGIC(a);
145
146 // The element power gain is computed as a product of cosine functions on the two axis
147 // The power pattern of the element is equal to:
148 // P(az,el) = cos(az/2)^2m * cos(pi/2 - incl/2)^2n,
149 // where az is the azimuth angle, and incl is the inclination angle.
150 double gain = (std::pow(std::cos(a.GetAzimuth() / 2), 2 * m_horizontalExponent)) *
151 (std::pow(std::cos((M_PI / 2 - a.GetInclination()) / 2), 2 * m_verticalExponent));
152 double gainDb = 10 * std::log10(gain);
153
154 NS_LOG_LOGIC("gain = " << gainDb << " + " << m_maxGain << " dB");
155 return gainDb + m_maxGain;
156}
157
158} // namespace ns3
Class holding the azimuth and inclination angles of spherical coordinates.
Definition angles.h:107
double GetInclination() const
Getter for inclination angle.
Definition angles.cc:236
void SetAzimuth(double azimuth)
Setter for azimuth angle.
Definition angles.cc:216
double GetAzimuth() const
Getter for azimuth angle.
Definition angles.cc:230
interface for antenna radiation pattern models
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:31
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
double DegreesToRadians(double degrees)
converts degrees to radians
Definition angles.cc:28
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
double RadiansToDegrees(double radians)
converts radians to degrees
Definition angles.cc:34