00001
00009
00010
00011
00012
00013
00014
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;
00063 Int_t fIndex;
00064 Int_t fFill;
00065
00066 TComplex *fBlock;
00067
00068 void Fill();
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;};
00078 Int_t GetIndex(Int_t);
00079
00080 Int_t GetDepth() const { return fDepth;};
00081 Int_t GetFill() const { return fFill; };
00082 TComplex* GetBlock() const { return fBlock; };
00083
00084 Bool_t WasFull() { return fFill>=fDepth;};
00085 Bool_t IsFull() { return fFill==fDepth-1;};
00086 void Reset();
00087
00088 TComplex& operator()();
00089 TComplex& operator()(Int_t i);
00090 TComplex& operator[](Int_t i);
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
00101
00102 Int_t GetIndex() const { return fIndex; };
00103 void Next() { if (fIndex++==fDepth) fIndex=0;}
00104 Int_t Next(Int_t current) {return current++==fDepth ? 0 : current;}
00105
00106 void Back() { fIndex= fIndex ? fIndex-1 : fDepth;}
00107 Int_t Back(Int_t current) {return current ? current-1 : fDepth;}
00108
00109 TComplex& Shift(Double_t x) { return Shift(TComplex(x,0)); };
00110 TComplex& Shift(TComplex c);
00111 TDSPVector* Shift(TDSPVector *input, TDSPVector *output);
00112 void FillFrom(TDSPVector *input);
00113 TDSPVector* FillTo(TDSPVector* output=NULL);
00114 void SetDepth(Int_t depth);
00115 void Set(const TComplex&);
00116 void Set(Double_t);
00117 void Zeros() { Set(0.0); };
00118 void Ones() { Set(1.0);};
00119
00120 TComplex Dot(TComplex *fir_vec, Bool_t conj=kTRUE,Int_t l=0);
00121 TComplex Dot(TDSPVector *fir, Bool_t conj=kTRUE);
00122 TComplex Dot(TDSPFifo *fir, Bool_t conj=kTRUE);
00123
00124 TDSPVector *filter(TDSPVector *out,
00125 TDSPVector *fir,
00126 TDSPVector *iir = NULL);
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);
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
00142
00143
00144 TDSPVector *filter(TDSPFifo *in,
00145 TDSPVector *out,
00146 TDSPVector *fir,
00147 TDSPVector *iir = NULL);
00148
00149
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) {
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;
00180 i += Next(fIndex);
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
00197
00198 (*this)() = c;
00199
00200
00201
00202 Next();
00203
00204
00205
00206 Fill();
00207
00208
00209
00210 if (!WasFull())
00211 return ComplexZero;
00212
00213
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