Nakagami propagation loss model from ns2
This commit is contained in:
@@ -107,7 +107,7 @@ RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
|
||||
|
||||
const double FriisPropagationLossModel::PI = 3.1415;
|
||||
const double FriisPropagationLossModel::PI = 3.14159265358979323846;
|
||||
|
||||
TypeId
|
||||
FriisPropagationLossModel::GetTypeId (void)
|
||||
@@ -408,5 +408,101 @@ ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
|
||||
return txPowerDbm - pathLossDb;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
|
||||
|
||||
TypeId
|
||||
NakagamiPropagationLossModel::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
|
||||
.SetParent<PropagationLossModel> ()
|
||||
.AddConstructor<NakagamiPropagationLossModel> ()
|
||||
.AddAttribute ("Distance1",
|
||||
"Beginning of the second distance field. Default is 80m.",
|
||||
DoubleValue (80.0),
|
||||
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddAttribute ("Distance2",
|
||||
"Beginning of the third distance field. Default is 200m.",
|
||||
DoubleValue (200.0),
|
||||
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddAttribute ("m0",
|
||||
"m0 for distances smaller than Distance1. Default is 1.5.",
|
||||
DoubleValue (1.5),
|
||||
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddAttribute ("m1",
|
||||
"m1 for distances smaller than Distance2. Default is 0.75.",
|
||||
DoubleValue (0.75),
|
||||
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddAttribute ("m2",
|
||||
"m2 for distances greater than Distance2. Default is 0.75.",
|
||||
DoubleValue (0.75),
|
||||
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
|
||||
MakeDoubleChecker<double> ())
|
||||
;
|
||||
return tid;
|
||||
|
||||
}
|
||||
|
||||
NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
|
||||
{}
|
||||
|
||||
double
|
||||
NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
|
||||
Ptr<MobilityModel> a,
|
||||
Ptr<MobilityModel> b) const
|
||||
{
|
||||
// select m parameter
|
||||
|
||||
double distance = a->GetDistanceFrom (b);
|
||||
NS_ASSERT(distance >= 0);
|
||||
|
||||
double m;
|
||||
if (distance < m_distance1)
|
||||
{
|
||||
m = m_m0;
|
||||
}
|
||||
else if (distance < m_distance2)
|
||||
{
|
||||
m = m_m1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m = m_m2;
|
||||
}
|
||||
|
||||
// the current power unit is dBm, but Watt is put into the Nakagami /
|
||||
// Rayleigh distribution.
|
||||
double powerW = pow(10, (txPowerDbm - 30) / 10);
|
||||
|
||||
double resultPowerW;
|
||||
|
||||
// switch between Erlang- and Gamma distributions: this is only for
|
||||
// speed. (Gamma is equal to Erlang for any positive integer m.)
|
||||
unsigned int int_m = static_cast<unsigned int>(floor(m));
|
||||
|
||||
if (int_m == m)
|
||||
{
|
||||
resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m);
|
||||
}
|
||||
|
||||
double resultPowerDbm = 10 * log10(resultPowerW) + 30;
|
||||
|
||||
NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
|
||||
"power=" << powerW <<"W, " <<
|
||||
"resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
|
||||
|
||||
return resultPowerDbm;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -296,6 +296,53 @@ private:
|
||||
double m_referenceLoss;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Nakagami-m fast fading propagation loss model.
|
||||
*
|
||||
* The Nakagami-m distribution is applied to the power level. The probability
|
||||
* density function is defined as
|
||||
* \f[ p(x; m, \omega) = \frac{2 m^m}{\Gamma(m) \omega^m} x^{2m - 1} e^{-\frac{m}{\omega} x^2} = 2 x \cdot p_{\text{Gamma}}(x^2, m, \frac{m}{\omega}) \f]
|
||||
* with \f$ m \f$ the fading depth parameter and \f$ \omega \f$ the average received power.
|
||||
*
|
||||
* It is implemented by either a ns3::GammaVariable or a ns3::ErlangVariable
|
||||
* random variable.
|
||||
*
|
||||
* Like in ns3::ThreeLogDistancePropagationLossModel, the m parameter is varied
|
||||
* over three distance fields:
|
||||
* \f[ \underbrace{0 \cdots\cdots}_{m_0} \underbrace{d_1 \cdots\cdots}_{m_1} \underbrace{d_2 \cdots\cdots}_{m_2} \infty \f]
|
||||
*
|
||||
* For m = 1 the Nakagami-m distribution equals the Rayleigh distribution. Thus
|
||||
* this model also implements Rayleigh distribution based fast fading.
|
||||
*/
|
||||
|
||||
class NakagamiPropagationLossModel : public PropagationLossModel
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
NakagamiPropagationLossModel ();
|
||||
|
||||
// Parameters are all accessible via attributes.
|
||||
|
||||
private:
|
||||
NakagamiPropagationLossModel (const NakagamiPropagationLossModel& o);
|
||||
NakagamiPropagationLossModel& operator= (const NakagamiPropagationLossModel& o);
|
||||
|
||||
virtual double DoCalcRxPower (double txPowerDbm,
|
||||
Ptr<MobilityModel> a,
|
||||
Ptr<MobilityModel> b) const;
|
||||
|
||||
double m_distance1;
|
||||
double m_distance2;
|
||||
|
||||
double m_m0;
|
||||
double m_m1;
|
||||
double m_m2;
|
||||
|
||||
ErlangVariable m_erlangRandomVariable;
|
||||
GammaVariable m_gammaRandomVariable;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* PROPAGATION_LOSS_MODEL_H */
|
||||
|
||||
Reference in New Issue
Block a user