A Discrete-Event Network Simulator
API
phased-array-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 University of Padova, Dep. of Information Engineering, SIGNET lab.
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
18#include "phased-array-model.h"
19
20#include <ns3/boolean.h>
21#include <ns3/double.h>
22#include <ns3/isotropic-antenna-model.h>
23#include <ns3/log.h>
24#include <ns3/pointer.h>
25#include <ns3/uinteger.h>
26
27namespace ns3
28{
29
31
32NS_LOG_COMPONENT_DEFINE("PhasedArrayModel");
33
34NS_OBJECT_ENSURE_REGISTERED(PhasedArrayModel);
35
36std::ostream&
37operator<<(std::ostream& os, const PhasedArrayModel::ComplexVector& cv)
38{
39 size_t N = cv.size();
40
41 // empty
42 if (N == 0)
43 {
44 os << "[]";
45 return os;
46 }
47
48 // non-empty
49 os << "[";
50 for (std::size_t i = 0; i < N - 1; ++i)
51 {
52 os << cv[i] << ", ";
53 }
54 os << cv[N - 1] << "]";
55 return os;
56}
57
59 : m_isBfVectorValid{false}
60{
61 m_id = m_idCounter++;
62}
63
65{
66 m_beamformingVector.clear();
67}
68
71{
72 static TypeId tid =
73 TypeId("ns3::PhasedArrayModel")
75 .SetGroupName("Antenna")
76 .AddAttribute("AntennaElement",
77 "A pointer to the antenna element used by the phased array",
78 PointerValue(CreateObject<IsotropicAntennaModel>()),
80 MakePointerChecker<AntennaModel>());
81 return tid;
82}
83
84void
86{
87 NS_LOG_FUNCTION(this << beamformingVector);
88 NS_ASSERT_MSG(beamformingVector.size() == GetNumberOfElements(),
89 beamformingVector.size() << " != " << GetNumberOfElements());
90 m_beamformingVector = beamformingVector;
91 m_isBfVectorValid = true;
92}
93
96{
97 NS_LOG_FUNCTION(this);
99 "The beamforming vector should be Set before it's Get, and should refer to the "
100 "current array configuration");
101 return m_beamformingVector;
102}
103
104double
106{
107 double norm = 0;
108
109 for (uint64_t i = 0; i < vector.size(); i++)
110 {
111 norm += std::norm(vector[i]);
112 }
113
114 return std::sqrt(norm);
115}
116
119{
120 NS_LOG_FUNCTION(this << a);
121
122 ComplexVector beamformingVector = GetSteeringVector(a);
123 double norm = ComputeNorm(beamformingVector);
124
125 for (uint64_t i = 0; i < beamformingVector.size(); i++)
126 {
127 beamformingVector[i] = std::conj(beamformingVector[i]) / norm;
128 }
129
130 return beamformingVector;
131}
132
135{
136 ComplexVector steeringVector;
137 steeringVector.resize(GetNumberOfElements());
138 for (uint64_t i = 0; i < GetNumberOfElements(); i++)
139 {
140 Vector loc = GetElementLocation(i);
141 double phase = -2 * M_PI *
142 (sin(a.GetInclination()) * cos(a.GetAzimuth()) * loc.x +
143 sin(a.GetInclination()) * sin(a.GetAzimuth()) * loc.y +
144 cos(a.GetInclination()) * loc.z);
145 steeringVector[i] = std::polar<double>(1.0, phase);
146 }
147 return steeringVector;
148}
149
150void
152{
153 NS_LOG_FUNCTION(this);
154 m_antennaElement = antennaElement;
155}
156
159{
160 NS_LOG_FUNCTION(this);
161 return m_antennaElement;
162}
163
166{
167 return m_id;
168}
169
170} /* 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:216
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:210
A base class which provides memory management and object aggregation.
Definition: object.h:89
static uint32_t m_idCounter
the ID counter that is used to determine the unique antenna array ID
ComplexVector GetSteeringVector(Angles a) const
Returns the steering vector that points toward the specified position.
virtual Vector GetElementLocation(uint64_t index) const =0
Returns the location of the antenna element with the specified index, normalized with respect to the ...
uint32_t GetId() const
Returns the ID of this antenna array instance.
PhasedArrayModel()
Constructor.
Ptr< AntennaModel > m_antennaElement
the model of the antenna element in use
Ptr< const AntennaModel > GetAntennaElement() const
Returns a pointer to the AntennaModel instance used to model the elements of the array.
void SetAntennaElement(Ptr< AntennaModel > antennaElement)
Sets the antenna model to be used.
ComplexVector GetBeamformingVector() const
Returns the beamforming vector that is currently being used.
bool m_isBfVectorValid
ensures the validity of the beamforming vector
static double ComputeNorm(const ComplexVector &vector)
Utility method to compute the euclidean norm of a ComplexVector.
~PhasedArrayModel() override
Destructor.
uint32_t m_id
the ID of this antenna array instance
virtual uint64_t GetNumberOfElements() const =0
Returns the number of antenna elements.
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
ComplexVector m_beamformingVector
the beamforming vector in use
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
static TypeId GetTypeId()
Get the type ID.
Hold objects of type Ptr<T>.
Definition: pointer.h:37
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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:86
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:230
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:45
const double norm
Normalization to obtain randoms on [0,1).
Definition: rng-stream.cc:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129