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 
21 
22 #include <ns3/boolean.h>
23 #include <ns3/double.h>
24 #include <ns3/log.h>
25 #include <ns3/pointer.h>
26 #include <ns3/uinteger.h>
27 
28 namespace ns3
29 {
30 
32 
33 NS_LOG_COMPONENT_DEFINE("PhasedArrayModel");
34 
35 NS_OBJECT_ENSURE_REGISTERED(PhasedArrayModel);
36 
38  : m_isBfVectorValid{false}
39 {
40  m_id = m_idCounter++;
41 }
42 
44 {
45 }
46 
47 TypeId
49 {
50  static TypeId tid =
51  TypeId("ns3::PhasedArrayModel")
52  .SetParent<Object>()
53  .SetGroupName("Antenna")
54  .AddAttribute("AntennaElement",
55  "A pointer to the antenna element used by the phased array",
56  PointerValue(CreateObject<IsotropicAntennaModel>()),
58  MakePointerChecker<AntennaModel>());
59  return tid;
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION(this << beamformingVector);
66  NS_ASSERT_MSG(beamformingVector.GetSize() == GetNumElems(),
67  beamformingVector.GetSize() << " != " << GetNumElems());
68  m_beamformingVector = beamformingVector;
69  m_isBfVectorValid = true;
70 }
71 
74 {
75  NS_LOG_FUNCTION(this);
77  "The beamforming vector should be Set before it's Get, and should refer to the "
78  "current array configuration");
79  return m_beamformingVector;
80 }
81 
84 {
85  NS_LOG_FUNCTION(this);
87  "The beamforming vector should be Set before it's Get, and should refer to the "
88  "current array configuration");
89  return m_beamformingVector;
90 }
91 
94 {
95  NS_LOG_FUNCTION(this << a);
96 
97  ComplexVector beamformingVector = GetSteeringVector(a);
98  // The normalization takes into account the total number of ports as only a
99  // portion (K,L) of beam weights associated with a specific port are non-zero.
100  // See 3GPP Section 5.2.2 36.897. This normalization corresponds to
101  // a sub-array partition model (which is different from the full-connection
102  // model). Note that the total number of ports used to perform normalization
103  // is the ratio between the total number of antenna elements and the
104  // number of antenna elements per port.
105  double normRes = norm(beamformingVector) / sqrt(GetNumPorts());
106 
107  for (size_t i = 0; i < GetNumElems(); i++)
108  {
109  beamformingVector[i] = std::conj(beamformingVector[i]) / normRes;
110  }
111 
112  return beamformingVector;
113 }
114 
117 {
118  ComplexVector steeringVector(GetNumElems());
119  for (size_t i = 0; i < GetNumElems(); i++)
120  {
121  Vector loc = GetElementLocation(i);
122  double phase = -2 * M_PI *
123  (sin(a.GetInclination()) * cos(a.GetAzimuth()) * loc.x +
124  sin(a.GetInclination()) * sin(a.GetAzimuth()) * loc.y +
125  cos(a.GetInclination()) * loc.z);
126  steeringVector[i] = std::polar<double>(1.0, phase);
127  }
128  return steeringVector;
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION(this);
135  m_antennaElement = antennaElement;
136 }
137 
140 {
141  NS_LOG_FUNCTION(this);
142  return m_antennaElement;
143 }
144 
145 uint32_t
147 {
148  return m_id;
149 }
150 
151 } /* 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
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable...
Definition: matrix-array.h:83
A base class which provides memory management and object aggregation.
Definition: object.h:89
const PhasedArrayModel::ComplexVector & GetBeamformingVectorRef() const
Returns the const reference of the beamforming vector that is currently being used.
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 ...
virtual uint16_t GetNumPorts() const =0
Get the number of ports.
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
double norm(const ComplexVector &complexVector) const
Computes the Frobenius norm of the complex vector.
~PhasedArrayModel() override
Destructor.
uint32_t m_id
the ID of this antenna array instance
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
ComplexVector m_beamformingVector
the beamforming vector in use
virtual size_t GetNumElems() const =0
Returns the number of antenna elements.
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
size_t GetSize() const
Definition: val-array.h:400
#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
#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:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227