INET Framework for OMNeT++/OMNEST
PathLossReceptionModel.cc
Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include "PathLossReceptionModel.h"
00019 #include "ChannelControl.h"
00020 #include "FWMath.h"
00021 
00022 Register_Class(PathLossReceptionModel);
00023 
00024 void PathLossReceptionModel::initializeFrom(cModule *radioModule)
00025 {
00026     pathLossAlpha = radioModule->par("pathLossAlpha");
00027     shadowingDeviation = radioModule->par("shadowingDeviation");
00028 
00029     cModule *cc = ChannelControl::get();
00030     if (pathLossAlpha < (double) (cc->par("alpha")))
00031         opp_error("PathLossReceptionModel: pathLossAlpha can't be smaller than in ChannelControl -- please adjust the parameters");
00032 }
00033 
00034 double PathLossReceptionModel::calculateReceivedPower(double pSend, double carrierFrequency, double distance)
00035 {
00036     const double speedOfLight = 300000000.0;
00037     double waveLength = speedOfLight / carrierFrequency;
00038     if (shadowingDeviation == 0.0)
00039         return pSend * waveLength * waveLength / (16 * M_PI * M_PI * pow(distance, pathLossAlpha));
00040     else
00041     {
00042         // This code implements a shadowing component for the path loss reception model. The random
00043         // variable has a normal distribution in dB and results to log-normal distribution in mW.
00044         // This is a widespread and common model used for reproducing shadowing effects
00045         // (Rappaport, T. S. (2002), Wireless Communications - Principles and Practice, Prentice Hall PTR).
00046         double xs = normal(0.0, shadowingDeviation);
00047         double mWValue = pSend * waveLength * waveLength / (16 * M_PI * M_PI * pow(distance, pathLossAlpha));
00048         double dBmValue = mW2dBm(mWValue);
00049         dBmValue += xs;
00050         double mWValueWithShadowing = pow(10.0, dBmValue/10.0);
00051         return mWValueWithShadowing;
00052     }
00053 }
00054 
00055 double PathLossReceptionModel::mW2dBm(double mW)
00056 {
00057      return 10*log10(mW);
00058 }