Sample implementation of an AnalogueModel which uses MultiDimMapping as AttenuationMapping. More...
#include <RandomFreqTimeModel.h>
Inherits AnalogueModel.
Public Member Functions | |
RandomFreqTimeModel (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. |
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 more dimensions then just the time.
Definition at line 20 of file RandomFreqTimeModel.h.
RandomFreqTimeModel::RandomFreqTimeModel | ( | 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" 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()" whould work also, but using "Dimension::time()" spares us a string comparison and should therefore be prefered instead of using "Dimension("time")". Besides using Dimension::time() is more typo resistant since the compiler can check if the static member actually exists.
Definition at line 50 of file RandomFreqTimeModel.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); }
void RandomFreqTimeModel::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 RandomFreqTimeModel.cc.
References Signal::addAttenuation(), MappingUtils::createMapping(), dimensions, frequency, Signal::getSignalLength(), 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 sets 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 this case, using NEAREST for frequency whould make * more sense. */ Mapping* attMapping = MappingUtils::createMapping(dimensions, Mapping::LINEAR); /* Get start and end of the signal to avoid unnecessary calculation * of attenuation. (Normally we don't wan't to attenuate the signal * outside its start and end time since it probably isn't defined there.*/ simtime_t sStart = s.getSignalStart(); simtime_t sEnd = sStart + s.getSignalLength(); simtime_t interval = (sEnd - sStart) / 10.0; //lets divide it into 10 steps Argument pos(dimensions); //create an Argument which we will use as parameter //to set the values inside the mapping for(double freq = 2.412; freq <= 2.472; freq += 0.01){ //assure attenuation is set at end of freq range if(freq > 2.465) freq = 2.472; pos.setArgValue(frequency, freq*1e9); // update arguments position in frequency dimension //create time entries for this frequency //the comparision to "sEnd + (interval * 0.5)" is used to avoid floating point errors for(simtime_t t = sStart; t <= sEnd - (interval * 0.5); 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 } //assure that the attenuation is set at the end of the signal pos.setTime(sEnd); // update arguments position in time 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); }