Public Member Functions | Protected Attributes

RandomFrequencyOnlyModel Class Reference
[analogueModels - AnalogueModel implementationsAnalogueModels example - Classes from the AnalogueModels example]

Sample implementation of an AnalogueModel which uses MultiDimMapping as AttenuationMapping. More...

#include <RandomFrequencyOnlyModel.h>

Inherits AnalogueModel.

Collaboration diagram for RandomFrequencyOnlyModel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RandomFrequencyOnlyModel (int seed=23)
 Initializes the analogue model.
virtual void filterSignal (Signal &s)
 Has to be overriden by every implementation.

Protected Attributes

const Dimension frequency
 shortcut to the frequency dimension, to avoid using 'Dimension("frequency")' every time.
const DimensionSet dimensions
 stores the dimensions this analogue model applies to.

Detailed Description

Sample implementation of an AnalogueModel which uses MultiDimMapping as AttenuationMapping.

This class is a sample which shows how to use the default Mapping implementation to implement a signal attenuation over only one dimension but which is not the time. Since every Mapping has to be defined in time we can't really create a Mapping with only frequency as Dimension. But we can just create a two dimensional Mapping over frequency and time which is constant in time space. This means every time we want to set a value of the Mapping we will just pass 0 as parameter for the time dimension.

Definition at line 24 of file RandomFrequencyOnlyModel.h.


Constructor & Destructor Documentation

RandomFrequencyOnlyModel::RandomFrequencyOnlyModel ( int  seed = 23  )  [inline]

Initializes the analogue model.

The only thing we have to do in the constructor and which whould probably have to be done for every other AnalogueModel is setting the the DimensionSet this AnalogueModel will work with.

In this case we want to work on "time (constant)" and "frequency". The DimensionSet provides constructors for up to three initial dimensions. If we need more we will have to add them after construction by calling the DimensionSets "addDimension()"-method.

Note: Using "Dimension("time")" instead of "Dimension::time()" would work also, but using "Dimension::time()" saves us a string comparison and should therefore be prefered instead of using "Dimension("time")".

Definition at line 52 of file RandomFrequencyOnlyModel.h.

                                         :
    frequency("frequency"),
    dimensions(Dimension::time_static(), frequency) {

    //sets the seed for random number generation. The PhyLayer
    //(which created the analogue models) gets the seed from the
    //configuration parameters inside the xml-config
    srand(seed);
  }


Member Function Documentation

void RandomFrequencyOnlyModel::filterSignal ( Signal s  )  [virtual]

Has to be overriden by every implementation.

The actual filtering method. This implementation just put some random attenuations over time and frequency into the attenuation mapping.

Filters a specified Signal by adding an attenuation over time to the Signal.

Implements AnalogueModel.

Definition at line 9 of file RandomFrequencyOnlyModel.cc.

References Signal::addAttenuation(), MappingUtils::createMapping(), dimensions, frequency, Signal::getSignalStart(), Mapping::LINEAR, Argument::setArgValue(), Argument::setTime(), and Mapping::setValue().

                                                    {


  /* At first get a new instance of the default Mapping implementation
   * which is able to represent our attenuation mapping.
   * the first parameter of "createMapping" gets the DimensionSet the
   * Mapping should use as domain and the second parameter gets the
   * interpolation method to be used to calculate the values between
   * two Mapping entries.
   *
   * Note 1: At the moment only LINEAR interpolation is implemented.
   *
   * Note 2: For now the same interpolation method is used for
   * interpolation in every dimension. Later it might be possible
   * to define different interpolation methods for different
   * dimensions. For example: While linear interpolation of time
   * makes sence in most cases, using NEAREST whould make more sense
   * for frequency.
   */
  Mapping* attMapping = MappingUtils::createMapping(1.0, dimensions, Mapping::LINEAR);

  /* Get start and end of the signal to avoid unnecessary calculation
   * of attenuation.*/
  simtime_t sStart = s.getSignalStart();

  // Since this mapping does not depend on time, we just set values for
  // the first entry in time-dimension (start of the Signal)
  /*
  simtime_t sEnd = sStart + s.getSignalLength();

  simtime_t interval = 0.01; //lets use constant intervals for entries in time
  */

  Argument pos(dimensions); //create an Argument which we will use as parameter
                //to set the values inside the mapping

  pos.setTime(sStart); // set arguments position in time dimension

  for(double freq = 2.412; freq < 2.465; freq += 0.01){

    pos.setArgValue(frequency, freq*1.e9); // update arguments position in frequency dimension

    /*
    //create time entries for this frequency
    for(simtime_t t = sStart; t <= sEnd; t+=interval){


      pos.setTime(t); // update arguments position in time dimension
    */
      /* Create random attenuation between 0.1 and 1.0.
       * Since the attenuation value is multiplied to the transmission power mapping
       * it should be between 0.0 and 1.0, otherwise it whouldn't be a real
       * attenuation.*/
      double att = (double)rand() / (double)RAND_MAX * 0.9 + 0.1;

      attMapping->setValue(pos, att); //put the attenuation at the current position into the mapping
    /*
    }
    */
  }
  //asure attenuation is set at end of freq range
  pos.setArgValue(frequency, 2.472e9); // update arguments position in frequency dimension
  double att = (double)rand() / (double)RAND_MAX * 0.9 + 0.1;
  attMapping->setValue(pos, att); //put the attenuation at the current position into the mapping

  //at last add the created attenuation mapping to the signal
  s.addAttenuation(attMapping);
}


The documentation for this class was generated from the following files: