Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

TDSPSymbolGenerator.h

Go to the documentation of this file.
00001 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef TDSPSYMBOLGENERATOR_H
00019 #define TDSPSYMBOLGENERATOR_H
00020 
00021 #include <TRandom.h>
00022 #include <TH1.h>
00023 #include <TH2.h>
00024 #include <Rtypes.h>
00025 #include <TDSPOutput1.h>
00026 #include <TDSPStatistics.h>
00027 
00032 // Options
00033 //
00034 #define kDEFAULT_OPTIONS               0
00035 
00036 #define NOT_DETECTED -1
00037 
00038 #define NUMSYMBOLS64
00039 
00040 class TDSPSymbolGenerator : public TDSPOutput1  {
00041   
00042  private:
00043   Bool_t      fAnalysed;      // Is there Analysed Data already ?
00044 
00045  protected:
00046   UInt_t      fDumpOptions;   // Dump options during simnulation
00047   UInt_t      fOptions;       //   Options
00048 #ifdef  NUMSYMBOLS64
00049   Long64_t    fAnalyseGrid;   //   how many detected symbols should analysed together 
00050   Long64_t    fNumAnalysed;
00051 #else
00052   UInt_t      fAnalyseGrid;   //   how many detected symbols should analysed together 
00053   UInt_t      fNumAnalysed;
00054 #endif
00055   Int_t       fNumSymbols;    //   Number of possible Symbols 
00056   Double_t   *fProbs;         
00057   
00058   Double_t   *fDetectSigmas;  
00059 
00060   TDSPSignal *fDecisionSignal; 
00061   
00062   Int_t       fNumISymbols;   
00063   Int_t       fNumISymbolsAlloc;  
00064   Int_t      *fISymbols;      
00065   Double_t   *fDetectProbs;   
00066   
00067 
00068   TComplex    fGlobalCorrection; 
00069   TComplex    fCorrection;       
00070   UInt_t      fCorrectionTrackingInterval;    
00071   UInt_t      fCorrectionTrackingIndex; 
00072   TDSPSignal* fReferenceSignal; 
00073   
00074   TString          Slot_Generate;
00075   TString          Slot_Update;
00076   TString          Slot_ReferenceUpdate;
00077 
00078   void             NormalizeProbs();
00079   
00080 
00081   virtual void     BookSymbols(Int_t num);
00082   virtual void     InitSymbols() = 0;
00083 
00084   // This split up of the generation routines 
00085   // allowing better optimizations
00086   
00087   virtual void     GenerateSymbols(Int_t, TComplex*); // Generate a lot of symbols 
00088   virtual Int_t    GenerateSymbol(TComplex*); // returns the symbol index
00089 
00090   virtual Int_t    DetectSymbol(TComplex&);   // returns the symbol index
00091 
00092   void             Analyse_Reset();
00093   void             Analyse_Finish();
00094   void             Analyse_Symbol(Int_t,TComplex*,
00095                   Int_t,TComplex*);
00096 
00097   
00098   // Distances
00099 
00100   Double_t         fMinDistance;
00101   Double_t         fMeanDistance;
00102   Double_t         fVarianceDistance;
00103   Double_t         fQWeightedDistance;
00104   Double_t         fQWeightedVarianceDistance;
00105 
00106   void             _calc_distances();
00107   void             _check_distances();
00108   Bool_t           _recalc_distances;
00109 
00110   void             DumpStep(); 
00111 
00112  public: 
00113 
00114   TComplex   *fSymbols;       
00115 
00116   Int_t      *fYields;        
00117   Int_t       fMisIdentified; //   number of misidentifications
00118   Double_t    fInEfficiency;  //   Inefficiency
00119   Double_t    fdInEfficiency; //   abs. Error of Inefficiency
00120 
00121   Double_t    fNoisePower;    //   Noise Power
00122   Double_t    fSignalPower;   //   sent Signal Power
00123   Double_t    fReceivedPower;   // received Signal Power
00124   TComplex    fAttentuation;   // the mean attentuation and phase rotation
00125   Double_t    fSINR;           //  SINR in dB
00126   Double_t    fLogSER;        //   LogSER 
00127   Double_t    fdLogSER;       //   Error of LogSER
00128 
00129   // Constructor and Destructor
00130   //
00131  
00132   TDSPSymbolGenerator(char *name, 
00133               Int_t,
00134               UInt_t = kDEFAULT_OPTIONS);
00135 
00136   ~TDSPSymbolGenerator();
00137 
00138   // Theoretic Error Rates
00139   //
00140   
00141   virtual Double_t SER(Double_t SNR);
00142   Double_t LogSER_dB(Double_t SNRdB);
00143   TComplex* GetSymbols() const { return fSymbols;};
00144   
00145 
00146   UInt_t GetNumSymbols() { return fNumSymbols;};
00147   void   SetAnalyseGrid(UInt_t a);
00148   void   SetSignalLength(Int_t num);
00149   void   ReduceSignalLength(Int_t num);
00150   Int_t  GetSignalLength() { return fNumISymbols;};
00151   Bool_t IsAnalysed() { return fAnalysed; };
00152   void   SetOption(Option_t*);
00153 
00154   Double_t GetSignalPower()  { return fSignalPower/fNumAnalysed;};
00155   Double_t GetReceivedPower()  { return fReceivedPower/fNumAnalysed;};
00156   Double_t GetIntNoisePower() { return fNoisePower/fNumAnalysed;};
00157   Double_t GetSINR() { return fSignalPower/fNoisePower;};
00158   TComplex GetAttentuation() { return fAttentuation/Double_t(fNumAnalysed);};
00159 
00160   Double_t GetDistance(Option_t *opt); // Get several distances from the alphabet
00161   
00162   TDSPSignal* GetDecisionSignal(); // Get the signal used for decision
00163 
00164   // Global Phase/Gain corrections
00165 
00166   TComplex& GetGlobalCorrection()  { return  fGlobalCorrection;};
00167   void      SetGlobalCorrection(TComplex c) { fGlobalCorrection=c;};
00168 
00169   // Tracking of Phase/Gain corrections (like CPEC/IDEAL_PHASE/REFERENCE_SIGNAL)
00170   // enable using SetOption(...)
00171 
00172   TComplex& GetCorrection()  { return fCorrection;}; 
00173   void      SetCorrection(TComplex c) { fCorrection=c;}; 
00174 
00175   UInt_t    GetCorrectionTrackingInterval() const { return fCorrectionTrackingInterval;}; 
00176   void      SetCorrectionTrackingInterval(UInt_t i) { fCorrectionTrackingInterval=i;}; 
00177 
00178   UInt_t EstimateNumSymbols(Double_t dError, 
00179                 UInt_t   d,
00180                 eEstimateNumSymbols method,
00181                 UInt_t   min=0); // Estimates the needed Number of Symbols
00182   
00183   UInt_t EstimateNumSymbols(Double_t dError, 
00184                 UInt_t   d = 10000,
00185                 char *method = "",
00186                 UInt_t   min=0); // Estimates the needed Number of Symbols
00187 
00188   // Slots
00189   
00190   void        Generate();
00191   TDSPSignal *Update(TDSPSignal*);
00192   void        ReferenceUpdate(TDSPSignal*s) { fReferenceSignal=s;};
00193 
00194   ClassDef(TDSPSymbolGenerator,1)
00195 
00196 };
00197 
00198 
00199 
00200 inline Int_t TDSPSymbolGenerator::GenerateSymbol(TComplex *c) {
00201   Double_t fR = gRandom->Rndm();
00202   Double_t prob = 0;
00203   
00204   for(Int_t i=0;i<fNumSymbols;i++) {
00205     prob += fProbs[i];
00206     if (fR < prob) {*c = fSymbols[i];return i;};
00207   }
00208   
00209   
00210   // This should only happen if fR==1
00211   // 
00212 
00213   Error("GenerateSymbol","(..) - Unnormal case fR = %f, prob = %f\n",
00214     fR,prob);
00215   
00216   *c = fSymbols[fNumSymbols-1];
00217 
00218   return fNumSymbols-1;
00219 }
00220 
00221 inline Int_t TDSPSymbolGenerator::DetectSymbol(TComplex& s) {
00222   
00223   Double_t len,s1;
00224   Double_t max_lik = 0;
00225 
00226   Int_t detected = NOT_DETECTED;
00227 
00228   // Calculate all Likelihoods
00229   //
00230   for(register Int_t i=0;i<fNumSymbols;i++) {
00231 
00232     len=Abs(s-fSymbols[i]);
00233     len*=-len;
00234 
00235     s1=2*fDetectSigmas[i];
00236     s1*=s1;
00237 
00238     fDetectProbs[i] = TMath::Exp(len/s1);
00239     
00240     if (fDetectProbs[i]>max_lik) {
00241       detected = i;
00242       max_lik = fDetectProbs[i];
00243     } else 
00244       if (fDetectProbs[i] == max_lik) {
00245     detected = NOT_DETECTED;
00246       }
00247   }
00248 
00249 
00250   return detected;
00251 
00252 }
00253 
00254 // Generate a lot of symbols
00255 //
00256 inline void TDSPSymbolGenerator::GenerateSymbols(Int_t num,
00257                          TComplex *c) {
00258   Int_t *sym = fISymbols;
00259   for(register Int_t i=num;i;--i) 
00260     *(sym++) = GenerateSymbol(c++);
00261 }
00262 
00263 // Generate one symbol
00264 //
00265 inline Double_t TDSPSymbolGenerator::LogSER_dB(Double_t SNRdB) {
00266   Double_t s=TMath::Power(10,SNRdB/10);
00267   return TMath::Log10(SER(s)); 
00268 }
00269 
00270 
00271 TDSPSymbolGenerator* Modulator(Option_t *name, Int_t param = 0);
00272 
00273 #endif

Generated on Fri Apr 23 16:23:43 2004 by doxygen 1.3.2