UWBIRStochasticPathlossModel.cc

00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        UWBIRStochasticPathlossModel.cc
00003  *
00004  * author:      Jerome Rousselot
00005  *
00006  * copyright:   (C) 2008 Centre Suisse d'Electronique et Microtechnique (CSEM) SA
00007  *              Real-Time Software and Networking
00008  *              Jaquet-Droz 1, CH-2002 Neuchatel, Switzerland.
00009  *
00010  *              This program is free software; you can redistribute it
00011  *              and/or modify it under the terms of the GNU General Public
00012  *              License as published by the Free Software Foundation; either
00013  *              version 2 of the License, or (at your option) any later
00014  *              version.
00015  *              For further information see file COPYING
00016  *              in the top level directory
00017  * description: this AnalogueModel models free-space pathloss
00018  ***************************************************************************/
00019 
00020 #include "UWBIRStochasticPathlossModel.h"
00021 
00022 double UWBIRStochasticPathlossModel::n1_limit = 1.25;
00023 double UWBIRStochasticPathlossModel::n2_limit = 2;
00024 
00025 double UWBIRStochasticPathlossModel::simtruncnormal(double mean, double stddev, double a, int rng) {
00026     double res = a + 1;
00027     while(res > a || res < -a) {
00028       res = normal(mean, stddev, 0);
00029     }
00030     return res;
00031 }
00032 
00033 void UWBIRStochasticPathlossModel::filterSignal(Signal& s) {
00034 
00035   if (isEnabled) {
00036     // Initialize objects and variables
00037     TimeMapping<Linear>* attMapping = new TimeMapping<Linear> ();
00038     Argument arg;
00039     Move srcMove = s.getMove();
00040     Coord srcCoord, rcvCoord;
00041     double distance = 0;
00042 
00043     // Generate channel.
00044     // assume channel coherence during whole frame
00045 
00046     n1 = simtruncnormal(0, 1, n1_limit, 1);
00047     n2 = simtruncnormal(0, 1, n2_limit, 2);
00048     n3 = simtruncnormal(0, 1, n2_limit, 3);
00049 
00050     gamma = mu_gamma + n1 * sigma_gamma;
00051     sigma = mu_sigma + n3 * sigma_sigma;
00052     S = n2 * sigma;
00053 
00054     // Determine distance between sender and receiver
00055     srcCoord = srcMove.getPositionAt(s.getSignalStart());
00056     rcvCoord = move->getPositionAt(s.getSignalStart());
00057 
00058     distance = rcvCoord.distance(srcCoord);
00059     /*
00060      srcPosX.record(srcCoord.getX());
00061      srcPosY.record(srcCoord.getY());
00062      dstPosX.record(rcvCoord.getX());
00063      dstPosY.record(rcvCoord.getY());
00064      distances.record(distance);
00065      */
00066     // Compute pathloss
00067     double attenuation = getGhassemzadehPathloss(distance);
00068     pathlosses.record(attenuation);
00069     //attenuation = attenuation / (4*PI*pow(distance, gamma));
00070     // Store scalar mapping
00071     attMapping->setValue(arg, attenuation);
00072     s.addAttenuation(attMapping);
00073   }
00074 }
00075 
00076 double UWBIRStochasticPathlossModel::getNarrowBandFreeSpacePathloss(double fc, double distance) {
00077     double attenuation = 4*M_PI*distance*fc/BaseWorldUtility::speedOfLight;
00078     return 1/(attenuation*attenuation);
00079 }
00080 
00081 double UWBIRStochasticPathlossModel::getGhassemzadehPathloss(double distance) {
00082     double attenuation = PL0;
00083     if(distance < d0) {
00084       distance = d0;
00085     }
00086     attenuation = attenuation - 10*gamma*log10(distance/d0);
00087     if (shadowing) {
00088       attenuation = attenuation - S;
00089     }
00090     attenuation = pow(10, attenuation/10); // from dB to mW
00091     return attenuation;
00092 }
00093 
00094 double UWBIRStochasticPathlossModel::getFDPathloss(double freq, double distance) {
00095     return 0.5*PL0*ntx*nrx*pow(freq/fc, -2*(kappa+1))/pow(distance/d0, pathloss_exponent);
00096 }
00097 
00098