| 1 | // This may look like C code, but it is really -*- C++ -*-
|
|---|
| 2 |
|
|---|
| 3 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
|---|
| 4 | // Eric Aubourg
|
|---|
| 5 | // Christophe Magneville
|
|---|
| 6 | // Reza Ansari
|
|---|
| 7 | // $Id: simtoipr.h,v 1.11 2001-11-13 16:22:47 aubourg Exp $
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | #ifndef SIMTOIPR_H
|
|---|
| 11 | #define SIMTOIPR_H
|
|---|
| 12 |
|
|---|
| 13 | #include "toiprocessor.h"
|
|---|
| 14 | #include "tvector.h"
|
|---|
| 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:
|
|---|
| 23 | SimpleDeglitcher(int wsz=64, double ns=3,
|
|---|
| 24 | int maxnpt=5, int minnpt=2);
|
|---|
| 25 | virtual ~SimpleDeglitcher();
|
|---|
| 26 |
|
|---|
| 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 |
|
|---|
| 32 | inline void SetWSize(int wsz)
|
|---|
| 33 | { wsize = (wsz < 5) ? 5 : wsz; }
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | void SetDetectionParam(double ns, double ns2, int maxnpt,
|
|---|
| 37 | int minnpt, int wszrec=0);
|
|---|
| 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 |
|
|---|
| 43 | virtual void init();
|
|---|
| 44 | virtual void run();
|
|---|
| 45 |
|
|---|
| 46 | inline int WSize() const { return wsize; }
|
|---|
| 47 | inline int WRecSize() const { return wrecsize; }
|
|---|
| 48 | inline double NbSigmas() const { return nsig; }
|
|---|
| 49 | inline double NbSigmas2() const { return nsig2; }
|
|---|
| 50 | inline int MaxPoints() const { return maxpoints; }
|
|---|
| 51 | inline int MinPoints() const { return minpoints; }
|
|---|
| 52 |
|
|---|
| 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; }
|
|---|
| 57 |
|
|---|
| 58 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
|---|
| 59 |
|
|---|
| 60 | protected:
|
|---|
| 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
|
|---|
| 65 | bool deglitchdone; // Deglitch effectue
|
|---|
| 66 |
|
|---|
| 67 | int wsize; // Taille de fenetre de travail
|
|---|
| 68 | int wrecsize; // Taille de fenetre de calcul pour reconstruite les mauvaises valeur
|
|---|
| 69 | // pour valeur de glitch
|
|---|
| 70 | double nsig; // Seuil en nb de sigmas
|
|---|
| 71 | double nsig2; // Seuil en nb de sigmas, pour les points suivants le 1er
|
|---|
| 72 | int maxpoints; // Nb maxi de points > ns sigmas
|
|---|
| 73 | int minpoints; // Nb mini de points > ns sigmas pour avoir un glitch
|
|---|
| 74 | double range_min, range_max; // Range acceptable pour in
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 97 | static string FilterKind2String(FilterKind fk);
|
|---|
| 98 | SimpleFilter(int wsz=128,
|
|---|
| 99 | FilterKind fk=SimpleFilter::MeanFilter,
|
|---|
| 100 | double a=1., double s=1.);
|
|---|
| 101 | SimpleFilter(Vector const & vc);
|
|---|
| 102 | ~SimpleFilter();
|
|---|
| 103 |
|
|---|
| 104 | inline FilterKind Type() { return fkind; }
|
|---|
| 105 |
|
|---|
| 106 | inline int WSize() const { return wsize; }
|
|---|
| 107 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
|---|
| 108 | Vector FilterCoefficients() const;
|
|---|
| 109 |
|
|---|
| 110 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
|---|
| 111 |
|
|---|
| 112 | virtual void init();
|
|---|
| 113 | virtual void run();
|
|---|
| 114 |
|
|---|
| 115 | protected:
|
|---|
| 116 | FilterKind fkind;
|
|---|
| 117 | int_8 totnscount; // Nombre total d'echantillon processe
|
|---|
| 118 | int wsize; // Taille de fenetre de travail
|
|---|
| 119 | double* coef; // Coefficients du filtre
|
|---|
| 120 |
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 167 | inline void KeepSpectra(string outname, int nb)
|
|---|
| 168 | { outppfname = outname; nb_keep = nb; }
|
|---|
| 169 | inline void ComputeMeanSpectra(bool fg)
|
|---|
| 170 | { c_meanspectra = fg; }
|
|---|
| 171 | protected:
|
|---|
| 172 | int_8 totnscount; // Nombre total d'echantillon processe
|
|---|
| 173 | int_8 totnbblock; // Nombre total de blocs pour FFT
|
|---|
| 174 | int wsize; // Taille de fenetre de travail
|
|---|
| 175 | Vector ffcoef; // Coefficients du filtre
|
|---|
| 176 | bool c_meanspectra;
|
|---|
| 177 | int nb_keep;
|
|---|
| 178 | string outppfname;
|
|---|
| 179 | };
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 | // Classe SimpleFanOut
|
|---|
| 183 | // Recopie chaque entree sur M lignes de sortie
|
|---|
| 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 |
|
|---|
| 205 |
|
|---|
| 206 | #endif
|
|---|