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

TDSPFifo.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 TDSPFIFO_H
00019 #define TDSPFIFO_H
00020 
00021 
00022 #include <Rtypes.h>
00023 #include <TError.h>
00024 #include "TDSPSignal.h"
00025 
00056 class TDSPSignal;
00057 class TDSPFifo {
00058 
00059   
00060  protected:
00061   
00062   Int_t     fDepth; //  The Size/Depth of the Fifo
00063   Int_t     fIndex; //  The actual index in the Fifo (is the top value)
00064   Int_t     fFill;  //  The Fill Status of the Fifo
00065 
00066   TComplex *fBlock; 
00067 
00068   void   Fill(); // Update the Fill Status
00069 
00070   static UInt_t  fPerLine;
00071 
00072  public: 
00073 
00074   TDSPFifo(Int_t depth=0);
00075   virtual ~TDSPFifo();
00076 
00077   static void ValuesPerLine(UInt_t p) { fPerLine = p;}; // How many Values to Print per line (using cout...)
00078   Int_t GetIndex(Int_t); // Transform a index into a cyclic index
00079 
00080   Int_t GetDepth() const { return fDepth;}; // return the depth of the fifo
00081   Int_t GetFill() const { return fFill; }; // return the fill depth of the fifo
00082   TComplex* GetBlock() const { return fBlock; }; // return the Block address of the fifo
00083   
00084   Bool_t WasFull() {  return fFill>=fDepth;};  // Is and was the Fifo full (for requests after shifts)
00085   Bool_t IsFull()  { return fFill==fDepth-1;}; // Is the Fifo full now (for request before shifts)
00086   void  Reset(); // reset the fifo
00087  
00088   TComplex& operator()(); // Get/Set the Top Value of the Fifo
00089   TComplex& operator()(Int_t i); // Get/Set the Value at Depth of "i" of the Fifo
00090   TComplex& operator[](Int_t i); // Get/Set the Value at direct position in the fifo (not cycled)
00091 
00092   friend istream    &operator>>(istream&,TDSPFifo&);
00093   friend ostream    &operator<<(ostream&,TDSPFifo&);
00094   friend istream    &operator>>(istream&,TDSPFifo*);
00095   friend ostream    &operator<<(ostream&,TDSPFifo*);
00096 
00097   void      Print();
00098   void      Input();
00099 
00100   // Implementation of cyclic Index operations (next/back etc.)
00101   //
00102   Int_t GetIndex() const { return fIndex; };  // return the actual cyclic index (eq. to GetIndex(0))
00103   void  Next()   { if (fIndex++==fDepth) fIndex=0;} // next with intern cyclic Index
00104   Int_t Next(Int_t current) {return current++==fDepth ? 0 : current;} // next with extern cyclic Index
00105 
00106   void  Back()   { fIndex= fIndex ? fIndex-1 : fDepth;} // back with intern cyclic Index
00107   Int_t Back(Int_t current) {return current ? current-1 : fDepth;} // back with extern cyclic Index
00108   
00109   TComplex&   Shift(Double_t x) { return Shift(TComplex(x,0)); };
00110   TComplex&   Shift(TComplex c); // Put a new Value on the top of the  Fifo and return the lowest value 
00111   TDSPVector* Shift(TDSPVector *input, TDSPVector *output); // Fills from a vector, returns into a vector
00112   void        FillFrom(TDSPVector *input); // Fills the fifo from a vector
00113   TDSPVector* FillTo(TDSPVector* output=NULL); // Fills the content into a vector
00114   void        SetDepth(Int_t depth); // Set the Depth of the Fifo
00115   void        Set(const TComplex&);                      // Set all values of the fifo to c
00116   void        Set(Double_t);                             // Set all values of the fifo to c
00117   void        Zeros() { Set(0.0); };                     // Set all values of the fifo to 0
00118   void        Ones() { Set(1.0);};                       // Set all values of the fifo to 1
00119  
00120   TComplex    Dot(TComplex *fir_vec, Bool_t conj=kTRUE,Int_t l=0); // Dot-product (conj this?) <this fifo, compl.array> (l=length with 0=fifofill)
00121   TComplex    Dot(TDSPVector *fir, Bool_t conj=kTRUE);   // Dot-product (conj this?) <this fifo, TDSPVector> 
00122   TComplex    Dot(TDSPFifo   *fir, Bool_t conj=kTRUE);   // Dot-product (conj this?) <this fifo, other fifo>
00123 
00124   TDSPVector *filter(TDSPVector *out,
00125              TDSPVector *fir,
00126              TDSPVector *iir = NULL); // Use the fifo-content as a filter input
00127 
00128   TGraph*   Graph(Option_t* = "complex", TGraph *in=NULL, Double_t dx=1.0, Double_t xoff=0.0);
00129   void      Draw(Option_t* = "", Double_t dx=1.0, Double_t xoff=0.0); //*MENU*
00130 
00131   
00132   TDSPFifo &operator=(const Double_t x)  { Set(x); return *this;};
00133   TDSPFifo &operator=(const TComplex& c) { Set(c); return *this;};
00134 
00135   ClassDef(TDSPFifo,0)
00136 
00137 };
00138 
00139 
00140 
00141 // FIR/IIR - filtering using the fifo-content as input signal
00142 //
00143 
00144 TDSPVector *filter(TDSPFifo   *in,
00145            TDSPVector *out,
00146            TDSPVector *fir,
00147            TDSPVector *iir = NULL);
00148 
00149 // FIR/IIR - filtering using the fifo-content as input signal
00150 //
00151 
00152 TComplex    filter(TDSPFifo   *in,
00153            TDSPFifo   *out,
00154            TDSPVector *fir,
00155            TDSPVector *iir = NULL);
00156 
00157 inline TDSPVector *TDSPFifo::filter(TDSPVector *out,
00158                     TDSPVector *fir,
00159                     TDSPVector *iir) { // Use the fifo-content as a filter input
00160 
00161   return ::filter(this,out,fir,iir);
00162 
00163 }
00164 inline TComplex& TDSPFifo::operator()() {
00165   return fBlock[fIndex];
00166 }
00167 
00168 
00169 inline TComplex& TDSPFifo::operator[](Int_t i) {
00170   return fBlock[i];
00171 }
00172 
00173 inline Int_t TDSPFifo::GetIndex(Int_t i) {
00174   if (i<0) {
00175     i++;
00176     i%=fFill;
00177     i+=fFill-1;
00178   } else 
00179     i %= fFill;         // can be seen as periodic
00180   i += Next(fIndex);   // index "0" correspond to fIndex+1 (the place of then oldest entry ...)
00181   if (i>fFill) return i-fFill-1;
00182   return i;
00183 }
00184 
00185 inline TComplex& TDSPFifo::operator()(Int_t i) {
00186   return fBlock[GetIndex(i)];
00187 }
00188 
00189 
00190 inline void TDSPFifo::Fill() {
00191   if (!WasFull()) fFill++;
00192 }
00193 
00194 
00195 inline TComplex& TDSPFifo::Shift(TComplex c) {
00196   // Put the new Value on the Top
00197   //
00198   (*this)() = c;
00199 
00200   // Increase the cyclic index
00201   //
00202   Next();
00203   
00204   // Update the Fill Status
00205   //
00206   Fill();
00207   
00208   // Checking Fill Status of the Fifo
00209   //
00210   if (!WasFull())
00211     return ComplexZero;
00212 
00213   // Return the bottom value
00214   return (*this)();
00215 }
00216 
00217 inline TComplex TDSPFifo::Dot(TComplex *fir_vec, Bool_t conj, Int_t len) {
00218   
00219   TComplex      tmp = 0;
00220 
00221   if (!len) len=fFill;
00222 
00223   if (conj) 
00224     for(register Int_t j=0;j<len;++j) tmp += operator()(-j-1) % fir_vec[j];
00225   else 
00226     for(register Int_t j=0;j<len;++j) tmp += operator()(-j-1) * fir_vec[j];
00227   return tmp;
00228 }
00229 
00230 inline void TDSPFifo::Set(const TComplex& c) {
00231   for(register Int_t i=0;i<=fDepth;++i) fBlock[i] = c;
00232   fFill = fDepth;
00233 }
00234 
00235 inline void TDSPFifo::Set(Double_t d) {
00236   for(register Int_t i=0;i<=fDepth;++i) { fBlock[i].fRe = d; fBlock[i].fIm = 0; };
00237   fFill = fDepth;
00238 }
00239 #endif

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