39 #include "ns3/buildings-module.h"
40 #include "ns3/mobility-module.h"
41 #include "ns3/core-module.h"
42 #include "ns3/network-module.h"
44 #include "ns3/uniform-planar-array.h"
45 #include "ns3/three-gpp-spectrum-propagation-loss-model.h"
46 #include "ns3/three-gpp-v2v-propagation-loss-model.h"
47 #include "ns3/three-gpp-channel-model.h"
73 Angles completeAngle (bPos,aPos);
96 NS_LOG_DEBUG (
"Pathloss " << -propagationGainDb <<
" dB");
97 double propagationGainLinear = std::pow (10.0, (propagationGainDb) / 10.0);
98 *(rxPsd) *= propagationGainLinear;
102 NS_LOG_DEBUG (
"Average rx power " << 10 * log10 (
Sum (*rxPsd) * 180e3) <<
" dB");
106 const double kT_dBm_Hz = -174.0;
107 double kT_W_Hz = std::pow (10.0, (kT_dBm_Hz - 30) / 10.0);
108 double noiseFigureLinear = std::pow (10.0, noiseFigure / 10.0);
109 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
111 (*noisePsd) = noisePowerSpectralDensity;
114 NS_LOG_DEBUG (
"Average SNR " << 10 * log10 (
Sum (*rxPsd) /
Sum (*noisePsd)) <<
" dB");
118 f.open (
"example-output.txt", std::ios::out | std::ios::app);
125 << 10 * log10 (
Sum (*rxPsd) /
Sum (*noisePsd)) <<
" "
126 << -propagationGainDb << std::endl;
138 std::ofstream outFile;
139 outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
140 if (!outFile.is_open ())
149 Box box = (*it)->GetBoundaries ();
150 outFile <<
"set object " << index
151 <<
" rect from " << box.
xMin <<
"," << box.
yMin
152 <<
" to " << box.
xMax <<
"," << box.
yMax
158 main (
int argc,
char *argv[])
160 double frequency = 28.0e9;
161 double txPow_dbm = 30.0;
162 double noiseFigure = 9.0;
165 std::string scenario =
"V2V-Urban";
167 double subCarrierSpacing = 60e3;
168 uint32_t numRb = 275;
171 cmd.AddValue (
"frequency",
"operating frequency in Hz", frequency);
172 cmd.AddValue (
"txPow",
"tx power in dBm", txPow_dbm);
173 cmd.AddValue (
"noiseFigure",
"noise figure in dB", noiseFigure);
174 cmd.AddValue (
"scenario",
"3GPP propagation scenario, V2V-Urban or V2V-Highway", scenario);
175 cmd.Parse (argc, argv);
186 nodes.Get (0)->AddDevice (txDev);
188 nodes.Get (1)->AddDevice (rxDev);
197 if (scenario ==
"V2V-Urban")
203 double buildingSizeX = 250 - 3.5 * 2 - 3;
204 double buildingSizeY = 433 - 3.5 * 2 - 3;
205 double streetWidth = 20;
206 double buildingHeight = 10;
207 uint32_t numBuildingsX = 2;
208 uint32_t numBuildingsY = 2;
209 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
210 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
212 std::vector<Ptr<Building> > buildingVector;
213 for (uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
215 for (uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
218 building = CreateObject<Building> ();
221 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
222 buildingIdY * (buildingSizeY + streetWidth),
223 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
224 0.0, buildingHeight));
228 buildingVector.push_back (building);
234 double vRx = vScatt / 2;
235 txMob = CreateObject<WaypointMobilityModel> ();
236 rxMob = CreateObject<WaypointMobilityModel> ();
239 nextWaypoint +=
Seconds ((maxAxisY - streetWidth) / 2 / vTx);
241 nextWaypoint +=
Seconds ((maxAxisX - streetWidth) / 2 / vTx);
245 nextWaypoint +=
Seconds (maxAxisY / vRx);
248 nodes.Get (0)->AggregateObject (txMob);
249 nodes.Get (1)->AggregateObject (rxMob);
252 m_condModel = CreateObject<ThreeGppV2vUrbanChannelConditionModel> ();
257 else if (scenario ==
"V2V-Highway")
265 double vRx = vScatt / 2;
267 txMob = CreateObject<ConstantVelocityMobilityModel> ();
268 rxMob = CreateObject<ConstantVelocityMobilityModel> ();
274 nodes.Get (0)->AggregateObject (txMob);
275 nodes.Get (1)->AggregateObject (rxMob);
278 m_condModel = CreateObject<ThreeGppV2vHighwayChannelConditionModel> ();
316 double freqSubBand = frequency;
317 for (uint16_t
n = 0;
n < numRb; ++
n)
321 freqSubBand += subCarrierSpacing / 2;
323 freqSubBand += subCarrierSpacing / 2;
329 double txPow_w = std::pow (10., (txPow_dbm - 30) / 10);
330 double txPowDens = (txPow_w / (numRb * subCarrierSpacing));
331 (*txPsd) = txPowDens;
333 for (
int i = 0; i < simTime / timeRes; i++)
340 f.open (
"example-output.txt", std::ios::out);
341 f <<
"Time[s] TxPosX[m] TxPosY[m] RxPosX[m] RxPosY[m] ChannelState SNR[dB] Pathloss[dB]" << std::endl;