00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00115 #ifndef SIGNAL_HEADER
00116 #define SIGNAL_HEADER
00117
00118
00119
00120 #ifndef DLLIMPORT
00121 # if defined(__declspec) | defined(IS_WIN32)
00122 # if BUILDING_SIMTHETICBASE_DLL
00123 # define DLLIMPORT __declspec (dllexport)
00124 # else
00125 # define DLLIMPORT __declspec (dllimport)
00126 # endif
00127 # else
00128 # define DLLIMPORT
00129 # endif
00130 #endif
00131
00132
00133 #include <iostream>
00134 #include <vector>
00135 #include <stdexcept>
00136
00137 #include <simthetic/misc.h>
00138 #include <simthetic/array.h>
00139 #include <simthetic/checkedvector.h>
00140
00141 namespace simth
00142 {
00143
00146 const double HIGH_METRIC = 1e9;
00147
00148
00149
00157 enum SequenceType { LLV_SEQ, LLR_SEQ };
00158
00161 SequenceType string2SequenceType(const std::string& s);
00162
00163
00164
00165
00166 class NoAttributes;
00167
00168 template<class Val, class Attr, class Cont> class SignalSequenceStorage;
00169 template<class Val, class Attr, class Cont> class SignalSequenceAccess;
00170
00171
00192 template<class Val, class Attr, class Cont, class Stor, class Accs>
00193 class SignalSequenceBase
00194 {
00195 public:
00196
00198 typedef Stor storage_type;
00200 typedef Accs access_type;
00201
00202 typedef Val value_type;
00203 typedef Attr attributes_type;
00204 typedef Cont container_type;
00205
00206 typedef typename container_type::iterator iterator;
00207 typedef typename container_type::const_iterator const_iterator;
00208
00209 typedef typename container_type::reference reference;
00210 typedef typename container_type::const_reference const_reference;
00211
00221 SignalSequenceBase(iterator iterStart, iterator iterEnd, storage_type &seq);
00222
00228 SignalSequenceBase(storage_type &seq);
00229
00230
00234 virtual ~SignalSequenceBase()=0;
00235
00236
00241 SignalSequenceBase<value_type,attributes_type,container_type,storage_type,access_type>&
00242 operator=(const SignalSequenceBase<value_type,attributes_type,container_type,storage_type,access_type> &seq);
00243
00244
00247 reference operator[](size_t i);
00248
00251 const_reference operator[](size_t i) const;
00252
00257 size_t size() const { return size_; }
00258
00266 size_t capacity() const {return capacity_;}
00267
00268
00292 virtual void resize(size_t i);
00293
00294
00298 void seek(iterator newStart, iterator newEnd);
00299
00301 iterator begin();
00303 const_iterator begin() const;
00304
00306 iterator end();
00308 const_iterator end() const;
00309
00318 attributes_type& wAttributes() { return storage->wAttributes(); }
00319
00324 const attributes_type& rAttributes() const
00325 { return storage->rAttributes(); };
00326
00329 bool isAttributesLocked() const { return storage->isLocked(); };
00330
00331 protected:
00332
00339 SignalSequenceBase();
00340
00344 void seek(iterator newStart, iterator newEnd, storage_type& storage);
00345
00346 private:
00347
00348 storage_type* storage;
00349 iterator iter1;
00350 iterator iter2;
00351 size_t size_;
00352 size_t capacity_;
00353
00354 void invariante() const;
00355 };
00356
00383 template<class Val, class Attr = NoAttributes,
00384 class Cont = simth::checkedVector<Val> >
00385 class SignalSequence :
00386 public SignalSequenceBase<Val, Attr, Cont,
00387 SignalSequenceStorage<Val,Attr,Cont>,
00388 SignalSequenceAccess<Val,Attr,Cont> >
00389 {
00390 public:
00392 typedef class SignalSequenceStorage<Val,Attr,Cont> storage_type;
00394 typedef class SignalSequenceAccess<Val,Attr,Cont> access_type;
00395
00396 typedef Val value_type;
00397 typedef Attr attributes_type;
00398 typedef Cont container_type;
00399
00400 typedef typename container_type::iterator iterator;
00401 typedef typename container_type::const_iterator const_iterator;
00402
00403 typedef typename container_type::reference reference;
00404 typedef typename container_type::const_reference const_reference;
00405
00411 typedef class SignalSequenceBase<Val, Attr, Cont,
00412 storage_type, access_type> base_type;
00413
00414
00424 SignalSequence(iterator iterStart, iterator iterEnd, storage_type &seq);
00425
00431 SignalSequence(storage_type &seq);
00432
00433
00437 virtual ~SignalSequence()=0;
00438
00439 protected:
00440
00441 SignalSequence();
00442
00443 };
00444
00445
00463 template<class Val, class Attr, class Cont>
00464 class SignalSequenceAccess : public SignalSequence<Val,Attr,Cont>
00465 {
00466 private:
00467 typedef class SignalSequence<Val,Attr,Cont> base_type;
00468
00469 public:
00470
00471 typedef typename base_type::value_type value_type;
00472 typedef typename base_type::attributes_type attributes_type;
00473 typedef typename base_type::container_type container_type;
00474
00475 typedef typename base_type::iterator iterator;
00476 typedef typename base_type::const_iterator const_iterator;
00477
00478 typedef typename base_type::reference reference;
00479 typedef typename base_type::const_reference const_reference;
00480
00481 typedef typename base_type::storage_type storage_type;
00482
00492 SignalSequenceAccess(iterator iterStart, iterator iterEnd, storage_type &seq)
00493 : base_type (iterStart, iterEnd, seq) {};
00494
00499 SignalSequenceAccess(const SignalSequence<Val,Attr,Cont>& seq)
00500 : base_type (seq) {};
00501
00502 };
00503
00504
00505
00506
00507
00536 template<class Val, class Attr, class Cont>
00537 class SignalSequenceStorage : public SignalSequence<Val,Attr,Cont>
00538 {
00539 public:
00540 typedef typename Cont::iterator iterator;
00541 typedef typename Cont::const_iterator const_iterator;
00542
00543 typedef typename Cont::reference reference;
00544 typedef typename Cont::const_reference const_reference;
00545
00546 typedef Val value_type;
00547 typedef Attr attributes_type;
00548 typedef Cont container_type;
00549
00551 SignalSequenceStorage();
00552
00559 SignalSequenceStorage(size_t size, const value_type &val = value_type());
00560
00565 SignalSequenceStorage(const SignalSequence<value_type,attributes_type,container_type> &seq);
00566
00568 virtual ~SignalSequenceStorage();
00569
00572 size_t capacity() const { return ownStorage.capacity(); }
00573
00582 virtual void resize(size_t i);
00583
00591 attributes_type& wAttributes();
00592
00597 const attributes_type& rAttributes() const { return attributes_; }
00598
00604 void lock() {lock_ = true;}
00605
00609 void unlock() {lock_= false;}
00610
00613 bool isLocked() const {return lock_;}
00614
00615 private:
00616 container_type ownStorage;
00617 attributes_type attributes_ ;
00618 bool lock_;
00619
00620 void invariante() const;
00621 private:
00622 typedef class SignalSequence<Val,Attr,Cont> base_type;
00623 };
00624
00625
00626
00627
00628 template<class Val, class Attr, class Cont, class Stor, class Accs>
00629 inline typename SignalSequenceBase<Val,Attr,Cont,Stor,Accs>::reference
00630 SignalSequenceBase<Val,Attr,Cont,Stor,Accs>::operator[](size_t pos)
00631 {
00632 #if DEBUG==1
00633 if(pos >= size()) {
00634 throw std::runtime_error("reference SignalSequence<Cont>::operator[](size_t i) : i > size()");
00635 }
00636 invariante();
00637 #endif
00638 return *(iter1+pos);
00639 }
00640
00641 template<class Val, class Attr, class Cont, class Stor, class Accs>
00642 inline typename SignalSequenceBase<Val,Attr,Cont,Stor,Accs>::const_reference
00643 SignalSequenceBase<Val,Attr,Cont,Stor,Accs>::operator[](size_t pos) const
00644 {
00645 #if DEBUG==1
00646 if(pos >= size()) {
00647 throw std::runtime_error("SignalSequenceBase::operator[](size_t pos): pos >= size()");
00648 }
00649 invariante();
00650 #endif
00651 return *(iter1+pos);
00652 }
00653
00654
00655
00656
00657
00658
00659 template<class Val, class Attr, class Cont, class Stor, class Accs>
00660 std::ostream& operator<<(std::ostream &os, const SignalSequenceBase<Val,Attr,Cont,Stor,Accs>& seq)
00661 {
00662
00663 std::ios::fmtflags oldSettings = os.flags();
00664
00665 os.precision(2);
00666 size_t len = seq.size();
00667 for(int i = len-1;i >= 0 ; i--) {
00668 os<<" "<<seq[i]<<" ";
00669 }
00670 os<<" <- start";
00671
00672 os.flags(oldSettings);
00673 return os;
00674 }
00675
00676
00677 template<class T, class A, class Cont>
00678 std::ostream& operator<<(std::ostream &os, const SignalSequenceStorage<T,A,Cont>& seq)
00679 {
00680
00681 std::ios::fmtflags oldSettings = os.flags();
00682
00683 os.precision(2);
00684 size_t len = seq.size();
00685 for(int i = len-1;i >= 0 ; i--) {
00686 os<<" "<<seq[i]<<" ";
00687 }
00688 os<<" <- start";
00689
00690 os.flags(oldSettings);
00691 return os;
00692 }
00693
00694
00695
00696
00697
00701 class NoAttributes
00702 {
00703 public:
00704 bool operator==(const NoAttributes& ) const {return true;}
00705 bool operator!=(const NoAttributes& ) const {return false;}
00706 };
00707
00708
00709
00710
00711
00712
00713
00714
00715
00718 class DLLIMPORT TimeSignalAttributes
00719 {
00720
00721 double dT;
00722
00723 public:
00724
00725 TimeSignalAttributes();
00726 virtual ~TimeSignalAttributes();
00727
00730 virtual double deltaT() const { return dT; }
00733 virtual void setDeltaT(double deltaTime);
00734
00735 bool operator==(const TimeSignalAttributes& att) const;
00736 bool operator!=(const TimeSignalAttributes& att) const;
00737
00738 };
00739
00740
00741
00742
00743 inline bool TimeSignalAttributes::operator==(const TimeSignalAttributes& att) const
00744 {
00745 return deltaT() == att.deltaT();
00746 }
00747
00748 inline bool TimeSignalAttributes::operator!=(const TimeSignalAttributes& att) const
00749 {
00750 return !operator==(att);
00751 }
00752
00753
00754
00755
00756
00757
00758
00759
00762 class DLLIMPORT FreqSignalAttributes
00763 {
00764
00765 double dF;
00766
00767 public:
00768
00769 FreqSignalAttributes();
00770 virtual ~FreqSignalAttributes();
00771
00774 virtual double deltaF() const { return dF; }
00777 virtual void setDeltaF(double deltaFreq);
00778
00779
00780 bool operator==(const FreqSignalAttributes& att) const;
00781 bool operator!=(const FreqSignalAttributes& att) const;
00782
00783 };
00784
00785
00786
00787
00788
00789
00790 inline bool FreqSignalAttributes::operator==(const FreqSignalAttributes& att) const
00791 {
00792 return deltaF() == att.deltaF();
00793 }
00794
00795 inline bool FreqSignalAttributes::operator!=(const FreqSignalAttributes& att) const
00796 {
00797 return !operator==(att);
00798 }
00799
00800
00801
00802
00803
00804
00808 typedef SignalSequence<bool> BoolSeq;
00809
00811 typedef SignalSequence<int> IntSeq;
00812
00814 typedef SignalSequence<double> DoubleSeq;
00815
00817 typedef SignalSequence<Complex> ComplexSeq;
00818
00820 typedef simth::Array<Complex> ComplexArray;
00822
00823
00824
00825
00826
00830 typedef BoolSeq BitSeq;
00831
00837 typedef IntSeq ModIndSeq;
00838
00840 typedef DoubleSeq PhaseSeq;
00841
00843 typedef ComplexSeq ModSeq;
00844
00848 typedef ComplexArray SignalSym;
00849
00852 typedef SignalSequence<SignalSym> SymSeq;
00853
00854
00857 typedef double LlrType;
00858
00859
00862 typedef double LlvType;
00863
00869 typedef simth::checkedVector<LlvType> Llv;
00870
00881 typedef SignalSequence<LlrType> LlrSeq;
00882
00890 typedef SignalSequence<Complex,TimeSignalAttributes> TimeSignal;
00891
00899 typedef SignalSequence<Complex,FreqSignalAttributes> FreqSignal;
00901
00902
00903
00904 std::ostream& operator<<(std::ostream &os, const BitSeq &bits);
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00916 class LlvSeqAttributes
00917 {
00918
00919 friend class LlvSeq;
00920 friend class LlvSeqStorage;
00921
00922 unsigned bitsPerState_;
00923 size_t numStates_;
00924 void setBitsPerState(unsigned numBits);
00925
00926 void invariante() const;
00927 public:
00928 LlvSeqAttributes();
00929 LlvSeqAttributes(unsigned bitsPerState);
00930 unsigned bitsPerState() const {return bitsPerState_;}
00931 size_t numStates() const { return numStates_;}
00932
00933 bool operator==(const LlvSeqAttributes& att) const;
00934 bool operator!=(const LlvSeqAttributes& att) const;
00935
00936 };
00937
00938
00947 class LlvSeqStorage;
00948
00957 class LlvSeqAccess;
00958
00968 class LlvSeq : public SignalSequenceBase<Llv, LlvSeqAttributes, simth::checkedVector<Llv>, LlvSeqStorage, LlvSeqAccess>
00969 {
00970 public:
00971
00973 typedef LlvSeqStorage storage_type;
00975 typedef LlvSeqAccess access_type;
00976
00977
00978 typedef Llv value_type;
00979 typedef LlvSeqAttributes attributes_type;
00980 typedef simth::checkedVector<value_type> container_type;
00981
00982 typedef container_type::iterator iterator;
00983 typedef container_type::const_iterator const_iterator;
00984
00985 typedef container_type::reference reference;
00986 typedef container_type::const_reference const_reference;
00987
00988
00991 LlvSeq(iterator iterStart,iterator iterEnd, storage_type& origStorage);
00992
00995 LlvSeq(const LlvSeq& sig);
00996
00997 virtual ~LlvSeq() = 0;
00998
00999 LlvSeq& operator=(const LlvSeq& seq);
01000
01001 void resize(size_t newLength, unsigned newBitsPerSymbol);
01002 void resize(size_t newLength);
01003
01004 protected:
01005
01011 LlvSeq( );
01012
01013 private:
01014 typedef SignalSequenceBase<value_type, attributes_type, container_type, storage_type, access_type> base_type;
01015 };
01016
01017
01019 class LlvSeqStorage : public LlvSeq
01020 {
01021 public:
01022
01023 typedef LlvSeq::value_type value_type;
01024 typedef LlvSeq::attributes_type attributes_type;
01025 typedef LlvSeq::container_type container_type;
01026 typedef LlvSeq base_type;
01027
01028 typedef container_type::iterator iterator;
01029 typedef container_type::const_iterator const_iterator;
01030
01031 typedef container_type::reference reference;
01032 typedef container_type::const_reference const_reference;
01033
01034
01042 LlvSeqStorage(size_t size, unsigned bitsPerState);
01043
01044 LlvSeqStorage(size_t size, const value_type& val = value_type());
01045
01046 LlvSeqStorage(const LlvSeq& seq);
01047
01048 virtual ~LlvSeqStorage();
01049
01050 LlvSeqStorage& operator=(const LlvSeqStorage& seq);
01051
01054 size_t capacity() const { return ownStorage.capacity(); }
01055
01056 void resize(size_t newLength, unsigned newBitsPerSymbol);
01057 void resize(size_t newLength);
01058
01066 attributes_type& wAttributes();
01067
01072 const attributes_type& rAttributes() const { return attributes_; }
01073
01079 void lock() {lock_ = true;}
01080
01084 void unlock() {lock_= false;}
01085
01088 bool isLocked() const {return lock_;}
01089
01090 private:
01091 container_type ownStorage;
01092 attributes_type attributes_ ;
01093 bool lock_;
01094
01095 void invariante() const {};
01096
01097
01098 };
01099
01101 class LlvSeqAccess : public LlvSeq
01102 {
01103 public:
01105 LlvSeqAccess(iterator iterStart,
01106 iterator iterEnd, LlvSeqStorage &origStorage) ;
01107
01109 LlvSeqAccess(const LlvSeq& sig);
01110
01113
01114
01115 virtual ~LlvSeqAccess() {};
01116
01117
01118 LlvSeqAccess& operator=(const LlvSeqAccess& seq);
01119 };
01120
01121
01122
01123
01124
01125
01136 unsigned bits2value(BitSeq::const_iterator first,
01137 BitSeq::const_iterator behindLast);
01138
01140 inline bool value2bit(unsigned index, size_t bitPos)
01141 {
01142 #if DEBUG==1
01143 if(bitPos > MAX_BITS_PER_SYMBOL) {
01144 throw std::out_of_range("value2bit: bitPos > MAX_BITS_PER_SYMBOL");
01145 }
01146 #endif
01147
01148 return index & ( 0x1 << bitPos );
01149 }
01150
01154 void value2bits(unsigned index,
01155 BitSeq::iterator first, BitSeq::iterator behindLast);
01156
01164 inline double llrValue2llvValue(LlrType llrValue, bool bitValue)
01165 {
01166 if(bitValue == 0) {
01167 return (llrValue/2.0);
01168 }
01169 else {
01170 return -(llrValue/2.0);
01171 }
01172 }
01173
01178 inline bool llrValue2bit(LlrType llrValue)
01179 {
01180 if(llrValue > 0.0) {
01181 return 0;
01182 }
01183 else {
01184 return 1;
01185 }
01186 }
01187
01192 inline LlvType bit2llvValue(bool bit, bool index)
01193 {
01194 if(bit == index) {
01195 return 1.0;
01196 }
01197 else {
01198 return -1.0;
01199 }
01200 }
01201
01208 inline LlrType bit2llrValue(bool bit)
01209 {
01210 return bit==1? -2.0 : 2.0;
01211 }
01212
01213
01216 void bitSeq2llvSeq(const BitSeq& bits, LlvSeq& llv);
01219 void bitSeq2llvSeq(const BitSeq& bits, LlvSeq* llv);
01220
01221 void llrSeq2bitLlvSeq(const LlrSeq& llr, LlvSeq& llv);
01222 void llrSeq2bitLlvSeq(const LlrSeq& llr, LlvSeq* llv);
01223
01224 void llrSeq2bitSeq(const LlrSeq& from, BitSeq& bits);
01225 void llrSeq2bitSeq(const LlrSeq& from, BitSeq* bits);
01226
01227 void llvSeq2bitLlvSeq(const LlvSeq& from, LlvSeq& bitLlv);
01228 void llvSeq2bitLlvSeq(const LlvSeq& from, LlvSeq* bitLlv);
01229
01230 void llvSeq2llrSeq(const LlvSeq& from, LlrSeq& to,
01231 size_t outputLength = 0);
01232 void llvSeq2llrSeq(const LlvSeq& from, LlrSeq* to,
01233 size_t outputLength = 0);
01234
01235 void bitLlvSeq2llvSeq(const LlvSeq& from, LlvSeq& to,
01236 unsigned bitsPerState=0);
01237 void bitLlvSeq2llvSeq(const LlvSeq& from, LlvSeq* to,
01238 unsigned bitsPerState=0);
01244 void bitSeq2IntSeq(const simth::BitSeq& bs, simth::checkedVector<int>& IntSeq, int numBits);
01245
01246
01247 enum ConversionFlag {CUT, FILL, FIT};
01248 size_t getSymSeqLength(size_t bitSeqLen, unsigned bitsPerSym,
01249 ConversionFlag flag = FIT);
01250
01251
01257
01267 enum ModType {
01268 UNMOD,
01269 PSK_2,
01270 PSK_4,
01271 PSK_8,
01272 RAM_8,
01273 QAM_4,
01274 QAM_16,
01275 QAM_32,
01276 RAM_32,
01277 QAM_64,
01278 QAM_128,
01279 RAM_128,
01280 QAM_256
01281 };
01282
01291 class LoadingInfo
01292 {
01293 public:
01294 ModType modtype;
01295 double amplification;
01296 };
01297
01306 typedef simth::SignalSequence<LoadingInfo> LoadingInfoSeq;
01307
01309
01310
01311
01312 }
01313
01314 #endif