|
17 |
* |
17 |
* |
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 |
* Contributions: Timo Bingmann <timo.bingmann@student.kit.edu> |
19 |
* Contributions: Timo Bingmann <timo.bingmann@student.kit.edu> |
|
|
20 |
* Contributions: Tom Hewer <tomhewer@mac.com> for Two Ray Ground Model |
20 |
*/ |
21 |
*/ |
21 |
|
22 |
|
22 |
#include "propagation-loss-model.h" |
23 |
#include "propagation-loss-model.h" |
|
39 |
{ |
40 |
{ |
40 |
static TypeId tid = TypeId ("ns3::PropagationLossModel") |
41 |
static TypeId tid = TypeId ("ns3::PropagationLossModel") |
41 |
.SetParent<Object> () |
42 |
.SetParent<Object> () |
42 |
; |
43 |
; |
43 |
return tid; |
44 |
return tid; |
44 |
} |
45 |
} |
45 |
|
46 |
|
46 |
PropagationLossModel::PropagationLossModel () |
47 |
PropagationLossModel::PropagationLossModel () |
47 |
: m_next (0) |
48 |
: m_next (0) |
48 |
{} |
49 |
{ |
|
|
50 |
} |
49 |
|
51 |
|
50 |
PropagationLossModel::~PropagationLossModel () |
52 |
PropagationLossModel::~PropagationLossModel () |
51 |
{} |
53 |
{ |
|
|
54 |
} |
52 |
|
55 |
|
53 |
void |
56 |
void |
54 |
PropagationLossModel::SetNext (Ptr<PropagationLossModel> next) |
57 |
PropagationLossModel::SetNext (Ptr<PropagationLossModel> next) |
55 |
{ |
58 |
{ |
56 |
m_next = next; |
59 |
m_next = next; |
57 |
} |
60 |
} |
58 |
|
61 |
|
59 |
double |
62 |
double |
60 |
PropagationLossModel::CalcRxPower (double txPowerDbm, |
63 |
PropagationLossModel::CalcRxPower (double txPowerDbm, |
61 |
Ptr<MobilityModel> a, |
64 |
Ptr<MobilityModel> a, |
62 |
Ptr<MobilityModel> b) const |
65 |
Ptr<MobilityModel> b) const |
|
83 |
RandomVariableValue (ConstantVariable (1.0)), |
86 |
RandomVariableValue (ConstantVariable (1.0)), |
84 |
MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable), |
87 |
MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable), |
85 |
MakeRandomVariableChecker ()) |
88 |
MakeRandomVariableChecker ()) |
86 |
; |
89 |
; |
87 |
return tid; |
90 |
return tid; |
88 |
} |
91 |
} |
89 |
RandomPropagationLossModel::RandomPropagationLossModel () |
92 |
RandomPropagationLossModel::RandomPropagationLossModel () |
90 |
: PropagationLossModel () |
93 |
: PropagationLossModel () |
91 |
{} |
94 |
{ |
|
|
95 |
} |
92 |
|
96 |
|
93 |
RandomPropagationLossModel::~RandomPropagationLossModel () |
97 |
RandomPropagationLossModel::~RandomPropagationLossModel () |
94 |
{} |
98 |
{ |
|
|
99 |
} |
95 |
|
100 |
|
96 |
double |
101 |
double |
97 |
RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm, |
102 |
RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm, |
98 |
Ptr<MobilityModel> a, |
103 |
Ptr<MobilityModel> a, |
99 |
Ptr<MobilityModel> b) const |
104 |
Ptr<MobilityModel> b) const |
100 |
{ |
105 |
{ |
101 |
double rxc = -m_variable.GetValue (); |
106 |
double rxc = -m_variable.GetValue (); |
102 |
NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db"); |
107 |
NS_LOG_DEBUG ("attenuation coefficent=" << rxc << "Db"); |
103 |
return txPowerDbm + rxc; |
108 |
return txPowerDbm + rxc; |
104 |
} |
109 |
} |
105 |
|
110 |
|
|
130 |
MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance, |
135 |
MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance, |
131 |
&FriisPropagationLossModel::GetMinDistance), |
136 |
&FriisPropagationLossModel::GetMinDistance), |
132 |
MakeDoubleChecker<double> ()) |
137 |
MakeDoubleChecker<double> ()) |
133 |
; |
138 |
; |
134 |
return tid; |
139 |
return tid; |
135 |
} |
140 |
} |
136 |
|
141 |
|
137 |
FriisPropagationLossModel::FriisPropagationLossModel () |
142 |
FriisPropagationLossModel::FriisPropagationLossModel () |
138 |
{} |
143 |
{ |
139 |
void |
144 |
} |
|
|
145 |
void |
140 |
FriisPropagationLossModel::SetSystemLoss (double systemLoss) |
146 |
FriisPropagationLossModel::SetSystemLoss (double systemLoss) |
141 |
{ |
147 |
{ |
142 |
m_systemLoss = systemLoss; |
148 |
m_systemLoss = systemLoss; |
143 |
} |
149 |
} |
144 |
double |
150 |
double |
145 |
FriisPropagationLossModel::GetSystemLoss (void) const |
151 |
FriisPropagationLossModel::GetSystemLoss (void) const |
146 |
{ |
152 |
{ |
147 |
return m_systemLoss; |
153 |
return m_systemLoss; |
148 |
} |
154 |
} |
149 |
void |
155 |
void |
150 |
FriisPropagationLossModel::SetMinDistance (double minDistance) |
156 |
FriisPropagationLossModel::SetMinDistance (double minDistance) |
151 |
{ |
157 |
{ |
152 |
m_minDistance = minDistance; |
158 |
m_minDistance = minDistance; |
153 |
} |
159 |
} |
154 |
double |
160 |
double |
155 |
FriisPropagationLossModel::GetMinDistance (void) const |
161 |
FriisPropagationLossModel::GetMinDistance (void) const |
156 |
{ |
162 |
{ |
157 |
return m_minDistance; |
163 |
return m_minDistance; |
158 |
} |
164 |
} |
159 |
void |
165 |
void |
160 |
FriisPropagationLossModel::SetLambda (double frequency, double speed) |
166 |
FriisPropagationLossModel::SetLambda (double frequency, double speed) |
161 |
{ |
167 |
{ |
162 |
m_lambda = speed / frequency; |
168 |
m_lambda = speed / frequency; |
163 |
} |
169 |
} |
164 |
void |
170 |
void |
165 |
FriisPropagationLossModel::SetLambda (double lambda) |
171 |
FriisPropagationLossModel::SetLambda (double lambda) |
166 |
{ |
172 |
{ |
167 |
m_lambda = lambda; |
173 |
m_lambda = lambda; |
168 |
} |
174 |
} |
169 |
double |
175 |
double |
170 |
FriisPropagationLossModel::GetLambda (void) const |
176 |
FriisPropagationLossModel::GetLambda (void) const |
171 |
{ |
177 |
{ |
172 |
return m_lambda; |
178 |
return m_lambda; |
173 |
} |
179 |
} |
174 |
|
180 |
|
175 |
double |
181 |
double |
176 |
FriisPropagationLossModel::DbmToW (double dbm) const |
182 |
FriisPropagationLossModel::DbmToW (double dbm) const |
177 |
{ |
183 |
{ |
178 |
double mw = pow(10.0,dbm/10.0); |
184 |
double mw = pow (10.0,dbm / 10.0); |
179 |
return mw / 1000.0; |
185 |
return mw / 1000.0; |
180 |
} |
186 |
} |
181 |
|
187 |
|
|
228 |
double numerator = m_lambda * m_lambda; |
234 |
double numerator = m_lambda * m_lambda; |
229 |
double denominator = 16 * PI * PI * distance * distance * m_systemLoss; |
235 |
double denominator = 16 * PI * PI * distance * distance * m_systemLoss; |
230 |
double pr = 10 * log10 (numerator / denominator); |
236 |
double pr = 10 * log10 (numerator / denominator); |
231 |
NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB"); |
237 |
NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << pr << "dB"); |
232 |
return txPowerDbm + pr; |
238 |
return txPowerDbm + pr; |
|
|
239 |
} |
240 |
|
241 |
// ------------------------------------------------------------------------- // |
242 |
// -- Two-Ray Ground Model ported from NS-2 -- tomhewer@mac.com -- Nov09 // |
243 |
|
244 |
NS_OBJECT_ENSURE_REGISTERED (TwoRayGroundPropagationLossModel); |
245 |
|
246 |
const double TwoRayGroundPropagationLossModel::PI = 3.14159265358979323846; |
247 |
|
248 |
TypeId |
249 |
TwoRayGroundPropagationLossModel::GetTypeId (void) |
250 |
{ |
251 |
static TypeId tid = TypeId ("ns3::TwoRayGroundPropagationLossModel") |
252 |
.SetParent<PropagationLossModel> () |
253 |
.AddConstructor<TwoRayGroundPropagationLossModel> () |
254 |
.AddAttribute ("Lambda", |
255 |
"The wavelength (default is 5.15 GHz at 300 000 km/s).", |
256 |
DoubleValue (300000000.0 / 5.150e9), |
257 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_lambda), |
258 |
MakeDoubleChecker<double> ()) |
259 |
.AddAttribute ("SystemLoss", "The system loss", |
260 |
DoubleValue (1.0), |
261 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_systemLoss), |
262 |
MakeDoubleChecker<double> ()) |
263 |
.AddAttribute ("MinDistance", |
264 |
"The distance under which the propagation model refuses to give results (m)", |
265 |
DoubleValue (0.5), |
266 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::SetMinDistance, |
267 |
&TwoRayGroundPropagationLossModel::GetMinDistance), |
268 |
MakeDoubleChecker<double> ()) |
269 |
.AddAttribute ("HeightAboveZ", |
270 |
"The height of the antenna (m) above the node's Z coordinate", |
271 |
DoubleValue (0), |
272 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_heightAboveZ), |
273 |
MakeDoubleChecker<double> ()) |
274 |
; |
275 |
return tid; |
276 |
} |
277 |
|
278 |
TwoRayGroundPropagationLossModel::TwoRayGroundPropagationLossModel () |
279 |
{ |
280 |
} |
281 |
void |
282 |
TwoRayGroundPropagationLossModel::SetSystemLoss (double systemLoss) |
283 |
{ |
284 |
m_systemLoss = systemLoss; |
285 |
} |
286 |
double |
287 |
TwoRayGroundPropagationLossModel::GetSystemLoss (void) const |
288 |
{ |
289 |
return m_systemLoss; |
290 |
} |
291 |
void |
292 |
TwoRayGroundPropagationLossModel::SetMinDistance (double minDistance) |
293 |
{ |
294 |
m_minDistance = minDistance; |
295 |
} |
296 |
double |
297 |
TwoRayGroundPropagationLossModel::GetMinDistance (void) const |
298 |
{ |
299 |
return m_minDistance; |
300 |
} |
301 |
void |
302 |
TwoRayGroundPropagationLossModel::SetHeightAboveZ (double heightAboveZ) |
303 |
{ |
304 |
m_heightAboveZ = heightAboveZ; |
305 |
} |
306 |
void |
307 |
TwoRayGroundPropagationLossModel::SetLambda (double frequency, double speed) |
308 |
{ |
309 |
m_lambda = speed / frequency; |
310 |
} |
311 |
void |
312 |
TwoRayGroundPropagationLossModel::SetLambda (double lambda) |
313 |
{ |
314 |
m_lambda = lambda; |
315 |
} |
316 |
double |
317 |
TwoRayGroundPropagationLossModel::GetLambda (void) const |
318 |
{ |
319 |
return m_lambda; |
320 |
} |
321 |
|
322 |
double |
323 |
TwoRayGroundPropagationLossModel::DbmToW (double dbm) const |
324 |
{ |
325 |
double mw = pow (10.0,dbm / 10.0); |
326 |
return mw / 1000.0; |
327 |
} |
328 |
|
329 |
double |
330 |
TwoRayGroundPropagationLossModel::DbmFromW (double w) const |
331 |
{ |
332 |
double dbm = log10 (w * 1000.0) * 10.0; |
333 |
return dbm; |
334 |
} |
335 |
|
336 |
double |
337 |
TwoRayGroundPropagationLossModel::DoCalcRxPower (double txPowerDbm, |
338 |
Ptr<MobilityModel> a, |
339 |
Ptr<MobilityModel> b) const |
340 |
{ |
341 |
/* |
342 |
* Two-Ray Ground equation: |
343 |
* |
344 |
* where Pt, Gt and Gr are in dBm units |
345 |
* L, Ht and Hr are in meter units. |
346 |
* |
347 |
* Pr Gt * Gr * (Ht^2 * Hr^2) |
348 |
* -- = (-------------------------) |
349 |
* Pt d^4 * L |
350 |
* |
351 |
* Gt: tx gain (unit-less) |
352 |
* Gr: rx gain (unit-less) |
353 |
* Pt: tx power (dBm) |
354 |
* d: distance (m) |
355 |
* L: system loss |
356 |
* Ht: Tx antenna height (m) |
357 |
* Hr: Rx antenna height (m) |
358 |
* lambda: wavelength (m) |
359 |
* |
360 |
* As with the Friis model we ignore tx and rx gain and output values |
361 |
* are in dB or dBm |
362 |
* |
363 |
* (Ht * Ht) * (Hr * Hr) |
364 |
* rx = tx + 10 log10 (-----------------------) |
365 |
* (d * d * d * d) * L |
366 |
*/ |
367 |
double distance = a->GetDistanceFrom (b); |
368 |
if (distance <= m_minDistance) |
369 |
{ |
370 |
return txPowerDbm; |
371 |
} |
372 |
|
373 |
// Set the height of the Tx and Rx antennae |
374 |
double txAntHeight = a->GetPosition ().z + m_heightAboveZ; |
375 |
double rxAntHeight = b->GetPosition ().z + m_heightAboveZ; |
376 |
|
377 |
// Calculate a crossover distance, under which we use Friis |
378 |
/* |
379 |
* |
380 |
* dCross = (4 * pi * Ht * Hr) / lambda |
381 |
* |
382 |
*/ |
383 |
|
384 |
double dCross = (4 * PI * txAntHeight * rxAntHeight) / GetLambda (); |
385 |
double tmp = 0; |
386 |
if (distance <= dCross) |
387 |
{ |
388 |
// We use Friis |
389 |
double numerator = m_lambda * m_lambda; |
390 |
tmp = PI * distance; |
391 |
double denominator = 16 * tmp * tmp * m_systemLoss; |
392 |
double pr = 10 * log10 (numerator / denominator); |
393 |
NS_LOG_DEBUG ("Receiver within crossover (" << dCross << "m) for Two_ray path; using Friis"); |
394 |
NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << pr << "dB"); |
395 |
return txPowerDbm + pr; |
396 |
} |
397 |
else // Use Two-Ray Pathloss |
398 |
{ |
399 |
tmp = txAntHeight * rxAntHeight; |
400 |
double rayNumerator = tmp * tmp; |
401 |
tmp = distance * distance; |
402 |
double rayDenominator = tmp * tmp * m_systemLoss; |
403 |
double rayPr = 10 * log10 (rayNumerator / rayDenominator); |
404 |
NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << rayPr << "dB"); |
405 |
return txPowerDbm + rayPr; |
406 |
|
407 |
} |
233 |
} |
408 |
} |
234 |
|
409 |
|
235 |
// ------------------------------------------------------------------------- // |
410 |
// ------------------------------------------------------------------------- // |
|
257 |
DoubleValue (46.6777), |
432 |
DoubleValue (46.6777), |
258 |
MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss), |
433 |
MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss), |
259 |
MakeDoubleChecker<double> ()) |
434 |
MakeDoubleChecker<double> ()) |
260 |
; |
435 |
; |
261 |
return tid; |
436 |
return tid; |
262 |
|
437 |
|
263 |
} |
438 |
} |
264 |
|
439 |
|
265 |
LogDistancePropagationLossModel::LogDistancePropagationLossModel () |
440 |
LogDistancePropagationLossModel::LogDistancePropagationLossModel () |
266 |
{} |
441 |
{ |
|
|
442 |
} |
267 |
|
443 |
|
268 |
void |
444 |
void |
269 |
LogDistancePropagationLossModel::SetPathLossExponent (double n) |
445 |
LogDistancePropagationLossModel::SetPathLossExponent (double n) |
270 |
{ |
446 |
{ |
271 |
m_exponent = n; |
447 |
m_exponent = n; |
272 |
} |
448 |
} |
273 |
void |
449 |
void |
274 |
LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss) |
450 |
LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss) |
275 |
{ |
451 |
{ |
276 |
m_referenceDistance = referenceDistance; |
452 |
m_referenceDistance = referenceDistance; |
277 |
m_referenceLoss = referenceLoss; |
453 |
m_referenceLoss = referenceLoss; |
278 |
} |
454 |
} |
279 |
double |
455 |
double |
280 |
LogDistancePropagationLossModel::GetPathLossExponent (void) const |
456 |
LogDistancePropagationLossModel::GetPathLossExponent (void) const |
281 |
{ |
457 |
{ |
282 |
return m_exponent; |
458 |
return m_exponent; |
283 |
} |
459 |
} |
284 |
|
460 |
|
285 |
double |
461 |
double |
286 |
LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm, |
462 |
LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm, |
287 |
Ptr<MobilityModel> a, |
463 |
Ptr<MobilityModel> a, |
288 |
Ptr<MobilityModel> b) const |
464 |
Ptr<MobilityModel> b) const |
|
308 |
*/ |
484 |
*/ |
309 |
double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance); |
485 |
double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance); |
310 |
double rxc = -m_referenceLoss - pathLossDb; |
486 |
double rxc = -m_referenceLoss - pathLossDb; |
311 |
NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<< |
487 |
NS_LOG_DEBUG ("distance=" << distance << "m, reference-attenuation=" << -m_referenceLoss << "dB, " << |
312 |
"attenuation coefficient="<<rxc<<"db"); |
488 |
"attenuation coefficient=" << rxc << "db"); |
313 |
return txPowerDbm + rxc; |
489 |
return txPowerDbm + rxc; |
314 |
} |
490 |
} |
315 |
|
491 |
|
|
358 |
DoubleValue (46.6777), |
534 |
DoubleValue (46.6777), |
359 |
MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss), |
535 |
MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss), |
360 |
MakeDoubleChecker<double> ()) |
536 |
MakeDoubleChecker<double> ()) |
361 |
; |
537 |
; |
362 |
return tid; |
538 |
return tid; |
363 |
|
539 |
|
364 |
} |
540 |
} |
365 |
|
541 |
|
366 |
ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel () |
542 |
ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel () |
|
373 |
Ptr<MobilityModel> b) const |
549 |
Ptr<MobilityModel> b) const |
374 |
{ |
550 |
{ |
375 |
double distance = a->GetDistanceFrom (b); |
551 |
double distance = a->GetDistanceFrom (b); |
376 |
NS_ASSERT(distance >= 0); |
552 |
NS_ASSERT (distance >= 0); |
377 |
|
553 |
|
378 |
// See doxygen comments for the formula and explanation |
554 |
// See doxygen comments for the formula and explanation |
379 |
|
555 |
|
|
386 |
else if (distance < m_distance1) |
562 |
else if (distance < m_distance1) |
387 |
{ |
563 |
{ |
388 |
pathLossDb = m_referenceLoss |
564 |
pathLossDb = m_referenceLoss |
389 |
+ 10 * m_exponent0 * log10(distance / m_distance0); |
565 |
+ 10 * m_exponent0 * log10 (distance / m_distance0); |
390 |
} |
566 |
} |
391 |
else if (distance < m_distance2) |
567 |
else if (distance < m_distance2) |
392 |
{ |
568 |
{ |
393 |
pathLossDb = m_referenceLoss |
569 |
pathLossDb = m_referenceLoss |
394 |
+ 10 * m_exponent0 * log10(m_distance1 / m_distance0) |
570 |
+ 10 * m_exponent0 * log10 (m_distance1 / m_distance0) |
395 |
+ 10 * m_exponent1 * log10(distance / m_distance1); |
571 |
+ 10 * m_exponent1 * log10 (distance / m_distance1); |
396 |
} |
572 |
} |
397 |
else |
573 |
else |
398 |
{ |
574 |
{ |
399 |
pathLossDb = m_referenceLoss |
575 |
pathLossDb = m_referenceLoss |
400 |
+ 10 * m_exponent0 * log10(m_distance1 / m_distance0) |
576 |
+ 10 * m_exponent0 * log10 (m_distance1 / m_distance0) |
401 |
+ 10 * m_exponent1 * log10(m_distance2 / m_distance1) |
577 |
+ 10 * m_exponent1 * log10 (m_distance2 / m_distance1) |
402 |
+ 10 * m_exponent2 * log10(distance / m_distance2); |
578 |
+ 10 * m_exponent2 * log10 (distance / m_distance2); |
403 |
} |
579 |
} |
404 |
|
580 |
|
405 |
NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " << |
581 |
NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " << |
|
443 |
DoubleValue (0.75), |
619 |
DoubleValue (0.75), |
444 |
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2), |
620 |
MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2), |
445 |
MakeDoubleChecker<double> ()) |
621 |
MakeDoubleChecker<double> ()) |
446 |
; |
622 |
; |
447 |
return tid; |
623 |
return tid; |
448 |
|
624 |
|
449 |
} |
625 |
} |
450 |
|
626 |
|
451 |
NakagamiPropagationLossModel::NakagamiPropagationLossModel () |
627 |
NakagamiPropagationLossModel::NakagamiPropagationLossModel () |
452 |
{} |
628 |
{ |
|
|
629 |
} |
453 |
|
630 |
|
454 |
double |
631 |
double |
455 |
NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm, |
632 |
NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm, |
456 |
Ptr<MobilityModel> a, |
633 |
Ptr<MobilityModel> a, |
457 |
Ptr<MobilityModel> b) const |
634 |
Ptr<MobilityModel> b) const |
|
459 |
// select m parameter |
636 |
// select m parameter |
460 |
|
637 |
|
461 |
double distance = a->GetDistanceFrom (b); |
638 |
double distance = a->GetDistanceFrom (b); |
462 |
NS_ASSERT(distance >= 0); |
639 |
NS_ASSERT (distance >= 0); |
463 |
|
640 |
|
464 |
double m; |
641 |
double m; |
465 |
if (distance < m_distance1) |
642 |
if (distance < m_distance1) |
|
474 |
{ |
651 |
{ |
475 |
m = m_m2; |
652 |
m = m_m2; |
476 |
} |
653 |
} |
477 |
|
654 |
|
478 |
// the current power unit is dBm, but Watt is put into the Nakagami / |
655 |
// the current power unit is dBm, but Watt is put into the Nakagami / |
479 |
// Rayleigh distribution. |
656 |
// Rayleigh distribution. |
480 |
double powerW = pow(10, (txPowerDbm - 30) / 10); |
657 |
double powerW = pow (10, (txPowerDbm - 30) / 10); |
481 |
|
658 |
|
482 |
double resultPowerW; |
659 |
double resultPowerW; |
483 |
|
660 |
|
484 |
// switch between Erlang- and Gamma distributions: this is only for |
661 |
// switch between Erlang- and Gamma distributions: this is only for |
485 |
// speed. (Gamma is equal to Erlang for any positive integer m.) |
662 |
// speed. (Gamma is equal to Erlang for any positive integer m.) |
486 |
unsigned int int_m = static_cast<unsigned int>(floor(m)); |
663 |
unsigned int int_m = static_cast<unsigned int> (floor (m)); |
487 |
|
664 |
|
488 |
if (int_m == m) |
665 |
if (int_m == m) |
489 |
{ |
666 |
{ |
490 |
resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m); |
667 |
resultPowerW = m_erlangRandomVariable.GetValue (int_m, powerW / m); |
491 |
} |
668 |
} |
492 |
else |
669 |
else |
493 |
{ |
670 |
{ |
494 |
resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m); |
671 |
resultPowerW = m_gammaRandomVariable.GetValue (m, powerW / m); |
495 |
} |
672 |
} |
496 |
|
673 |
|
497 |
double resultPowerDbm = 10 * log10(resultPowerW) + 30; |
674 |
double resultPowerDbm = 10 * log10 (resultPowerW) + 30; |
498 |
|
675 |
|
499 |
NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " << |
676 |
NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " << |
500 |
"power=" << powerW <<"W, " << |
677 |
"power=" << powerW << "W, " << |
501 |
"resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm"); |
678 |
"resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm"); |
502 |
|
679 |
|
503 |
return resultPowerDbm; |
680 |
return resultPowerDbm; |
|
517 |
DoubleValue (-150.0), |
694 |
DoubleValue (-150.0), |
518 |
MakeDoubleAccessor (&FixedRssLossModel::m_rss), |
695 |
MakeDoubleAccessor (&FixedRssLossModel::m_rss), |
519 |
MakeDoubleChecker<double> ()) |
696 |
MakeDoubleChecker<double> ()) |
520 |
; |
697 |
; |
521 |
return tid; |
698 |
return tid; |
522 |
} |
699 |
} |
523 |
FixedRssLossModel::FixedRssLossModel () |
700 |
FixedRssLossModel::FixedRssLossModel () |
524 |
: PropagationLossModel () |
701 |
: PropagationLossModel () |
525 |
{} |
702 |
{ |
|
|
703 |
} |
526 |
|
704 |
|
527 |
FixedRssLossModel::~FixedRssLossModel () |
705 |
FixedRssLossModel::~FixedRssLossModel () |
528 |
{} |
706 |
{ |
|
|
707 |
} |
529 |
|
708 |
|
530 |
void |
709 |
void |
531 |
FixedRssLossModel::SetRss (double rss) |
710 |
FixedRssLossModel::SetRss (double rss) |
532 |
{ |
711 |
{ |
533 |
m_rss = rss; |
712 |
m_rss = rss; |
534 |
} |
713 |
} |
535 |
|
714 |
|
536 |
double |
715 |
double |
537 |
FixedRssLossModel::DoCalcRxPower (double txPowerDbm, |
716 |
FixedRssLossModel::DoCalcRxPower (double txPowerDbm, |
538 |
Ptr<MobilityModel> a, |
717 |
Ptr<MobilityModel> a, |
539 |
Ptr<MobilityModel> b) const |
718 |
Ptr<MobilityModel> b) const |
540 |
{ |
719 |
{ |
541 |
return m_rss; |
720 |
return m_rss; |
542 |
} |
721 |
} |