[1442] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 |
|
---|
[1738] | 3 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 4 | // Eric Aubourg
|
---|
| 5 | // Christophe Magneville
|
---|
| 6 | // Reza Ansari
|
---|
[2008] | 7 | // $Id: simtoipr.h,v 1.13 2002-05-16 13:13:00 ansari Exp $
|
---|
[1738] | 8 |
|
---|
| 9 |
|
---|
[1442] | 10 | #ifndef SIMTOIPR_H
|
---|
| 11 | #define SIMTOIPR_H
|
---|
| 12 |
|
---|
| 13 | #include "toiprocessor.h"
|
---|
[1454] | 14 | #include "tvector.h"
|
---|
[1442] | 15 |
|
---|
| 16 | // --------- Un deglitcheur simple
|
---|
| 17 | // Dans chaque fenetre de largeur de wsz
|
---|
| 18 | // if (val > Mean(Window)+ns*Sigma(Window)) val = Mean(Window)
|
---|
| 19 | // Si Pas plus de maxnpt points remplissants cette condition
|
---|
[2000] | 20 | //
|
---|
| 21 | // Structure generale :
|
---|
| 22 | //
|
---|
| 23 | // --------------------
|
---|
| 24 | // toi in ---> | | ---> out (toi = in_deglitche)
|
---|
| 25 | // | SimpleDeglitcher | ---> mean (toi - optionnel)
|
---|
| 26 | // | | ---> sigma (toi - optionnel)
|
---|
| 27 | // | | ---> incopie ( toi = in , optionnel)
|
---|
| 28 | // | |
|
---|
| 29 | // --------------------
|
---|
| 30 | // Si pas de toi out connecte, seul mean et sigma sont calcule
|
---|
| 31 | // les flags sont mis a jour pour le toi out en sortie
|
---|
[1442] | 32 |
|
---|
| 33 | class SimpleDeglitcher : public TOIProcessor {
|
---|
| 34 | public:
|
---|
[1479] | 35 | SimpleDeglitcher(int wsz=64, double ns=3,
|
---|
| 36 | int maxnpt=5, int minnpt=2);
|
---|
[1442] | 37 | virtual ~SimpleDeglitcher();
|
---|
| 38 |
|
---|
[1454] | 39 | inline void SetRange(double min, double max)
|
---|
| 40 | { range_min = min; range_max = max; }
|
---|
| 41 | inline void GetRange(double& min, double& max) const
|
---|
| 42 | { min = range_min; max = range_max; }
|
---|
| 43 |
|
---|
[1478] | 44 | inline void SetWSize(int wsz)
|
---|
| 45 | { wsize = (wsz < 5) ? 5 : wsz; }
|
---|
| 46 |
|
---|
| 47 |
|
---|
[1479] | 48 | void SetDetectionParam(double ns, double ns2, int maxnpt,
|
---|
| 49 | int minnpt, int wszrec=0);
|
---|
[1478] | 50 |
|
---|
| 51 | inline void RepBadSamples(bool gl_samples, bool out_range_samples, bool use_wrec=true)
|
---|
| 52 | { rec_gl_samples = gl_samples; rec_out_range_samples = out_range_samples;
|
---|
| 53 | rec_use_wrec = use_wrec; }
|
---|
| 54 |
|
---|
[1442] | 55 | virtual void init();
|
---|
| 56 | virtual void run();
|
---|
| 57 |
|
---|
| 58 | inline int WSize() const { return wsize; }
|
---|
[1478] | 59 | inline int WRecSize() const { return wrecsize; }
|
---|
[1442] | 60 | inline double NbSigmas() const { return nsig; }
|
---|
[1478] | 61 | inline double NbSigmas2() const { return nsig2; }
|
---|
[1442] | 62 | inline int MaxPoints() const { return maxpoints; }
|
---|
[1479] | 63 | inline int MinPoints() const { return minpoints; }
|
---|
[1442] | 64 |
|
---|
[1454] | 65 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 66 | inline int_8 GlitchCount() const { return glcount; }
|
---|
| 67 | inline int_8 GlitchSampleCount() const { return glnscount; }
|
---|
[2008] | 68 | inline int_8 SrcFgCount() const { return srcfgcount; }
|
---|
| 69 | inline int_8 SrcFgSampleCount() const { return srcfgnscount; }
|
---|
[1454] | 70 | inline int_8 OutOfRangeSampleCount() const { return out_range_nscount; }
|
---|
[1442] | 71 |
|
---|
[1762] | 72 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1443] | 73 |
|
---|
[1442] | 74 | protected:
|
---|
[1454] | 75 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
| 76 | int_8 glnscount; // Nombre total de glitch
|
---|
| 77 | int_8 glcount; // Nombre de glitch detecte
|
---|
[2008] | 78 | int_8 srcfgnscount; // Nombre total d'echantillons flagges source
|
---|
| 79 | int_8 srcfgcount; // Nombre de sections flaggees source
|
---|
[1454] | 80 | int_8 out_range_nscount; // Nombre de sample Out Of Range
|
---|
[1443] | 81 | bool deglitchdone; // Deglitch effectue
|
---|
[1442] | 82 |
|
---|
| 83 | int wsize; // Taille de fenetre de travail
|
---|
[1478] | 84 | int wrecsize; // Taille de fenetre de calcul pour reconstruite les mauvaises valeur
|
---|
| 85 | // pour valeur de glitch
|
---|
[1442] | 86 | double nsig; // Seuil en nb de sigmas
|
---|
[1478] | 87 | double nsig2; // Seuil en nb de sigmas, pour les points suivants le 1er
|
---|
[1442] | 88 | int maxpoints; // Nb maxi de points > ns sigmas
|
---|
[1479] | 89 | int minpoints; // Nb mini de points > ns sigmas pour avoir un glitch
|
---|
[1454] | 90 | double range_min, range_max; // Range acceptable pour in
|
---|
[1478] | 91 |
|
---|
| 92 | bool rec_gl_samples; // if true, replace glitch sample values
|
---|
| 93 | bool rec_out_range_samples; // if true, replace out of range sample values
|
---|
| 94 | bool rec_use_wrec; // if true, use Mean[Window(wrecsize)] to replace bad samples
|
---|
| 95 | // else use sliding mean value for
|
---|
| 96 |
|
---|
[1442] | 97 | };
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | // Un filtre simple, dans le domaine temporel
|
---|
| 101 | // remplace val -> Somme(val(i)*coeff(i)) ds Fenetre
|
---|
[2000] | 102 | //
|
---|
| 103 | // Structure generale :
|
---|
| 104 | //
|
---|
| 105 | // ------------------
|
---|
| 106 | // toi in ---> | | ---> out (toi = in_filtre)
|
---|
| 107 | // | SimpleFilter |
|
---|
| 108 | // | | ---> incopie ( toi = in , optionnel)
|
---|
| 109 | // | |
|
---|
| 110 | // ------------------
|
---|
[1442] | 111 |
|
---|
| 112 | class SimpleFilter : public TOIProcessor {
|
---|
| 113 | public:
|
---|
| 114 | enum FilterKind {
|
---|
| 115 | UserFilter=0, // User defined filter function
|
---|
| 116 | MeanFilter=1, // Replace sample by the window mean value (lowpass)
|
---|
| 117 | SumFilter=2, // Replace sample by the window sum (lowpass)
|
---|
| 118 | GaussFilter=3, // Apply a gaussian to the window samples
|
---|
| 119 | DiffFilter=4, // value -= MeanValue
|
---|
| 120 | };
|
---|
| 121 |
|
---|
[1454] | 122 | static string FilterKind2String(FilterKind fk);
|
---|
[1442] | 123 | SimpleFilter(int wsz=128,
|
---|
[1454] | 124 | FilterKind fk=SimpleFilter::MeanFilter,
|
---|
| 125 | double a=1., double s=1.);
|
---|
| 126 | SimpleFilter(Vector const & vc);
|
---|
[1442] | 127 | ~SimpleFilter();
|
---|
| 128 |
|
---|
| 129 | inline FilterKind Type() { return fkind; }
|
---|
| 130 |
|
---|
| 131 | inline int WSize() const { return wsize; }
|
---|
[1454] | 132 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 133 | Vector FilterCoefficients() const;
|
---|
[1442] | 134 |
|
---|
[1762] | 135 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1443] | 136 |
|
---|
[1442] | 137 | virtual void init();
|
---|
| 138 | virtual void run();
|
---|
| 139 |
|
---|
| 140 | protected:
|
---|
| 141 | FilterKind fkind;
|
---|
[1454] | 142 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
[1442] | 143 | int wsize; // Taille de fenetre de travail
|
---|
| 144 | double* coef; // Coefficients du filtre
|
---|
| 145 |
|
---|
| 146 | };
|
---|
| 147 |
|
---|
[1454] | 148 | // Classe SimpleAdder
|
---|
| 149 | // Calcule la sortie = Somme_Entree [ coeff[num] * entree[num] ]
|
---|
| 150 |
|
---|
| 151 | class SimpleAdder : public TOIProcessor {
|
---|
| 152 | public:
|
---|
| 153 | SimpleAdder(int nbinput);
|
---|
| 154 | ~SimpleAdder();
|
---|
| 155 |
|
---|
| 156 | void SetGain(int num, double g);
|
---|
| 157 | double Gain(int num);
|
---|
| 158 |
|
---|
| 159 | inline int NbInput() const { return nb_input; }
|
---|
| 160 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 161 |
|
---|
[1762] | 162 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1454] | 163 |
|
---|
| 164 | virtual void init();
|
---|
| 165 | virtual void run();
|
---|
| 166 |
|
---|
| 167 | protected:
|
---|
| 168 | int nb_input;
|
---|
| 169 | Vector gains;
|
---|
| 170 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 |
|
---|
[1479] | 174 | // Un filtre simple, dans le domaine de Fourier
|
---|
| 175 | // InverseFFT ( FFT(Vecteur(in)) * FilterCoefficient )
|
---|
| 176 |
|
---|
| 177 | class SimpleFourierFilter : public TOIProcessor {
|
---|
| 178 | public:
|
---|
| 179 | SimpleFourierFilter(Vector const & vc);
|
---|
| 180 | ~SimpleFourierFilter();
|
---|
| 181 |
|
---|
| 182 | inline int WSize() const { return wsize; }
|
---|
| 183 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 184 | inline Vector FilterCoefficients() const
|
---|
| 185 | { Vector rcv; rcv = ffcoef; return(rcv); }
|
---|
| 186 |
|
---|
[1762] | 187 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1479] | 188 |
|
---|
| 189 | virtual void init();
|
---|
| 190 | virtual void run();
|
---|
| 191 |
|
---|
[1483] | 192 | inline void KeepSpectra(string outname, int nb)
|
---|
| 193 | { outppfname = outname; nb_keep = nb; }
|
---|
[1484] | 194 | inline void ComputeMeanSpectra(bool fg)
|
---|
| 195 | { c_meanspectra = fg; }
|
---|
[1479] | 196 | protected:
|
---|
| 197 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
[1484] | 198 | int_8 totnbblock; // Nombre total de blocs pour FFT
|
---|
[1479] | 199 | int wsize; // Taille de fenetre de travail
|
---|
| 200 | Vector ffcoef; // Coefficients du filtre
|
---|
[1484] | 201 | bool c_meanspectra;
|
---|
[1479] | 202 | int nb_keep;
|
---|
[1483] | 203 | string outppfname;
|
---|
[1479] | 204 | };
|
---|
| 205 |
|
---|
| 206 |
|
---|
[1467] | 207 | // Classe SimpleFanOut
|
---|
[1479] | 208 | // Recopie chaque entree sur M lignes de sortie
|
---|
[1467] | 209 |
|
---|
| 210 | class SimpleFanOut : public TOIProcessor {
|
---|
| 211 | public:
|
---|
| 212 | SimpleFanOut(int nbinput, int mfanout);
|
---|
| 213 | ~SimpleFanOut();
|
---|
| 214 |
|
---|
| 215 | inline int NbInput() const { return nb_input; }
|
---|
| 216 | inline int MFanOut() const { return m_fanout; }
|
---|
| 217 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 218 |
|
---|
[1762] | 219 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1467] | 220 |
|
---|
| 221 | virtual void init();
|
---|
| 222 | virtual void run();
|
---|
| 223 |
|
---|
| 224 | protected:
|
---|
| 225 | int nb_input;
|
---|
| 226 | int m_fanout;
|
---|
| 227 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
| 228 | };
|
---|
| 229 |
|
---|
[1479] | 230 |
|
---|
[1442] | 231 | #endif
|
---|