[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
|
---|
| 7 | // $Id: simtoipr.h,v 1.9 2001-11-08 15:47:45 aubourg Exp $
|
---|
| 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
|
---|
| 20 |
|
---|
| 21 | class SimpleDeglitcher : public TOIProcessor {
|
---|
| 22 | public:
|
---|
[1479] | 23 | SimpleDeglitcher(int wsz=64, double ns=3,
|
---|
| 24 | int maxnpt=5, int minnpt=2);
|
---|
[1442] | 25 | virtual ~SimpleDeglitcher();
|
---|
| 26 |
|
---|
[1454] | 27 | inline void SetRange(double min, double max)
|
---|
| 28 | { range_min = min; range_max = max; }
|
---|
| 29 | inline void GetRange(double& min, double& max) const
|
---|
| 30 | { min = range_min; max = range_max; }
|
---|
| 31 |
|
---|
[1478] | 32 | inline void SetWSize(int wsz)
|
---|
| 33 | { wsize = (wsz < 5) ? 5 : wsz; }
|
---|
| 34 |
|
---|
| 35 |
|
---|
[1479] | 36 | void SetDetectionParam(double ns, double ns2, int maxnpt,
|
---|
| 37 | int minnpt, int wszrec=0);
|
---|
[1478] | 38 |
|
---|
| 39 | inline void RepBadSamples(bool gl_samples, bool out_range_samples, bool use_wrec=true)
|
---|
| 40 | { rec_gl_samples = gl_samples; rec_out_range_samples = out_range_samples;
|
---|
| 41 | rec_use_wrec = use_wrec; }
|
---|
| 42 |
|
---|
[1442] | 43 | virtual void init();
|
---|
| 44 | virtual void run();
|
---|
| 45 |
|
---|
| 46 | inline int WSize() const { return wsize; }
|
---|
[1478] | 47 | inline int WRecSize() const { return wrecsize; }
|
---|
[1442] | 48 | inline double NbSigmas() const { return nsig; }
|
---|
[1478] | 49 | inline double NbSigmas2() const { return nsig2; }
|
---|
[1442] | 50 | inline int MaxPoints() const { return maxpoints; }
|
---|
[1479] | 51 | inline int MinPoints() const { return minpoints; }
|
---|
[1442] | 52 |
|
---|
[1454] | 53 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 54 | inline int_8 GlitchCount() const { return glcount; }
|
---|
| 55 | inline int_8 GlitchSampleCount() const { return glnscount; }
|
---|
| 56 | inline int_8 OutOfRangeSampleCount() const { return out_range_nscount; }
|
---|
[1442] | 57 |
|
---|
[1443] | 58 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
| 59 |
|
---|
[1442] | 60 | protected:
|
---|
[1454] | 61 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
| 62 | int_8 glnscount; // Nombre total de glitch
|
---|
| 63 | int_8 glcount; // Nombre de glitch detecte
|
---|
| 64 | int_8 out_range_nscount; // Nombre de sample Out Of Range
|
---|
[1443] | 65 | bool deglitchdone; // Deglitch effectue
|
---|
[1442] | 66 |
|
---|
| 67 | int wsize; // Taille de fenetre de travail
|
---|
[1478] | 68 | int wrecsize; // Taille de fenetre de calcul pour reconstruite les mauvaises valeur
|
---|
| 69 | // pour valeur de glitch
|
---|
[1442] | 70 | double nsig; // Seuil en nb de sigmas
|
---|
[1478] | 71 | double nsig2; // Seuil en nb de sigmas, pour les points suivants le 1er
|
---|
[1442] | 72 | int maxpoints; // Nb maxi de points > ns sigmas
|
---|
[1479] | 73 | int minpoints; // Nb mini de points > ns sigmas pour avoir un glitch
|
---|
[1454] | 74 | double range_min, range_max; // Range acceptable pour in
|
---|
[1478] | 75 |
|
---|
| 76 | bool rec_gl_samples; // if true, replace glitch sample values
|
---|
| 77 | bool rec_out_range_samples; // if true, replace out of range sample values
|
---|
| 78 | bool rec_use_wrec; // if true, use Mean[Window(wrecsize)] to replace bad samples
|
---|
| 79 | // else use sliding mean value for
|
---|
| 80 |
|
---|
[1442] | 81 | };
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | // Un filtre simple, dans le domaine temporel
|
---|
| 85 | // remplace val -> Somme(val(i)*coeff(i)) ds Fenetre
|
---|
| 86 |
|
---|
| 87 | class SimpleFilter : public TOIProcessor {
|
---|
| 88 | public:
|
---|
| 89 | enum FilterKind {
|
---|
| 90 | UserFilter=0, // User defined filter function
|
---|
| 91 | MeanFilter=1, // Replace sample by the window mean value (lowpass)
|
---|
| 92 | SumFilter=2, // Replace sample by the window sum (lowpass)
|
---|
| 93 | GaussFilter=3, // Apply a gaussian to the window samples
|
---|
| 94 | DiffFilter=4, // value -= MeanValue
|
---|
| 95 | };
|
---|
| 96 |
|
---|
[1454] | 97 | static string FilterKind2String(FilterKind fk);
|
---|
[1442] | 98 | SimpleFilter(int wsz=128,
|
---|
[1454] | 99 | FilterKind fk=SimpleFilter::MeanFilter,
|
---|
| 100 | double a=1., double s=1.);
|
---|
| 101 | SimpleFilter(Vector const & vc);
|
---|
[1442] | 102 | ~SimpleFilter();
|
---|
| 103 |
|
---|
| 104 | inline FilterKind Type() { return fkind; }
|
---|
| 105 |
|
---|
| 106 | inline int WSize() const { return wsize; }
|
---|
[1454] | 107 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 108 | Vector FilterCoefficients() const;
|
---|
[1442] | 109 |
|
---|
[1443] | 110 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
| 111 |
|
---|
[1442] | 112 | virtual void init();
|
---|
| 113 | virtual void run();
|
---|
| 114 |
|
---|
| 115 | protected:
|
---|
| 116 | FilterKind fkind;
|
---|
[1454] | 117 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
[1442] | 118 | int wsize; // Taille de fenetre de travail
|
---|
| 119 | double* coef; // Coefficients du filtre
|
---|
| 120 |
|
---|
| 121 | };
|
---|
| 122 |
|
---|
[1454] | 123 | // Classe SimpleAdder
|
---|
| 124 | // Calcule la sortie = Somme_Entree [ coeff[num] * entree[num] ]
|
---|
| 125 |
|
---|
| 126 | class SimpleAdder : public TOIProcessor {
|
---|
| 127 | public:
|
---|
| 128 | SimpleAdder(int nbinput);
|
---|
| 129 | ~SimpleAdder();
|
---|
| 130 |
|
---|
| 131 | void SetGain(int num, double g);
|
---|
| 132 | double Gain(int num);
|
---|
| 133 |
|
---|
| 134 | inline int NbInput() const { return nb_input; }
|
---|
| 135 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 136 |
|
---|
| 137 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
| 138 |
|
---|
| 139 | virtual void init();
|
---|
| 140 | virtual void run();
|
---|
| 141 |
|
---|
| 142 | protected:
|
---|
| 143 | int nb_input;
|
---|
| 144 | Vector gains;
|
---|
| 145 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
| 146 | };
|
---|
| 147 |
|
---|
| 148 |
|
---|
[1479] | 149 | // Un filtre simple, dans le domaine de Fourier
|
---|
| 150 | // InverseFFT ( FFT(Vecteur(in)) * FilterCoefficient )
|
---|
| 151 |
|
---|
| 152 | class SimpleFourierFilter : public TOIProcessor {
|
---|
| 153 | public:
|
---|
| 154 | SimpleFourierFilter(Vector const & vc);
|
---|
| 155 | ~SimpleFourierFilter();
|
---|
| 156 |
|
---|
| 157 | inline int WSize() const { return wsize; }
|
---|
| 158 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 159 | inline Vector FilterCoefficients() const
|
---|
| 160 | { Vector rcv; rcv = ffcoef; return(rcv); }
|
---|
| 161 |
|
---|
| 162 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
| 163 |
|
---|
| 164 | virtual void init();
|
---|
| 165 | virtual void run();
|
---|
| 166 |
|
---|
[1483] | 167 | inline void KeepSpectra(string outname, int nb)
|
---|
| 168 | { outppfname = outname; nb_keep = nb; }
|
---|
[1484] | 169 | inline void ComputeMeanSpectra(bool fg)
|
---|
| 170 | { c_meanspectra = fg; }
|
---|
[1479] | 171 | protected:
|
---|
| 172 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
[1484] | 173 | int_8 totnbblock; // Nombre total de blocs pour FFT
|
---|
[1479] | 174 | int wsize; // Taille de fenetre de travail
|
---|
| 175 | Vector ffcoef; // Coefficients du filtre
|
---|
[1484] | 176 | bool c_meanspectra;
|
---|
[1479] | 177 | int nb_keep;
|
---|
[1483] | 178 | string outppfname;
|
---|
[1479] | 179 | };
|
---|
| 180 |
|
---|
| 181 |
|
---|
[1467] | 182 | // Classe SimpleFanOut
|
---|
[1479] | 183 | // Recopie chaque entree sur M lignes de sortie
|
---|
[1467] | 184 |
|
---|
| 185 | class SimpleFanOut : public TOIProcessor {
|
---|
| 186 | public:
|
---|
| 187 | SimpleFanOut(int nbinput, int mfanout);
|
---|
| 188 | ~SimpleFanOut();
|
---|
| 189 |
|
---|
| 190 | inline int NbInput() const { return nb_input; }
|
---|
| 191 | inline int MFanOut() const { return m_fanout; }
|
---|
| 192 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
---|
| 193 |
|
---|
| 194 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
| 195 |
|
---|
| 196 | virtual void init();
|
---|
| 197 | virtual void run();
|
---|
| 198 |
|
---|
| 199 | protected:
|
---|
| 200 | int nb_input;
|
---|
| 201 | int m_fanout;
|
---|
| 202 | int_8 totnscount; // Nombre total d'echantillon processe
|
---|
| 203 | };
|
---|
| 204 |
|
---|
[1479] | 205 |
|
---|
[1442] | 206 | #endif
|
---|