00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef MODULATOR_HEADER
00029 #define MODULATOR_HEADER
00030
00031 #include <iostream>
00032 #include <fstream>
00033 #include <complex>
00034 #include <vector>
00035 #include <cmath>
00036
00037 #include <simthetic/signals.h>
00038 #include <simthetic/misc.h>
00039 #include <simthetic/phbib.h>
00040 #include <simthetic/basicdevice.h>
00041
00042 #include "bitmapping.h"
00043 #include "modulationschemes.h"
00044 #include "modulationmodes.h"
00045
00046
00047 namespace simthlib
00048 {
00049
00050 using simth::Complex;
00051
00052 class Modulator;
00053 class Demodulator;
00054
00055
00056 std::ostream& operator<<(std::ostream &os, const Modulator& mod);
00057
00058 class AdachiDemodulator;
00059
00060
00066 class Modulator : public simth::Device
00067 {
00068 friend class AdachiDemodulator;
00069 private:
00070
00071
00072 MappingScheme* usedMapping;
00073
00074
00075
00076
00077 protected:
00078
00079 virtual int getBitsPerSymbol() const = 0;
00080
00081 virtual Complex getComplSymbol(int symbolIndex) const = 0;
00082
00083 int getSymbolIndex(int dataValue) const
00084 {return usedMapping->getSymbolIndex(dataValue);}
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00112
00113
00118
00119
00124
00125
00126
00127
00137 void bitSeq2IndexSeq(const simth::BitSeq& newBitSeq, simth::ModIndSeq* indexSeq);
00138
00139
00140
00145 void indexSeq2complSymbolSeq(const simth::ModIndSeq &modIndexes, simth::ModSeq* complSym);
00146
00147 int indexLength(int bitLen) const;
00148
00149 public:
00150
00154 Modulator(int deviceID, simth::DeviceSystemIntf* system,
00155 const simth::PropertyList& pl,
00156 std::auto_ptr<MappingScheme> mapp);
00157
00162 virtual ~Modulator() = 0;
00163
00164 virtual void updateInputLengths();
00165
00166
00171 virtual void modulate(const simth::BitSeq& bits, simth::ModSeq* modSymbols)=0;
00172
00173
00174 virtual int getNumStates() const = 0;
00175
00176
00177
00178
00179
00180
00181
00182 virtual void process();
00183
00184 virtual void print(std::ostream &os) const;
00185
00186 virtual void startOfSimulation();
00187
00191 static void init(const std::string fileName, simth::Device** dev, simth::DeviceSystemIntf* sysPtr, int ID,
00192 const std::string& regionQualifier = "");
00193
00195 virtual const ConstellationDiagram* constellation() const = 0;
00196 };
00197
00198
00199
00200
00201
00208 class AbsModulator : public Modulator
00209 {
00210 private:
00211
00212 protected:
00213
00214 public:
00215 AbsModulator(int deviceID, simth::DeviceSystemIntf* system,
00216 const simth::PropertyList& pl,
00217 std::auto_ptr<MappingScheme> mapp)
00218 : Modulator(deviceID, system, pl, mapp) {};
00219
00223 virtual ~AbsModulator() = 0;
00224
00225 virtual void updateOutputLengths();
00226
00227 virtual void modulate(const simth::BitSeq&, simth::ModSeq *modulatedSeq);
00228 };
00229
00230
00231
00232 class QamModulator : public AbsModulator
00233 {
00234
00235 private:
00236
00237 QamConstellationDiagram* usedConstellationDiagram;
00238
00239
00240 virtual int getBitsPerSymbol() const
00241 {return usedConstellationDiagram->getBitsPerSymbol();}
00242
00243
00244 virtual Complex getComplSymbol(int symbolIndex) const
00245 {return usedConstellationDiagram->getComplSymbol(symbolIndex);}
00246
00247 void scaleConstellation(Complex scale){usedConstellationDiagram->scaleConstellation(scale);};
00248
00249 public:
00251 QamModulator(int deviceID, simth::DeviceSystemIntf* system,
00252 const simth::PropertyList& pl);
00253
00254 virtual ~QamModulator();
00255
00256 virtual int getNumStates() const {return usedConstellationDiagram->getNumStates();}
00257
00258 virtual void print(std::ostream &os) const;
00259
00260 const ConstellationDiagram* constellation() const
00261 {return usedConstellationDiagram;}
00262 };
00263
00264
00265
00266
00267
00273 class PskModulator : public AbsModulator
00274 {
00275 private:
00276
00277
00278 PskConstellationDiagram* usedConstellationDiagram;
00279
00280
00281 virtual int getBitsPerSymbol() const
00282 {return usedConstellationDiagram->getBitsPerSymbol();}
00283
00284
00285 virtual Complex getComplSymbol(int symbolIndex) const
00286 {return usedConstellationDiagram->getComplSymbol(symbolIndex);}
00287
00288
00289 void scaleConstellation(Complex scale){usedConstellationDiagram->scaleConstellation(scale);};
00290
00291
00292 public:
00295 PskModulator(int deviceID, simth::DeviceSystemIntf* system,
00296 const simth::PropertyList& pl);
00297
00298 virtual ~PskModulator();
00299
00300 virtual void startOfSimulation();
00301
00302 virtual int getNumStates() const {return usedConstellationDiagram->getNumStates();}
00303
00304 virtual void print(std::ostream &os) const;
00305
00306 const ConstellationDiagram* constellation() const
00307 {return usedConstellationDiagram;}
00308 };
00309
00310
00311
00312
00313
00314
00320 class ApskModulator : public AbsModulator
00321 {
00322 private:
00323
00324
00325 ApskConstellationDiagram* usedConstellationDiagram;
00326
00327
00328 virtual int getBitsPerSymbol() const
00329 {return usedConstellationDiagram->getBitsPerSymbol();}
00330
00331
00332 virtual Complex getComplSymbol(int symbolIndex) const
00333 {return usedConstellationDiagram->getComplSymbol(symbolIndex);}
00334
00335
00336 public:
00344 ApskModulator(int deviceID, simth::DeviceSystemIntf* system,
00345 const simth::PropertyList& pl);
00346
00353 ApskModulator(int deviceID, simth::DeviceSystemIntf* system,
00354 const simth::PropertyList& pl,
00355 int bitsPerAmpl,int bitsPerPhase,
00356 double amplFactor, double amplAddend=0.0,
00357 map_type mappMode = GRAY);
00358
00359
00360 virtual ~ApskModulator();
00361
00362 virtual void startOfSimulation();
00363
00364 virtual int getNumStates() const {return usedConstellationDiagram->getNumStates();}
00365
00366 virtual void print(std::ostream &os) const;
00367
00368 const ConstellationDiagram* constellation() const
00369 {return usedConstellationDiagram;}
00370 };
00371
00372
00373
00383 class DiffModulator : public Modulator
00384 {
00385 private:
00386
00387
00388 protected:
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00402
00403
00406 void ModSingle(const simth::ModIndSeq &mis, simth::ModSeq* &sym){};
00407
00410 void ModCross(const simth::ModIndSeq &mis, simth::ModSeq* &sym){};
00411
00418 virtual void diffCoding(const simth::ModIndSeq& absSeq, simth::ModIndSeq* diffSeq);
00419
00424 virtual int diffOperation(int refIndex, int informationIndex) const = 0;
00425
00426
00427 public:
00428
00429 DiffModulator(int deviceID, simth::DeviceSystemIntf* system,
00430 const simth::PropertyList& pl,
00431 std::auto_ptr<MappingScheme> mapp)
00432 : Modulator(deviceID, system, pl, mapp) {};
00433
00437 virtual ~DiffModulator() = 0;
00438
00439 virtual void updateOutputLengths();
00440
00441 virtual void modulate(const simth::BitSeq&, simth::ModSeq *);
00442 };
00443
00444
00445
00456 class DiffSubSeqModulator : public DiffModulator
00457 {
00458 private:
00459
00460 int subSeqLen;
00461
00462 protected:
00463
00464
00469 virtual void diffCoding(const simth::ModIndSeq& absSeq, simth::ModIndSeq* diffSeq);
00470
00474 virtual int diffOperation(int smybolIndex1, int symbolIndex2) const = 0;
00475
00476
00477 public:
00478
00479 DiffSubSeqModulator(int deviceID, simth::DeviceSystemIntf* system,
00480 const simth::PropertyList& pl,
00481 std::auto_ptr<MappingScheme> mapp,
00482 int subSeqLength);
00483
00484
00488 virtual ~DiffSubSeqModulator() = 0;
00489 virtual void print(std::ostream &os) const;
00490 };
00491
00492
00501 class DaskModulator : public DiffSubSeqModulator
00502 {
00503
00504 private:
00505
00506 ApskConstellationDiagram* usedConstellationDiagram;
00507
00508
00509 virtual int getBitsPerSymbol() const
00510 {return usedConstellationDiagram->getBitsPerSymbol();}
00511
00512
00513 virtual Complex getComplSymbol(int symbolIndex) const
00514 {return usedConstellationDiagram->getComplSymbol(symbolIndex);}
00515
00516
00517 virtual int diffOperation(int symbolIndex1, int symbolIndex2) const
00518 { return (symbolIndex1 + symbolIndex2) % getNumStates();}
00519
00520 public:
00522 DaskModulator(int deviceID, simth::DeviceSystemIntf* system,
00523 const simth::PropertyList& pl);
00524
00525 virtual ~DaskModulator();
00526
00527 int getNumStates() const {return usedConstellationDiagram->getNumStates();}
00528
00529 virtual void print(std::ostream &os) const;
00530
00531 const ConstellationDiagram* constellation() const
00532 {return usedConstellationDiagram;}
00533 };
00534
00535
00536
00537
00538
00547 class DpskModulator : public DiffSubSeqModulator
00548 {
00549
00550 private:
00551
00552 PskConstellationDiagram* usedConstellationDiagram;
00553
00554
00555 virtual int getBitsPerSymbol() const
00556 {return usedConstellationDiagram->getBitsPerSymbol();}
00557
00558
00559 virtual Complex getComplSymbol(int symbolIndex) const
00560 {return usedConstellationDiagram->getComplSymbol(symbolIndex);}
00561
00562
00563 virtual int diffOperation(int symbolIndex1, int symbolIndex2) const
00564 { return (symbolIndex1 + symbolIndex2) % getNumStates();}
00565
00566 public:
00569 DpskModulator(int deviceID, simth::DeviceSystemIntf* system,
00570 const simth::PropertyList& pl);
00571
00572 virtual ~DpskModulator();
00573
00574 virtual void startOfSimulation();
00575
00576 int getNumStates() const {return usedConstellationDiagram->getNumStates();}
00577
00578 virtual void print(std::ostream &os) const;
00579
00580 const ConstellationDiagram* constellation() const
00581 {return usedConstellationDiagram;}
00582 };
00583
00591 class DapskModulator : public DiffSubSeqModulator
00592 {
00593 private:
00594
00595 ApskConstellationDiagram* usedConstellationDiagram;
00596
00597
00598 virtual int getBitsPerSymbol() const
00599 {return usedConstellationDiagram->getBitsPerSymbol();}
00600
00601
00602 virtual Complex getComplSymbol(int symbolIndex) const
00603 {return usedConstellationDiagram->getComplSymbol(symbolIndex);}
00604
00605
00606 int getNumAmplitudeBits() const
00607 {return usedConstellationDiagram->bitsPerAmpl();}
00608
00609 int getNumPhaseBits() const
00610 {return usedConstellationDiagram->bitsPerPhase();}
00611
00615 int getNumAmplitudes() const
00616 {return 1<<(usedConstellationDiagram->bitsPerAmpl());}
00617
00618
00622 int getNumPhases() const
00623 {return 1<<(usedConstellationDiagram->bitsPerPhase());}
00624
00625
00626 virtual int diffOperation(int symbolIndex1, int symbolIndex2) const;
00627
00628 public:
00639 DapskModulator(int deviceID, simth::DeviceSystemIntf* system,
00640 const simth::PropertyList& pl);
00641
00642
00650 DapskModulator(int deviceID, simth::DeviceSystemIntf* system,
00651 const simth::PropertyList& pl,
00652 int bitsPerAmpl,int bitsPerPhase, double amplFactor,
00653 double amplAddend,
00654 int subSeqLen, map_type mappMode = GRAY);
00655
00656
00657 virtual ~DapskModulator();
00658
00659 virtual void startOfSimulation();
00660
00661 int getNumStates() const {return usedConstellationDiagram->getNumStates();}
00662
00663 virtual void print(std::ostream &os) const;
00664
00665 const ConstellationDiagram* constellation() const
00666 {return usedConstellationDiagram;}
00667 };
00668
00669
00670
00671 }
00672
00673 #endif // MODULATOR_HEADER