User Manual, Developers Guide and API Documentation

FTFading.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <RISE/scenario/ftfading/FTFading.hpp>
00029 
00030 #include <math.h>
00031 
00032 using namespace rise;
00033 using namespace rise::scenario;
00034 using namespace rise::scenario::ftfading;
00035 
00036 
00037 
00038 STATIC_FACTORY_REGISTER_WITH_CREATOR( FTFadingOff, FTFading, "rise.scenario.ftfading.FTFadingOff",  wns::PyConfigViewCreator);
00039 STATIC_FACTORY_REGISTER_WITH_CREATOR( FTFadingFflat, FTFading, "rise.scenario.ftfading.FTFadingFflat",  wns::PyConfigViewCreator);
00040 STATIC_FACTORY_REGISTER_WITH_CREATOR( FTFadingFuncorrelated, FTFading, "rise.scenario.ftfading.FTFadingFuncorrelated",  wns::PyConfigViewCreator);
00041 STATIC_FACTORY_REGISTER_WITH_CREATOR( FTFadingFneighbourCorrelation, FTFading, "rise.scenario.ftfading.FTFadingFneighbourCorrelation",  wns::PyConfigViewCreator);
00042 
00043 FTFading::FTFading(const wns::pyconfig::View& config)
00044     : logger(config.getView("logger")),
00045       numberOfSubChannels(config.get<int>("numSubCarriers"))
00046 {
00047     assure(!config.isNone("samplingTime"),"FTFading: samplingTime is None");
00048     samplingTime = config.get<double>("samplingTime");
00049     assure(samplingTime>=0.0,"samplingTime must be positive: t="<<samplingTime);
00050     //samplingFrequency = 1.0/samplingTime;
00051     // numberOfSubChannels can be 0, e.g. for FTFadingOff
00052 }
00053 
00054 FTFadingOff::FTFadingOff(const wns::pyconfig::View& config)
00055     : FTFading(config)
00056 {
00057     MESSAGE_SINGLE(NORMAL, logger, "Using FTFadingOff strategy" );
00058 }
00059 
00060 wns::Ratio
00061 FTFadingOff::getFTFading(int /*subCarrier*/)
00062 {
00063     wns::Ratio OneFading = wns::Ratio(); // ::from_factor(1);
00064     return OneFading;
00065 }
00066 
00067 FTFadingJakes::FTFadingJakes(const wns::pyconfig::View& config)
00068     : FTFading(config),
00069       _dopFreq(config.get<double>("dopFreq")),
00070       //_sampFreq(config.get<double>("sampFreq")),
00071       _numWaves(config.get<int>("numWaves")),
00072       scheduler(wns::simulator::getEventScheduler())
00073 {
00074     assure(numberOfSubChannels>0,"wrong numberOfSubChannels="<<numberOfSubChannels);
00075 }
00076 
00077 FTFadingFflat::FTFadingFflat(const wns::pyconfig::View& config)
00078     : FTFadingJakes(config)
00079 {
00080     MESSAGE_SINGLE(NORMAL, logger, "Using FTFadingFflat strategy" );
00081 
00082     //samplePeriod = 1/_sampFreq; // new: samplingTime
00083     currentPeriodTime = 0;
00084     subCarrierFading = 0;
00085 
00086     jakesVector.push_back(new JakesFadingGenerator());
00087     jakesVector[0]->initJakes(_dopFreq,samplingTime,_numWaves);
00088     subCarrierFading = jakesVector[0]->getNextFadingValue(); // initial value
00089     CurrentFading = wns::Ratio::from_factor(subCarrierFading);
00090 }
00091 
00092 FTFadingFflat::~FTFadingFflat()
00093 {
00094     delete jakesVector[0]; jakesVector[0]=NULL;
00095     jakesVector.clear();
00096 }
00097 
00098 wns::Ratio
00099 FTFadingFflat::getFTFading(int /*subCarrier*/)
00100 {
00101     simTimeType now = Now();
00102     if ( (now/samplingTime) >= currentPeriodTime){
00103         double diffPeriodTime = (floor(now/samplingTime)+1) - currentPeriodTime;
00104         // ^ should be int !
00105         for (int i = 0; i<diffPeriodTime; ++i){
00106             subCarrierFading = jakesVector[0]->getNextFadingValue();
00107         }
00108         CurrentFading = wns::Ratio::from_factor(subCarrierFading);
00109         currentPeriodTime = static_cast<int>(currentPeriodTime + diffPeriodTime);
00110     } else {
00111         // do nothing, i.e. return the same value
00112     }
00113     return CurrentFading;
00114 }
00115 
00116 
00117 
00118 FTFadingFuncorrelated::FTFadingFuncorrelated(const wns::pyconfig::View& config)
00119     : FTFadingJakes(config)
00120 {
00121     MESSAGE_SINGLE(NORMAL, logger, "Using FTFadingFuncorrelated strategy" );
00122 
00123     for (int subCarrierCounter = 0; subCarrierCounter < numberOfSubChannels; ++subCarrierCounter){
00124         jakesVector.push_back(new JakesFadingGenerator());
00125         jakesVector[subCarrierCounter]->initJakes(_dopFreq,samplingTime,_numWaves);
00126         subCarrierFading.push_back(jakesVector[subCarrierCounter]->getNextFadingValue());
00127         currentFading.push_back(wns::Ratio::from_factor(subCarrierFading[subCarrierCounter]));
00128         sampleIndex.push_back(1);
00129     }
00130 }
00131 
00132 wns::Ratio
00133 FTFadingFuncorrelated::getFTFading(int _subCarrier)
00134 {
00135     assure( _subCarrier < numberOfSubChannels, "Exceeded Max Number of subcarriers!");
00136     simTimeType now = Now();
00137 
00138     if ( (now/samplingTime) >= (sampleIndex[_subCarrier]) ) {
00139 
00140         double diffPeriodTime = (floor(now/samplingTime)+1) - sampleIndex[_subCarrier];
00141         // ^ should be int !
00142 
00143         for (int i = 0; i<diffPeriodTime; ++i) {
00144                 subCarrierFading[_subCarrier] = jakesVector[_subCarrier]->getNextFadingValue();
00145                 currentFading[_subCarrier] = wns::Ratio::from_factor(subCarrierFading[_subCarrier]);
00146         }
00147         sampleIndex[_subCarrier] = static_cast<int>(sampleIndex[_subCarrier] + diffPeriodTime);
00148     }
00149     return currentFading[_subCarrier];
00150 }
00151 
00152 
00153 
00157 FTFadingFneighbourCorrelation::FTFadingFneighbourCorrelation(const wns::pyconfig::View& config)
00158     : FTFadingJakes(config),
00159       _neighbourCorrelationFactor(config.get<double>("neighbourCorrelationFactor"))
00160 {
00161     MESSAGE_SINGLE(NORMAL, logger, "Using FTFadingFneighbourCorrelation strategy with correlation factor= "<< _neighbourCorrelationFactor);
00162     assure(_neighbourCorrelationFactor <= 1, "Correlation factor out of order (bigger than 1)!");
00163 
00164     currentSampleIndex = 1;
00165 
00166     for (int subCarrierCounter = 0; subCarrierCounter < numberOfSubChannels; ++subCarrierCounter){
00167         jakesVector.push_back(new JakesFadingGenerator());
00168         jakesVector[subCarrierCounter]->initJakes(_dopFreq,samplingTime,_numWaves);
00169         subCarrierFading.push_back(jakesVector[subCarrierCounter]->getNextFadingValue());
00170         sampleIndex.push_back(1);
00171     }
00172 
00173     double correlatedFadingFirstSubcarrier = (1-_neighbourCorrelationFactor)*subCarrierFading[0] + _neighbourCorrelationFactor*subCarrierFading[numberOfSubChannels-1];
00174     currentFading.push_back(wns::Ratio::from_factor(correlatedFadingFirstSubcarrier));
00175     for (int subCarrierCounter = 1; subCarrierCounter < numberOfSubChannels; ++subCarrierCounter){
00176         double correlatedFading = (1-_neighbourCorrelationFactor)*subCarrierFading[subCarrierCounter] + _neighbourCorrelationFactor*currentFading[subCarrierCounter-1].get_factor();
00177             currentFading.push_back(wns::Ratio::from_factor(correlatedFading));
00178     }
00179 }
00180 
00181 wns::Ratio
00182 FTFadingFneighbourCorrelation::getFTFading(int _subCarrier)
00183 {
00184     simTimeType now = Now();
00185 
00186     if ( (now/samplingTime) >= (sampleIndex[_subCarrier]) ) {
00187         if (sampleIndex[_subCarrier] == currentSampleIndex) {
00188             double diffPeriodTime = (floor(now/samplingTime)+1) - (sampleIndex[_subCarrier]);
00189             // ^ should be int !
00190             for (int i = 0; i<diffPeriodTime; ++i){
00191                 for (int subCarrierCounter = 0; subCarrierCounter <  numberOfSubChannels; ++subCarrierCounter) {
00192                     subCarrierFading[subCarrierCounter] = jakesVector[subCarrierCounter]->getNextFadingValue();
00193                 }
00194 
00195                 double correlatedFadingFirstSubcarrier = (1-_neighbourCorrelationFactor)*subCarrierFading[0] + _neighbourCorrelationFactor*subCarrierFading[numberOfSubChannels-1];
00196                 currentFading[0] = wns::Ratio::from_factor(correlatedFadingFirstSubcarrier);
00197                 for (int subCarrierCounter = 1; subCarrierCounter < numberOfSubChannels; ++subCarrierCounter){
00198                     double correlatedFading = (1-_neighbourCorrelationFactor)*subCarrierFading[subCarrierCounter] + _neighbourCorrelationFactor*currentFading[subCarrierCounter-1].get_factor();
00199                     currentFading[subCarrierCounter] = wns::Ratio::from_factor(correlatedFading);
00200                 }
00201             }
00202 
00203             sampleIndex[_subCarrier] = static_cast<int>(sampleIndex[_subCarrier] + diffPeriodTime);
00204             currentSampleIndex = sampleIndex[_subCarrier];
00205         } else if (sampleIndex[_subCarrier] < currentSampleIndex) {
00206             sampleIndex[_subCarrier] = currentSampleIndex;
00207         }
00208     }
00209     return currentFading[_subCarrier];
00210 }
00211 

Generated on Wed May 23 03:31:53 2012 for openWNS by  doxygen 1.5.5