A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
cosine-antenna-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 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: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
22
#include <ns3/log.h>
23
#include <ns3/double.h>
24
#include <cmath>
25
26
#include "
antenna-model.h
"
27
#include "
cosine-antenna-model.h
"
28
29
30
NS_LOG_COMPONENT_DEFINE
(
"CosineAntennaModel"
);
31
32
namespace
ns3 {
33
34
NS_OBJECT_ENSURE_REGISTERED
(CosineAntennaModel);
35
36
37
TypeId
38
CosineAntennaModel::GetTypeId
()
39
{
40
static
TypeId
tid =
TypeId
(
"ns3::CosineAntennaModel"
)
41
.
SetParent
<
AntennaModel
> ()
42
.AddConstructor<CosineAntennaModel> ()
43
.AddAttribute (
"Beamwidth"
,
44
"The 3dB beamwidth (degrees)"
,
45
DoubleValue
(60),
46
MakeDoubleAccessor (&
CosineAntennaModel::SetBeamwidth
,
47
&
CosineAntennaModel::GetBeamwidth
),
48
MakeDoubleChecker<double> (0, 180))
49
.AddAttribute (
"Orientation"
,
50
"The angle (degrees) that expresses the orientation of the antenna on the x-y plane relative to the x axis"
,
51
DoubleValue
(0.0),
52
MakeDoubleAccessor (&
CosineAntennaModel::SetOrientation
,
53
&
CosineAntennaModel::GetOrientation
),
54
MakeDoubleChecker<double> (-360, 360))
55
.AddAttribute (
"MaxGain"
,
56
"The gain (dB) at the antenna boresight (the direction of maximum gain)"
,
57
DoubleValue
(0.0),
58
MakeDoubleAccessor (&
CosineAntennaModel::m_maxGain
),
59
MakeDoubleChecker<double> ())
60
;
61
return
tid;
62
}
63
64
void
65
CosineAntennaModel::SetBeamwidth
(
double
beamwidthDegrees)
66
{
67
NS_LOG_FUNCTION
(
this
<< beamwidthDegrees);
68
m_beamwidthRadians
=
DegreesToRadians
(beamwidthDegrees);
69
m_exponent
= -3.0 / (20*log10 (cos (
m_beamwidthRadians
/ 4.0)));
70
NS_LOG_LOGIC
(
this
<<
" m_exponent = "
<<
m_exponent
);
71
}
72
73
double
74
CosineAntennaModel::GetBeamwidth
()
const
75
{
76
return
RadiansToDegrees
(
m_beamwidthRadians
);
77
}
78
79
void
80
CosineAntennaModel::SetOrientation
(
double
orientationDegrees)
81
{
82
NS_LOG_FUNCTION
(
this
<< orientationDegrees);
83
m_orientationRadians
=
DegreesToRadians
(orientationDegrees);
84
}
85
86
double
87
CosineAntennaModel::GetOrientation
()
const
88
{
89
return
RadiansToDegrees
(
m_orientationRadians
);
90
}
91
92
double
93
CosineAntennaModel::GetGainDb
(
Angles
a)
94
{
95
NS_LOG_FUNCTION
(
this
<< a);
96
// azimuth angle w.r.t. the reference system of the antenna
97
double
phi = a.
phi
-
m_orientationRadians
;
98
99
// make sure phi is in (-pi, pi]
100
while
(phi <= -M_PI)
101
{
102
phi += M_PI+M_PI;
103
}
104
while
(phi > M_PI)
105
{
106
phi -= M_PI+M_PI;
107
}
108
109
NS_LOG_LOGIC
(
"phi = "
<< phi );
110
111
// element factor: amplitude gain of a single antenna element in linear units
112
double
ef = pow (cos (phi / 2.0),
m_exponent
);
113
114
// the array factor is not considered. Note that if we did consider
115
// the array factor, the actual beamwidth would change, and in
116
// particular it would be different from the one specified by the
117
// user. Hence it is not desirable to use the array factor, for the
118
// ease of use of this model.
119
120
double
gainDb = 20*log10 (ef);
121
NS_LOG_LOGIC
(
"gain = "
<< gainDb <<
" + "
<<
m_maxGain
<<
" dB"
);
122
return
gainDb +
m_maxGain
;
123
}
124
125
126
}
127
src
antenna
model
cosine-antenna-model.cc
Generated on Tue Oct 9 2012 16:45:32 for ns-3 by
1.8.1.2