00001 #include "BreakpointPathlossModel.h" 00002 00003 #define debugEV (ev.isDisabled()||!debug) ? ev : ev << "PhyLayer(BreakpointPathlossModel): " 00004 00005 00006 void BreakpointPathlossModel::filterSignal(Signal& s) { 00007 00009 simtime_t sStart = s.getSignalStart(); 00010 simtime_t sEnd = s.getSignalLength() + sStart; 00011 00013 Coord sendersPos = s.getMove().getPositionAt(sStart); 00014 Coord myPos = myMove.getPositionAt(sStart); 00015 00017 double distance = useTorus ? myPos.sqrTorusDist(sendersPos, playgroundSize) 00018 : myPos.sqrdist(sendersPos); 00019 distance = sqrt(distance); 00020 debugEV << "distance is: " << distance << endl; 00021 00022 if(distance <= 1.0) { 00023 //attenuation is negligible 00024 return; 00025 } 00026 00027 double attenuation = 1; 00028 // PL(d) = PL0 + 10 alpha log10 (d/d0) 00029 // 10 ^ { PL(d)/10 } = 10 ^{PL0 + 10 alpha log10 (d/d0)}/10 00030 // 10 ^ { PL(d)/10 } = 10 ^ PL0/10 * 10 ^ { 10 log10 (d/d0)^alpha }/10 00031 // 10 ^ { PL(d)/10 } = 10 ^ PL0/10 * 10 ^ { log10 (d/d0)^alpha } 00032 // 10 ^ { PL(d)/10 } = 10 ^ PL0/10 * (d/d0)^alpha 00033 if(distance < breakpointDistance) { 00034 attenuation = attenuation * PL01_real; 00035 attenuation = attenuation * pow(distance, alpha1); 00036 } else { 00037 attenuation = attenuation * PL02_real; 00038 attenuation = attenuation * pow(distance/breakpointDistance, alpha2); 00039 } 00040 attenuation = 1/attenuation; 00041 debugEV << "attenuation is: " << attenuation << endl; 00042 00043 if(debug) { 00044 pathlosses.record(10*log10(attenuation)); // in dB 00045 } 00046 00047 const DimensionSet& domain = DimensionSet::timeDomain; 00048 Argument arg; // default constructor initializes with a single dimension, time, and value 0 (offset from signal start) 00049 TimeMapping<Linear>* attMapping = new TimeMapping<Linear> (); // mapping performs a linear interpolation from our single point -> constant 00050 attMapping->setValue(arg, attenuation); 00051 00052 /* at last add the created attenuation mapping to the signal */ 00053 s.addAttenuation(attMapping); 00054 }