path_loss.cpp

00001 
00002 #include "path_loss.hpp"
00003 #include "utility.hpp"
00004 #include "wireless_comm_signal.hpp"
00005 #include "physical_layer.hpp"
00006 
00007 const double FreeSpace::m_DEFAULT_LOSS_FACTOR = 1.0;
00008 const double TwoRay::m_DEFAULT_ANTENNA_HEIGHT = 1.5;
00009 
00010 PathLoss::PathLoss()
00011 {
00012 
00013 }
00014 
00015 PathLoss::~PathLoss()
00016 {
00017 
00018 }
00019 
00020 FreeSpace::FreeSpace()
00021    : m_lossFactor(m_DEFAULT_LOSS_FACTOR)
00022 {
00023    assert(m_lossFactor >= 1.0);
00024 }
00025 
00026 FreeSpace::FreeSpace(double lossFactor)
00027    : m_lossFactor(lossFactor)
00028 {
00029    if(m_lossFactor < 1.0)
00030       m_lossFactor = m_DEFAULT_LOSS_FACTOR;
00031    assert(m_lossFactor >= 1.0);
00032 }
00033 
00034 TwoRay::TwoRay()
00035    : FreeSpace(), m_antennaHeight(m_DEFAULT_ANTENNA_HEIGHT)
00036 {
00037 
00038 }
00039 
00040 TwoRay::TwoRay(double lossFactor)
00041    : FreeSpace(lossFactor), m_antennaHeight(m_DEFAULT_ANTENNA_HEIGHT)
00042 {
00043 
00044 }
00045 
00046 double FreeSpace::getRecvdStrength(const WirelessCommSignal& signal,
00047    const PhysicalLayer& receiver) const
00048 {
00049    double numerator = decibelsToPower(signal.getDbStrength()) * 
00050       signal.getTransmitterGain() * receiver.getGain() * 
00051       pow(signal.getWavelength(), 2);
00052    double distance = Location::distance(
00053       signal.getLocation(), receiver.getLocation());
00054    double denominator = pow((4.0 * PI), 2) * 
00055       pow(distance, 2) * m_lossFactor;
00056 
00057    assert(denominator > 0.0);
00058 
00059    return (numerator / denominator);
00060 }
00061 
00062 double TwoRay::getRecvdStrength(const WirelessCommSignal& signal,
00063    const PhysicalLayer& receiver) const
00064 {
00065 
00066    // These equations are largely from ns-2.  If the distance
00067    // is less than crossoverDistance, then use the FreeSpace
00068    // model; otherwise use the TwoRay model.
00069 
00070    double crossoverDistance = (4 * PI * 
00071       m_antennaHeight * m_antennaHeight) / signal.getWavelength();
00072    double distance = Location::distance(
00073       signal.getLocation(), receiver.getLocation());
00074 
00075    double recvdStrength = FreeSpace::getRecvdStrength(signal, receiver);
00076 
00077    if(m_DEBUG_SIGNAL_STRENGTH) {
00078       ostringstream debugStream;
00079       debugStream << __FUNCTION__ << " crossover: " <<
00080          crossoverDistance << ", dist: " << distance <<
00081          ", FS SS: " << recvdStrength;
00082       LogStreamManager::instance()->logDebugItem(debugStream.str());
00083    }
00084 
00085    // If the distance is greater, use the Two Ray equation.
00086    if(distance > crossoverDistance) {
00087       double numerator = decibelsToPower(signal.getDbStrength()) *
00088          signal.getTransmitterGain() * receiver.getGain() *
00089          pow(m_antennaHeight, 2) * pow(m_antennaHeight, 2);
00090       double denominator = pow(distance, 4) * m_lossFactor;
00091       assert(denominator > 0.0);
00092       recvdStrength = numerator / denominator;
00093    }
00094    
00095    return recvdStrength;
00096 }
00097 
00098 

Generated on Tue Dec 12 17:04:38 2006 for rfidsim by  doxygen 1.4.7