|
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" |
|
230 |
double pr = 10 * log10 (numerator / denominator); |
231 |
double pr = 10 * log10 (numerator / denominator); |
231 |
NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB"); |
232 |
NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB"); |
232 |
return txPowerDbm + pr; |
233 |
return txPowerDbm + pr; |
|
|
234 |
} |
235 |
|
236 |
// ------------------------------------------------------------------------- // |
237 |
// -- Two-Ray Ground Model ported from NS-2 -- tomhewer@mac.com -- Nov09 // |
238 |
|
239 |
NS_OBJECT_ENSURE_REGISTERED (TwoRayGroundPropagationLossModel); |
240 |
|
241 |
const double TwoRayGroundPropagationLossModel::PI = 3.14159265358979323846; |
242 |
|
243 |
TypeId |
244 |
TwoRayGroundPropagationLossModel::GetTypeId (void) |
245 |
{ |
246 |
static TypeId tid = TypeId ("ns3::TwoRayGroundPropagationLossModel") |
247 |
.SetParent<PropagationLossModel> () |
248 |
.AddConstructor<TwoRayGroundPropagationLossModel> () |
249 |
.AddAttribute ("Lambda", |
250 |
"The wavelength (default is 5.15 GHz at 300 000 km/s).", |
251 |
DoubleValue (300000000.0 / 5.150e9), |
252 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_lambda), |
253 |
MakeDoubleChecker<double> ()) |
254 |
.AddAttribute ("SystemLoss", "The system loss", |
255 |
DoubleValue (1.0), |
256 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_systemLoss), |
257 |
MakeDoubleChecker<double> ()) |
258 |
.AddAttribute ("MinDistance", |
259 |
"The distance under which the propagation model refuses to give results (m)", |
260 |
DoubleValue (0.5), |
261 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::SetMinDistance, |
262 |
&TwoRayGroundPropagationLossModel::GetMinDistance), |
263 |
MakeDoubleChecker<double> ()) |
264 |
.AddAttribute ("HeightAboveZ", |
265 |
"The height of the antenna (m) above the node's Z coordinate", |
266 |
DoubleValue (0), |
267 |
MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_heightAboveZ), |
268 |
MakeDoubleChecker<double> ()) |
269 |
; |
270 |
return tid; |
271 |
} |
272 |
|
273 |
TwoRayGroundPropagationLossModel::TwoRayGroundPropagationLossModel () |
274 |
{} |
275 |
void |
276 |
TwoRayGroundPropagationLossModel::SetSystemLoss (double systemLoss) |
277 |
{ |
278 |
m_systemLoss = systemLoss; |
279 |
} |
280 |
double |
281 |
TwoRayGroundPropagationLossModel::GetSystemLoss (void) const |
282 |
{ |
283 |
return m_systemLoss; |
284 |
} |
285 |
void |
286 |
TwoRayGroundPropagationLossModel::SetMinDistance (double minDistance) |
287 |
{ |
288 |
m_minDistance = minDistance; |
289 |
} |
290 |
double |
291 |
TwoRayGroundPropagationLossModel::GetMinDistance (void) const |
292 |
{ |
293 |
return m_minDistance; |
294 |
} |
295 |
void |
296 |
TwoRayGroundPropagationLossModel::SetHeightAboveZ (double heightAboveZ) |
297 |
{ |
298 |
m_heightAboveZ = heightAboveZ; |
299 |
} |
300 |
void |
301 |
TwoRayGroundPropagationLossModel::SetLambda (double frequency, double speed) |
302 |
{ |
303 |
m_lambda = speed / frequency; |
304 |
} |
305 |
void |
306 |
TwoRayGroundPropagationLossModel::SetLambda (double lambda) |
307 |
{ |
308 |
m_lambda = lambda; |
309 |
} |
310 |
double |
311 |
TwoRayGroundPropagationLossModel::GetLambda (void) const |
312 |
{ |
313 |
return m_lambda; |
314 |
} |
315 |
|
316 |
double |
317 |
TwoRayGroundPropagationLossModel::DbmToW (double dbm) const |
318 |
{ |
319 |
double mw = pow(10.0,dbm/10.0); |
320 |
return mw / 1000.0; |
321 |
} |
322 |
|
323 |
double |
324 |
TwoRayGroundPropagationLossModel::DbmFromW (double w) const |
325 |
{ |
326 |
double dbm = log10 (w * 1000.0) * 10.0; |
327 |
return dbm; |
328 |
} |
329 |
|
330 |
double |
331 |
TwoRayGroundPropagationLossModel::DoCalcRxPower (double txPowerDbm, |
332 |
Ptr<MobilityModel> a, |
333 |
Ptr<MobilityModel> b) const |
334 |
{ |
335 |
/* |
336 |
* Two-Ray Ground equation: |
337 |
* |
338 |
* where Pt, Gt and Gr are in dBm units |
339 |
* L, Ht and Hr are in meter units. |
340 |
* |
341 |
* Pr Gt * Gr * (Ht^2 * Hr^2) |
342 |
* -- = (-------------------------) |
343 |
* Pt d^4 * L |
344 |
* |
345 |
* Gt: tx gain (unit-less) |
346 |
* Gr: rx gain (unit-less) |
347 |
* Pt: tx power (dBm) |
348 |
* d: distance (m) |
349 |
* L: system loss |
350 |
* Ht: Tx antenna height (m) |
351 |
* Hr: Rx antenna height (m) |
352 |
* lambda: wavelength (m) |
353 |
* |
354 |
* As with the Friis model we ignore tx and rx gain and output values |
355 |
* are in dB or dBm |
356 |
* |
357 |
* (Ht * Ht) * (Hr * Hr) |
358 |
* rx = tx + 10 log10 (-----------------------) |
359 |
* (d * d * d * d) * L |
360 |
*/ |
361 |
double distance = a->GetDistanceFrom (b); |
362 |
if (distance <= m_minDistance) |
363 |
{ |
364 |
return txPowerDbm; |
365 |
} |
366 |
|
367 |
// Set the height of the Tx and Rx antennae |
368 |
Ptr<MobilityModel> txPosition = a->GetObject<MobilityModel> (); |
369 |
Vector txPos = txPosition->GetPosition(); |
370 |
double txAntHeight = txPos.z + m_heightAboveZ; |
371 |
Ptr<MobilityModel> rxPosition = b->GetObject<MobilityModel> (); |
372 |
Vector rxPos = rxPosition->GetPosition(); |
373 |
double rxAntHeight = rxPos.z + m_heightAboveZ; |
374 |
|
375 |
// Calculate a crossover distance, under which we use Friis |
376 |
/* |
377 |
* |
378 |
* dCross = (4 * pi * Ht * Hr) / lambda |
379 |
* |
380 |
*/ |
381 |
|
382 |
double dCross = (4 * PI * txAntHeight * rxAntHeight) / GetLambda(); |
383 |
|
384 |
if (distance <= dCross) { |
385 |
// We use Friis |
386 |
double numerator = m_lambda * m_lambda; |
387 |
double denominator = 16 * PI * PI * distance * distance * m_systemLoss; |
388 |
double pr = 10 * log10 (numerator / denominator); |
389 |
NS_LOG_DEBUG ("Receiver within crossover ("<<dCross<<"m) for Two_ray path; using Friis"); |
390 |
NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB"); |
391 |
return txPowerDbm + pr; |
392 |
} |
393 |
else { // Use Two-Ray Pathloss |
394 |
double rayNumerator = (txAntHeight * txAntHeight) * |
395 |
(rxAntHeight * rxAntHeight); |
396 |
double rayDenominator = (distance * distance * distance * distance) * m_systemLoss; |
397 |
double rayPr = 10 * log10 (rayNumerator / rayDenominator); |
398 |
NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<rayPr<<"dB"); |
399 |
return txPowerDbm + rayPr; |
400 |
} |
233 |
} |
401 |
} |
234 |
|
402 |
|
235 |
// ------------------------------------------------------------------------- // |
403 |
// ------------------------------------------------------------------------- // |