RandomFreqTimeModel.cc

00001 #include "RandomFreqTimeModel.h"
00002 
00003 
00009 void RandomFreqTimeModel::filterSignal(Signal& s){
00010 
00011 
00012   /* At first get a new instance of the default Mapping implementation
00013    * which is able to represent our attenuation mapping.
00014    * the first parameter of "createMapping" gets the DimensionSet the
00015    * Mapping should use as domain and the second parameter sets the
00016    * interpolation method to be used to calculate the values between
00017    * two Mapping entries.
00018    *
00019    * Note 1: At the moment only LINEAR interpolation is implemented.
00020    *
00021    * Note 2: For now the same interpolation method is used for
00022    * interpolation in every dimension. Later it might be possible
00023    * to define different interpolation methods for different
00024    * dimensions. For example: While linear interpolation of time
00025    * makes sence in this case, using NEAREST for frequency  whould make
00026    * more sense.
00027    */
00028   Mapping* attMapping = MappingUtils::createMapping(dimensions, Mapping::LINEAR);
00029 
00030   /* Get start and end of the signal to avoid unnecessary calculation
00031    * of attenuation. (Normally we don't wan't to attenuate the signal
00032    * outside its start and end time since it probably isn't defined there.*/
00033   simtime_t sStart = s.getSignalStart();
00034   simtime_t sEnd = sStart + s.getSignalLength();
00035 
00036   simtime_t interval = (sEnd - sStart) / 10.0; //lets divide it into 10 steps
00037 
00038   Argument pos(dimensions); //create an Argument which we will use as parameter
00039                 //to set the values inside the mapping
00040 
00041   for(double freq = 2.412; freq <= 2.472; freq += 0.01){
00042     //assure attenuation is set at end of freq range
00043     if(freq > 2.465)
00044       freq = 2.472;
00045 
00046     pos.setArgValue(frequency, freq*1e9); // update arguments position in frequency dimension
00047 
00048     //create time entries for this frequency
00049     //the comparision to "sEnd + (interval * 0.5)" is used to avoid floating point errors
00050     for(simtime_t t = sStart; t <= sEnd - (interval * 0.5); t+=interval){
00051 
00052       pos.setTime(t); // update arguments position in time dimension
00053 
00054       /* Create random attenuation between 0.1 and 1.0.
00055        * Since the attenuation value is multiplied to the transmission power mapping
00056        * it should be between 0.0 and 1.0, otherwise it whouldn't be a real
00057        * attenuation.*/
00058       double att = (double)rand() / (double)RAND_MAX * 0.9 + 0.1;
00059 
00060       attMapping->setValue(pos, att); //put the attenuation at the current position into the mapping
00061     }
00062 
00063     //assure that the attenuation is set at the end of the signal
00064     pos.setTime(sEnd); // update arguments position in time dimension
00065     double att = (double)rand() / (double)RAND_MAX * 0.9 + 0.1;
00066     attMapping->setValue(pos, att); //put the attenuation at the current position into the mapping
00067   }
00068 
00069   //at last add the created attenuation mapping to the signal
00070   s.addAttenuation(attMapping);
00071 }