simplepathloss.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <math.h>
00031 
00032 //#include <delay.h>
00033 #include <packet.h>
00034 #include <node-core.h>
00035 
00036 //#include <packet-stamp.h>
00037 #include <antenna.h>
00038 //#include <mobilenode.h>
00039 //#include <mrcl_propagation.h>
00040 //#include <mrcl_wireless-phy.h>
00041 #include "simplepathloss.h"
00042 #include "wirelessphy-module.h"
00043 
00044 
00045 static class SimplePathLossClass: public TclClass {
00046 public:
00047         SimplePathLossClass() : TclClass("Propagation/SimplePathLoss") {}
00048         TclObject* create(int, const char*const*) {
00049                 return (new SimplePathLoss);
00050         }
00051 } class_simplepathloss;
00052 
00053 SimplePathLoss::SimplePathLoss()
00054 {
00055         bind("gamma_", &gamma_);
00056         bind("d0_", &d0_);
00057 }
00058 
00059 // use Friis at less than crossover distance
00060 // use two-ray at more than crossover distance
00061 //static double
00062 double SimplePathLoss::spl(double Pt, double d0, double gamma, double lambda, double d)
00063 {
00064         /*
00065          * Simple path loss propagation model.
00066          *
00067          *                   gamma
00068          *              [ d ]
00069          *  Pr = Pt * K [---]
00070          *              [ d0]
00071          *
00072          *                    2
00073          *         (  lambda )
00074          * with K= (---------)
00075          *         ( 4 pi d0 )
00076          *
00077          * Goldsmith A. "Wireless communication" sez 2.6 p 46
00078          */
00079         double K = (lambda / 4 / PI / d0) * (lambda / 4 / PI / d0);
00080         //printf("lambda=%f d0=%f K=%f Pt=%f d=%f gamma=%f pow=%f\n", lambda, d0, K, Pt, d, gamma, pow(d / d0, gamma));
00081         return Pt * K * pow(d0 / d, gamma);
00082 }
00083 
00084 double SimplePathLoss::Pr(Packet *p, PacketStamp *t, PacketStamp *r, double L, double lambda)
00085 {
00086         Position *sourcePos;
00087         Position *destPos;
00088         double rX, rY, rZ;              // location of receiver
00089         double tX, tY, tZ;              // location of transmitter
00090         double d;                               // distance
00091         double hr, ht;          // height of recv and xmit antennas
00092         double Pr;                      // received signal power
00093 
00094 
00095         // new position Parameters
00096         hdr_MrclWrlPhy *wph = HDR_MRCLWRLPHY(p);
00097         sourcePos = wph->sourcePos_;
00098         destPos = wph->destPos_;
00099   
00100         rX = destPos->getX();
00101         rY = destPos->getY();
00102         rZ = 0.;
00103         tX = sourcePos->getX();
00104         tY = sourcePos->getY();
00105         tZ = 0.;
00106 
00107         rX += r->getAntenna()->getX();
00108         rY += r->getAntenna()->getY();
00109         tX += t->getAntenna()->getX();
00110         tY += t->getAntenna()->getY();
00111 
00112         d = sqrt((rX - tX) * (rX - tX) 
00113                 + (rY - tY) * (rY - tY) 
00114                 + (rZ - tZ) * (rZ - tZ));
00115 
00116         if(d >= d0_)
00117         {
00118                 Pr = spl(t->getTxPr(), d0_, gamma_, lambda, d);
00119         }
00120         else
00121         {
00122                 double Gt = t->getAntenna()->getTxGain(rX - tX, rY - tY, rZ - tZ, t->getLambda());
00123                 double Gr = r->getAntenna()->getRxGain(tX - rX, tY - rY, tZ - rZ, r->getLambda());
00124                 Pr = Friis(t->getTxPr(), Gt, Gr, lambda, L, d);
00125         }
00126         //printf("PI=%f d=%f pr = %f\n", PI, d, Pr);
00127         //fflush(stdout);
00128         return Pr;
00129 }
00130 
00131 /*double MrclTwoRayGround::getDist(double Pr, double Pt, double Gt, double Gr, double hr, double ht, double L, double lambda)
00132 {
00133        /* Get quartic root * /
00134        return sqrt(sqrt(Pt * Gt * Gr * (hr * hr * ht * ht) / Pr));
00135 }*/
00136 

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2