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