OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2009 CTTC |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Nicola Baldo <nbaldo@cttc.es> |
| 19 */ |
| 20 |
| 21 |
| 22 #include <ns3/mobility-model.h> |
| 23 #include <ns3/friis-spectrum-propagation-loss.h> |
| 24 #include <math.h> |
| 25 |
| 26 |
| 27 |
| 28 namespace ns3 { |
| 29 |
| 30 NS_OBJECT_ENSURE_REGISTERED (FriisSpectrumPropagationLossModel); |
| 31 |
| 32 |
| 33 FriisSpectrumPropagationLossModel::FriisSpectrumPropagationLossModel () |
| 34 { |
| 35 } |
| 36 |
| 37 FriisSpectrumPropagationLossModel::~FriisSpectrumPropagationLossModel () |
| 38 { |
| 39 } |
| 40 |
| 41 |
| 42 TypeId |
| 43 FriisSpectrumPropagationLossModel::GetTypeId (void) |
| 44 { |
| 45 static TypeId tid = TypeId ("ns3::FriisSpectrumPropagationLossModel") |
| 46 .SetParent<SpectrumPropagationLossModel> () |
| 47 .AddConstructor<FriisSpectrumPropagationLossModel> () |
| 48 ; |
| 49 return tid; |
| 50 } |
| 51 |
| 52 |
| 53 Ptr<SpectrumValue> |
| 54 FriisSpectrumPropagationLossModel::DoCalcRxPowerSpectralDensity (Ptr<const Spect
rumValue> txPsd, |
| 55 Ptr<const Mobil
ityModel> a, |
| 56 Ptr<const Mobil
ityModel> b) const |
| 57 { |
| 58 Ptr<SpectrumValue> rxPsd = Copy<SpectrumValue> (txPsd); |
| 59 Values::iterator vit = rxPsd->ValuesBegin (); |
| 60 Bands::const_iterator fit = rxPsd->ConstBandsBegin (); |
| 61 |
| 62 NS_ASSERT (a); |
| 63 NS_ASSERT (b); |
| 64 |
| 65 double d = a->GetDistanceFrom (b); |
| 66 |
| 67 while (vit != rxPsd->ValuesEnd ()) |
| 68 { |
| 69 NS_ASSERT (fit != rxPsd->ConstBandsEnd ()); |
| 70 *vit /= CalculateLoss (fit->fc, d); // Prx = Ptx / loss |
| 71 ++vit; |
| 72 ++fit; |
| 73 } |
| 74 return rxPsd; |
| 75 } |
| 76 |
| 77 |
| 78 double |
| 79 FriisSpectrumPropagationLossModel::CalculateLoss (double f, double d) const |
| 80 { |
| 81 NS_ASSERT (d >= 0); |
| 82 |
| 83 if (d == 0) |
| 84 { |
| 85 return 1; |
| 86 } |
| 87 |
| 88 NS_ASSERT (f > 0); |
| 89 double loss = ( d * f * f) / ((3e8 * 3e8) / (4 * M_PI)) ; |
| 90 |
| 91 if (loss < 1) |
| 92 { |
| 93 loss = 1; |
| 94 } |
| 95 return loss; |
| 96 } |
| 97 |
| 98 |
| 99 |
| 100 |
| 101 |
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 |
| 108 } // namespace ns3 |
OLD | NEW |