shadowing.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /*
00004  * shadowing.cc
00005  * Copyright (C) 2000 by the University of Southern California
00006  * $Id: shadowing.cc,v 1.4 2005/08/25 18:58:09 johnh Exp $
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License,
00010  * version 2, as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * The copyright of this module includes the following
00023  * linking-with-specific-other-licenses addition:
00024  *
00025  * In addition, as a special exception, the copyright holders of
00026  * this module give you permission to combine (via static or
00027  * dynamic linking) this module with free software programs or
00028  * libraries that are released under the GNU LGPL and with code
00029  * included in the standard release of ns-2 under the Apache 2.0
00030  * license or under otherwise-compatible licenses with advertising
00031  * requirements (or modified versions of such code, with unchanged
00032  * license).  You may copy and distribute such a system following the
00033  * terms of the GNU GPL for this module and the licenses of the
00034  * other code concerned, provided that you include the source code of
00035  * that other code when and as the GNU GPL requires distribution of
00036  * source code.
00037  *
00038  * Note that people who make modified versions of this module
00039  * are not obligated to grant this special exception for their
00040  * modified versions; it is their choice whether to do so.  The GNU
00041  * General Public License gives permission to release a modified
00042  * version without this exception; this exception also makes it
00043  * possible to release a modified version which carries forward this
00044  * exception.
00045  *
00046  */
00047 
00048 /*
00049  * Shadowing propation model, including the path-loss model.
00050  * This statistcal model is applicable for both outdoor and indoor.
00051  * Wei Ye, weiye@isi.edu, 2000
00052  */
00053 
00054 
00055 #include <math.h>
00056 
00057 #include <delay.h>
00058 #include <packet.h>
00059 
00060 #include <packet-stamp.h>
00061 #include <antenna.h>
00062 #include <mobilenode.h>
00063 #include <propagation.h>
00064 #include <wireless-phy.h>
00065 #include <shadowing.h>
00066 
00067 
00068 static class ShadowingClass: public TclClass {
00069 public:
00070     ShadowingClass() : TclClass("Propagation/Shadowing") {}
00071     TclObject* create(int, const char*const*) {
00072         return (new Shadowing);
00073     }
00074 } class_shadowing;
00075 
00076 
00077 Shadowing::Shadowing()
00078 {
00079     bind("pathlossExp_", &pathlossExp_);
00080     bind("std_db_", &std_db_);
00081     bind("dist0_", &dist0_);
00082     bind("seed_", &seed_);
00083     
00084     ranVar = new RNG;
00085     ranVar->set_seed(RNG::PREDEF_SEED_SOURCE, seed_);
00086 }
00087 
00088 
00089 Shadowing::~Shadowing()
00090 {
00091     delete ranVar;
00092 }
00093 
00094 
00095 double Shadowing::Pr(PacketStamp *t, PacketStamp *r, WirelessPhy *ifp)
00096 {
00097     double L = ifp->getL();     // system loss
00098     double lambda = ifp->getLambda();   // wavelength
00099 
00100     double Xt, Yt, Zt;      // loc of transmitter
00101     double Xr, Yr, Zr;      // loc of receiver
00102 
00103     t->getNode()->getLoc(&Xt, &Yt, &Zt);
00104     r->getNode()->getLoc(&Xr, &Yr, &Zr);
00105 
00106     // Is antenna position relative to node position?
00107     Xr += r->getAntenna()->getX();
00108     Yr += r->getAntenna()->getY();
00109     Zr += r->getAntenna()->getZ();
00110     Xt += t->getAntenna()->getX();
00111     Yt += t->getAntenna()->getY();
00112     Zt += t->getAntenna()->getZ();
00113 
00114     double dX = Xr - Xt;
00115     double dY = Yr - Yt;
00116     double dZ = Zr - Zt;
00117     double dist = sqrt(dX * dX + dY * dY + dZ * dZ);
00118 
00119     // get antenna gain
00120     double Gt = t->getAntenna()->getTxGain(dX, dY, dZ, lambda);
00121     double Gr = r->getAntenna()->getRxGain(dX, dY, dZ, lambda);
00122 
00123     // calculate receiving power at reference distance
00124     double Pr0 = Friis(t->getTxPr(), Gt, Gr, lambda, L, dist0_);
00125 
00126     // calculate average power loss predicted by path loss model
00127     double avg_db = -10.0 * pathlossExp_ * log10(dist/dist0_);
00128    
00129     // get power loss by adding a log-normal random variable (shadowing)
00130     // the power loss is relative to that at reference distance dist0_
00131     double powerLoss_db = avg_db + ranVar->normal(0.0, std_db_);
00132 
00133     // calculate the receiving power at dist
00134     double Pr = Pr0 * pow(10.0, powerLoss_db/10.0);
00135     
00136     return Pr;
00137 }
00138 
00139 
00140 int Shadowing::command(int argc, const char* const* argv)
00141 {
00142     if (argc == 4) {
00143         if (strcmp(argv[1], "seed") == 0) {
00144             int s = atoi(argv[3]);
00145             if (strcmp(argv[2], "raw") == 0) {
00146                 ranVar->set_seed(RNG::RAW_SEED_SOURCE, s);
00147             } else if (strcmp(argv[2], "predef") == 0) {
00148                 ranVar->set_seed(RNG::PREDEF_SEED_SOURCE, s);
00149                 // s is the index in predefined seed array
00150                 // 0 <= s < 64
00151             } else if (strcmp(argv[2], "heuristic") == 0) {
00152                 ranVar->set_seed(RNG::HEURISTIC_SEED_SOURCE, 0);
00153             }
00154             return(TCL_OK);
00155         }
00156     }
00157     
00158     return Propagation::command(argc, argv);
00159 }
00160 

Generated on Tue Mar 6 16:47:51 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6