00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef ADAMOD_HEADER
00019 #define ADAMOD_HEADER
00020
00021 #include <iostream>
00022 #include <fstream>
00023 #include <complex>
00024 #include <vector>
00025 #include <cmath>
00026 #include <simthetic/signals.h>
00027 #include <simthetic/misc.h>
00028 #include <simthetic/phbib.h>
00029 #include <simthetic/basicdevicefactory.h>
00030 #include <simthetic/basicdevice.h>
00031 #include <simthetic/interfaces.h>
00032 #include "modulator.h"
00033 #include "channel.h"
00034 #include "interleaver.h"
00035 #include "multiplexer.h"
00036
00037 namespace simthlib {
00038
00039
00040
00041
00042
00044 enum loadingAlgorithm {
00045 DUMMY,
00046 CCB,
00047 SOFT_CCB,
00048 SPLIT_CCB,
00049 MULTILEVEL_LOADING,
00050 MULTILEVEL_NET_LOADING,
00051 MULTILEVEL_MSE_NET_LOADING
00052 };
00053 loadingAlgorithm string2loadingAlgorithm(const std::string&);
00054
00055 void initAdaptiveModulator(const std::string fileName, simth::Device** dev, simth::DeviceSystemIntf* sysPtr, int ID,
00056 const std::string& regionQualifier = "");
00057
00058
00059 class AdaptiveModulator;
00060 std::ostream& operator<<(std::ostream &os, const AdaptiveModulator& mod);
00061
00062
00063
00064
00067 class ModInfo
00068 {
00069 public:
00070 simth::ModType type;
00071 std::string name;
00072 std::string alternativeName;
00073 int bitsPerSymbol;
00074
00075 diff_type absDiff;
00076 };
00077
00078
00079
00080
00081
00084 class ModList
00085 {
00086 public:
00087 static int getNumBitsPerSym(simth::ModType modScheme);
00088 static std::string getName(simth::ModType modScheme);
00089
00090 static diff_type getDiffType(simth::ModType modScheme);
00091 static simth::ModType getModScheme(std::string name);
00092 static const ModInfo *getModInfo(std::string name);
00093 static const ModInfo *getModInfo(simth::ModType type);
00094
00095
00096 protected:
00097 static int numSchemes;
00098 static ModInfo info[];
00099
00100 };
00101
00102
00103
00104
00107 class ExtendedModScheme
00108 {
00109
00110 public:
00111 const ModInfo *scheme;
00112 ConstellationDiagram *constellation;
00113 MappingScheme *mapping;
00114
00115
00116 ExtendedModScheme(const ModInfo *scheme,
00117 std::auto_ptr<ConstellationDiagram> c_diagr,
00118 std::auto_ptr<MappingScheme> mapp);
00120 ExtendedModScheme(const ModInfo *scheme);
00121 ~ExtendedModScheme();
00122
00123 };
00124
00125
00126
00127
00128
00132 class ExtendedModList
00133 {
00134 friend class LoadingScheme;
00135 friend class MultilevelAdaptiveModulator;
00136 public:
00137 typedef simth::checkedVector<ExtendedModScheme*> schemes_lt;
00138 typedef std::map<simth::ModType, ExtendedModScheme*> schemes_mapt;
00139 typedef std::map<int, ExtendedModScheme*> bit_map_t;
00140
00141 private:
00142
00143 schemes_lt schemes;
00144
00145
00146 schemes_mapt schemes_map;
00147
00148 bit_map_t bit_map;
00149
00150 int numSchemes;
00151
00152
00153 void addScheme(ExtendedModScheme *e);
00154
00155 public:
00156 ExtendedModList();
00157
00160 bool hasScheme(simth::ModType t) const;
00161 void addScheme(const ModInfo *scheme,
00162 std::auto_ptr<ConstellationDiagram> c_diagr,
00163 std::auto_ptr<MappingScheme> mapp);
00164 void addScheme(const ModInfo *scheme);
00165 ExtendedModScheme *getSchemeForBitsPerSym(int bitsPerSym);
00166 ~ExtendedModList();
00167
00168 };
00169
00170
00176 enum adaptCriterion{
00177 EQUALIZER_CRITERION,
00178 EXP_CRITERION,
00179 CUSTOM_CRITERION,
00180 MIN_CRITERION
00181 };
00182
00183
00184
00187 class LoadingScheme
00188 {
00189 private:
00190 int numCarr;
00191 int avgBitsPerSym;
00192 int numGroups;
00193 bool schemeValid;
00194 bool powerScaling;
00195 ExtendedModList *modlist;
00196 simth::checkedVector<ExtendedModScheme*> schemeOnCarr;
00197 simth::checkedVector<double> carrierAmplification;
00198 simth::checkedVector<double> softLoadingInfo;
00199
00200 simth::checkedVector<int> possibleBitsPerSym;
00201 void updateDummy(int bitsPerSym, simth::FreqSignal* transfer);
00202 void updateCCB(int bitsPerSym, simth::FreqSignal* transfer);
00203 void updateSoftCCB(int bitsPerSym, simth::FreqSignal* transfer);
00204 void updateSplitCCB(int bitsPerSym, simth::FreqSignal* transfer, int numGroups=1);
00205 void updateMultilevel(int bitsPerSym, simth::FreqSignal* transfer);
00206
00207 public:
00208 int usedCarr;
00209
00211 LoadingScheme(int numCarr, ExtendedModList *modlist);
00212
00214 void update(int bitsPerSym, simth::FreqSignal* transfer, loadingAlgorithm algorithm,int numGroups=1);
00215
00219 bool isValid() const { return schemeValid; };
00220
00221 double getAmplification(int carrIndex){return carrierAmplification[carrIndex];};
00222 ExtendedModScheme *getModScheme(int carrierIndex);
00223 double getSoftLoadingInfo(int carrierIndex);
00224 void setPowerScaling(bool scaleIt){powerScaling=scaleIt;};
00225 void updateMultilevelNet(double netBitsPerSym, simth::FreqSignal* transfer, simth::checkedVector<double> codeRates);
00226 void updateMultilevelMseNet(double netBitsPerSym, simth::FreqSignal* transfer, simth::checkedVector<double> codeRates, simth::checkedVector<double> levelWeights, double snr=0,double twiddle=1.0, double twiddle2=1.0,adaptCriterion criterion=EXP_CRITERION);
00227 ~LoadingScheme();
00228 };
00229
00230
00231
00232
00233
00234
00236 class AdaptiveModulatorBase: public simth::CompatibleDevice
00237 {
00238 protected:
00239 int numCarr;
00240 int carrIndex;
00241 double carrDist;
00242 int oversampling;
00243 double guardTime;
00244
00245
00246 simth::FreqSignal *transfer;
00247 LoadingScheme *loading;
00248 loadingAlgorithm algorithm;
00249 int avgBitsPerSym;
00250 const Channel *channel;
00251 Interleaving *intl;
00252 bool powerScaling;
00253 int numGroups;
00254 int indexLength(int bitseqLength) const;
00255
00256
00257 void updateTransferFunc(const simth::FreqSignal& helpTrans);
00258
00259 public:
00260 AdaptiveModulatorBase(int numCarr, int oversampling, double carrDist,
00261 double guardTime,int avgBitsPerSym,loadingAlgorithm algorithm,
00262 ExtendedModList *modlist, Channel *channel,
00263 std::auto_ptr<Interleaving> interl);
00264 AdaptiveModulatorBase(int id, simth::DeviceSystemIntf *s, const simth::PropertyList& pl);
00265 virtual void updateInputLengths()=0;
00266 virtual void updateOutputLengths()=0;
00267 void print(std::ostream &os) const;
00268 virtual void refresh();
00269 void reset(){refresh();}
00270 virtual void process()=0;
00271 void setPowerScaling(bool scaleIt){powerScaling=scaleIt;loading->setPowerScaling(scaleIt);};
00272 void setNumGroups(int numGroups_){numGroups=numGroups_;};
00273 virtual ~AdaptiveModulatorBase()=0;
00274
00275 static std::auto_ptr<Interleaving>
00276 createInterleaving(int interLength, int interRows, int interCols, int interPlanes);
00277
00278 private:
00279 void init();
00280 };
00281
00282
00283
00284
00285
00286
00288 class AdaptiveModulator: public AdaptiveModulatorBase
00289 {
00290 private:
00291 void modulate(const simth::BitSeq &newBitSeq, simth::ModSeq* complSym, simth::LoadingInfoSeq* loadingSeq);
00292
00293
00294 void init();
00295
00296 public:
00297 AdaptiveModulator(int numCarr, int oversampling, double carrDist,
00298 double guardTime,int avgBitsPerSym,loadingAlgorithm algorithm,
00299 ExtendedModList *modlist, Channel *channel, std::auto_ptr<Interleaving> interl);
00300 AdaptiveModulator(int id, simth::DeviceSystemIntf *s, const simth::PropertyList& pl);
00301 ~AdaptiveModulator();
00302 void updateInputLengths();
00303 void updateOutputLengths();
00304 void process();
00305 void acceptNewData(int interfaceId);
00306 void startOfSimulation();
00307 };
00308
00309
00310
00311
00312
00313
00314
00320 class MultilevelAdaptiveModulator: public AdaptiveModulatorBase
00321 {
00322 private:
00323 unsigned int numLevels;
00324 int multiplexerBlockNumber;
00325 int demultiplexerBlockNumber;
00326 AdaptiveMultiplexerT<simth::BitSeq>* multiplexer;
00327 AdaptiveMultiplexerT<simth::BitSeq>* demultiplexer;
00328 void modulate(std::vector<simth::BitSeq*> newBitSeqArr, simth::ModSeq* complSym, simth::LoadingInfoSeq* loadingSeq);
00329 simth::checkedVector<int> levelInputLengths;
00330 simth::checkedVector<double> codeRates;
00331 simth::checkedVector<unsigned int> bitsTransmittedInLevel;
00332 double netBitsPerSym;
00333 double twiddleFactor;
00334 double twiddleFactor2;
00335 simth::checkedVector<double> levelWeights;
00336 double currentSnr;
00337 std::ofstream rateFile;
00338 std::string rateFileName;
00339 adaptCriterion criterion;
00340
00341 public:
00342 MultilevelAdaptiveModulator(int numCarr, int oversampling, double carrDist,
00343 double guardTime,int avgBitsPerSym,loadingAlgorithm algorithm,
00344 ExtendedModList *modlist, Channel *channel, std::auto_ptr<Interleaving> interl);
00345 MultilevelAdaptiveModulator(int id, simth::DeviceSystemIntf *s, const simth::PropertyList& pl);
00346 void updateInputLengths();
00347 void updateOutputLengths();
00348 void process();
00349 void refresh();
00350 void startOfSimulation();
00351 void endOfSimulation();
00352 void setMultiplexerNumber(int blockNumber){multiplexerBlockNumber=blockNumber;};
00353 void setDemultiplexerNumber(int blockNumber){demultiplexerBlockNumber=blockNumber;};
00354 void setCodeRates(simth::checkedVector<double> rates){codeRates=rates;};
00355 void setNetBitsPerSym(double netBits){netBitsPerSym=netBits;};
00356 void setTwiddleFactors(double twiddle, double twiddle2){twiddleFactor=twiddle;twiddleFactor2=twiddle2;};
00357 void setCriterion(adaptCriterion crit){criterion=crit;};
00358 void setLevelWeights(simth::checkedVector<double> weights){levelWeights=weights;};
00359 void logCodeRate(double newSnr);
00360 void setRateFileName(std::string name){rateFileName=name;};
00361 ~MultilevelAdaptiveModulator();
00362 };
00363
00364 }
00365
00366 #endif