RandomFrequencyOnlyModel.cc

00001 #include "RandomFrequencyOnlyModel.h"
00002 
00003 
00009 void RandomFrequencyOnlyModel::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 gets 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 most cases, using NEAREST whould make more sense
00026    * for frequency.
00027    */
00028   Mapping* attMapping = MappingUtils::createMapping(1.0, dimensions, Mapping::LINEAR);
00029 
00030   /* Get start and end of the signal to avoid unnecessary calculation
00031    * of attenuation.*/
00032   simtime_t sStart = s.getSignalStart();
00033 
00034   // Since this mapping does not depend on time, we just set values for
00035   // the first entry in time-dimension (start of the Signal)
00036   /*
00037   simtime_t sEnd = sStart + s.getSignalLength();
00038 
00039   simtime_t interval = 0.01; //lets use constant intervals for entries in time
00040   */
00041 
00042   Argument pos(dimensions); //create an Argument which we will use as parameter
00043                 //to set the values inside the mapping
00044 
00045   pos.setTime(sStart); // set arguments position in time dimension
00046 
00047   for(double freq = 2.412; freq < 2.465; freq += 0.01){
00048 
00049     pos.setArgValue(frequency, freq*1.e9); // update arguments position in frequency dimension
00050 
00051     /*
00052     //create time entries for this frequency
00053     for(simtime_t t = sStart; t <= sEnd; t+=interval){
00054 
00055 
00056       pos.setTime(t); // update arguments position in time dimension
00057     */
00058       /* Create random attenuation between 0.1 and 1.0.
00059        * Since the attenuation value is multiplied to the transmission power mapping
00060        * it should be between 0.0 and 1.0, otherwise it whouldn't be a real
00061        * attenuation.*/
00062       double att = (double)rand() / (double)RAND_MAX * 0.9 + 0.1;
00063 
00064       attMapping->setValue(pos, att); //put the attenuation at the current position into the mapping
00065     /*
00066     }
00067     */
00068   }
00069   //asure attenuation is set at end of freq range
00070   pos.setArgValue(frequency, 2.472e9); // update arguments position in frequency dimension
00071   double att = (double)rand() / (double)RAND_MAX * 0.9 + 0.1;
00072   attMapping->setValue(pos, att); //put the attenuation at the current position into the mapping
00073 
00074   //at last add the created attenuation mapping to the signal
00075   s.addAttenuation(attMapping);
00076 }