A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
friis-spectrum-propagation-loss.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
21
22#include <ns3/friis-spectrum-propagation-loss.h>
23#include <ns3/mobility-model.h>
24
25#include <cmath> // for M_PI
26
27namespace ns3
28{
29
30NS_OBJECT_ENSURE_REGISTERED(FriisSpectrumPropagationLossModel);
31
33{
34}
35
37{
38}
39
42{
43 static TypeId tid = TypeId("ns3::FriisSpectrumPropagationLossModel")
45 .SetGroupName("Spectrum")
46 .AddConstructor<FriisSpectrumPropagationLossModel>();
47 return tid;
48}
49
55{
56 Ptr<SpectrumValue> rxPsd = Copy<SpectrumValue>(params->psd);
57 Values::iterator vit = rxPsd->ValuesBegin();
58 Bands::const_iterator fit = rxPsd->ConstBandsBegin();
59
60 NS_ASSERT(a);
61 NS_ASSERT(b);
62
63 double d = a->GetDistanceFrom(b);
64
65 while (vit != rxPsd->ValuesEnd())
66 {
67 NS_ASSERT(fit != rxPsd->ConstBandsEnd());
68 *vit /= CalculateLoss(fit->fc, d); // Prx = Ptx / loss
69 ++vit;
70 ++fit;
71 }
72 return rxPsd;
73}
74
75double
77{
78 NS_ASSERT(d >= 0);
79
80 if (d == 0)
81 {
82 return 1;
83 }
84
85 NS_ASSERT(f > 0);
86 double loss_sqrt = (4 * M_PI * f * d) / 3e8;
87 double loss = loss_sqrt * loss_sqrt;
88
89 if (loss < 1)
90 {
91 loss = 1;
92 }
93 return loss;
94}
95
96} // namespace ns3
double f(double x, void *params)
Definition: 80211b.c:70
Friis spectrum propagation loss model.
double CalculateLoss(double f, double d) const
Return the propagation loss L according to a simplified version of Friis' formula in which antenna ga...
Ptr< SpectrumValue > DoCalcRxPowerSpectralDensity(Ptr< const SpectrumSignalParameters > params, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
spectrum-aware propagation loss model
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.