Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
Also, fixed NS_LOG_COMPONENT_DEFINE for qd-channel-model-example, qd-channel-utils
  • Loading branch information
mattia-lecci committed May 27, 2021
1 parent f4d3a52 commit 9778514
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 94 deletions.
42 changes: 21 additions & 21 deletions examples/qd-channel-model-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "ns3/lte-spectrum-value-helper.h"
#include "ns3/qd-channel-utils.h"

NS_LOG_COMPONENT_DEFINE ("ThreeGppChannelExample");
NS_LOG_COMPONENT_DEFINE ("QdChannelModelExample");

using namespace ns3;

Expand Down Expand Up @@ -65,15 +65,14 @@ static void DoBeamforming (Ptr<NetDevice> txDevice, Ptr<ThreeGppAntennaArrayMode
*/
static void ComputeSnr ();


int
main (int argc, char *argv[])
{
std::string qdFilesPath = "contrib/qd-channel/model/QD/"; // The path of the folder with the QD scenarios
std::string scenario = "Indoor1"; // The name of the scenario
RngSeedManager::SetSeed(1);
RngSeedManager::SetRun(1);

RngSeedManager::SetSeed (1);
RngSeedManager::SetRun (1);

// Create the tx and rx nodes
NodeContainer nodes;
Expand Down Expand Up @@ -105,42 +104,42 @@ main (int argc, char *argv[])
// Create the QdChannelModel
qdChannel = CreateObject<QdChannelModel> (qdFilesPath, scenario);
Time simTime = qdChannel->GetQdSimTime ();

// Create the spectrum propagation loss model
spectrumLossModel = CreateObjectWithAttributes<ThreeGppSpectrumPropagationLossModel> ("ChannelModel", PointerValue (qdChannel));

// Create the antenna objects and set their dimensions
txAntenna = CreateObjectWithAttributes<ThreeGppAntennaArrayModel> ("NumColumns", UintegerValue (2),
"NumRows", UintegerValue (2),
"IsotropicElements", BooleanValue (true));
txNode->AggregateObject(txAntenna);
txNode->AggregateObject (txAntenna);

rxAntenna = CreateObjectWithAttributes<ThreeGppAntennaArrayModel> ("NumColumns", UintegerValue (2),
"NumRows", UintegerValue (2),
"IsotropicElements", BooleanValue (true));
rxNode->AggregateObject(rxAntenna);
rxNode->AggregateObject (rxAntenna);

// Initialize the devices in the ThreeGppSpectrumPropagationLossModel
spectrumLossModel->AddDevice (txDev, txAntenna);
spectrumLossModel->AddDevice (rxDev, rxAntenna);

// Compute and print SNR
Simulator::ScheduleNow (&ComputeSnr);

Simulator::Stop (simTime);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}


/* UTILITIES */
static void
DoBeamforming (Ptr<NetDevice> txDevice, Ptr<ThreeGppAntennaArrayModel> txAntenna, Ptr<NetDevice> rxDevice, Ptr<ThreeGppAntennaArrayModel> rxAntenna)
{
Ptr<MobilityModel> thisMob = txDevice->GetNode ()->GetObject<MobilityModel> ();
Ptr<MobilityModel> otherMob = rxDevice->GetNode ()->GetObject<MobilityModel> ();
Ptr<const MatrixBasedChannelModel::ChannelMatrix> channelMatrix = qdChannel->GetChannel (thisMob, otherMob, txAntenna, rxAntenna);
Ptr<const MatrixBasedChannelModel::ChannelMatrix> channelMatrix =
qdChannel->GetChannel (thisMob, otherMob, txAntenna, rxAntenna);

auto bfVectors = ComputeSvdBeamformingVectors (channelMatrix);

Expand All @@ -149,25 +148,26 @@ DoBeamforming (Ptr<NetDevice> txDevice, Ptr<ThreeGppAntennaArrayModel> txAntenna
rxAntenna->SetBeamformingVector (std::get<1> (bfVectors));
}


static void
ComputeSnr ()
{
// Create the tx PSD using the LteSpectrumValueHelper
// 100 RBs corresponds to 18 MHz (1 RB = 180 kHz)
// EARFCN 100 corresponds to 2125.00 MHz
std::vector<int> activeRbs0 (100);
for (int i = 0; i < 100 ; i++)
{
activeRbs0[i] = i;
}
Ptr<SpectrumValue> txPsd = LteSpectrumValueHelper::CreateTxPowerSpectralDensity (2100, 100, txPow, activeRbs0);
for (int i = 0; i < 100; i++)
{
activeRbs0[i] = i;
}
Ptr<SpectrumValue> txPsd =
LteSpectrumValueHelper::CreateTxPowerSpectralDensity (2100, 100, txPow, activeRbs0);
Ptr<SpectrumValue> rxPsd = txPsd->Copy ();
NS_LOG_DEBUG ("Average tx power " << 10*log10(Sum (*txPsd) * 180e3) << " dB");
NS_LOG_DEBUG ("Average tx power " << 10 * log10 (Sum (*txPsd) * 180e3) << " dB");

// Create the noise PSD
Ptr<SpectrumValue> noisePsd = LteSpectrumValueHelper::CreateNoisePowerSpectralDensity (2100, 100, noiseFigure);
NS_LOG_DEBUG ("Average noise power " << 10*log10 (Sum (*noisePsd) * 180e3) << " dB");
Ptr<SpectrumValue> noisePsd =
LteSpectrumValueHelper::CreateNoisePowerSpectralDensity (2100, 100, noiseFigure);
NS_LOG_DEBUG ("Average noise power " << 10 * log10 (Sum (*noisePsd) * 180e3) << " dB");

// compute beamforming vectors
Ptr<NetDevice> txDevice = txMob->GetObject<Node> ()->GetDevice (0);
Expand All @@ -177,7 +177,7 @@ ComputeSnr ()

// Apply the fast fading and the beamforming gain
rxPsd = spectrumLossModel->CalcRxPowerSpectralDensity (rxPsd, txMob, rxMob);
NS_LOG_DEBUG ("Average rx power " << 10*log10 (Sum (*rxPsd) * 180e3) << " dB");
NS_LOG_DEBUG ("Average rx power " << 10 * log10 (Sum (*rxPsd) * 180e3) << " dB");

// Compute the SNR
NS_LOG_DEBUG ("Average SNR " << 10 * log10 (Sum (*rxPsd) / Sum (*noisePsd)) << " dB");
Expand Down
Loading

0 comments on commit 9778514

Please sign in to comment.