| 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"
|
|---|
| 7 | #include "tvector.h"
|
|---|
| 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:
|
|---|
| 16 | SimpleDeglitcher(int wsz=64, double ns=3,
|
|---|
| 17 | int maxnpt=5, int minnpt=2);
|
|---|
| 18 | virtual ~SimpleDeglitcher();
|
|---|
| 19 |
|
|---|
| 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 |
|
|---|
| 25 | inline void SetWSize(int wsz)
|
|---|
| 26 | { wsize = (wsz < 5) ? 5 : wsz; }
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | void SetDetectionParam(double ns, double ns2, int maxnpt,
|
|---|
| 30 | int minnpt, int wszrec=0);
|
|---|
| 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 |
|
|---|
| 36 | virtual void init();
|
|---|
| 37 | virtual void run();
|
|---|
| 38 |
|
|---|
| 39 | inline int WSize() const { return wsize; }
|
|---|
| 40 | inline int WRecSize() const { return wrecsize; }
|
|---|
| 41 | inline double NbSigmas() const { return nsig; }
|
|---|
| 42 | inline double NbSigmas2() const { return nsig2; }
|
|---|
| 43 | inline int MaxPoints() const { return maxpoints; }
|
|---|
| 44 | inline int MinPoints() const { return minpoints; }
|
|---|
| 45 |
|
|---|
| 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; }
|
|---|
| 50 |
|
|---|
| 51 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
|---|
| 52 |
|
|---|
| 53 | protected:
|
|---|
| 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
|
|---|
| 58 | bool deglitchdone; // Deglitch effectue
|
|---|
| 59 |
|
|---|
| 60 | int wsize; // Taille de fenetre de travail
|
|---|
| 61 | int wrecsize; // Taille de fenetre de calcul pour reconstruite les mauvaises valeur
|
|---|
| 62 | // pour valeur de glitch
|
|---|
| 63 | double nsig; // Seuil en nb de sigmas
|
|---|
| 64 | double nsig2; // Seuil en nb de sigmas, pour les points suivants le 1er
|
|---|
| 65 | int maxpoints; // Nb maxi de points > ns sigmas
|
|---|
| 66 | int minpoints; // Nb mini de points > ns sigmas pour avoir un glitch
|
|---|
| 67 | double range_min, range_max; // Range acceptable pour in
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 90 | static string FilterKind2String(FilterKind fk);
|
|---|
| 91 | SimpleFilter(int wsz=128,
|
|---|
| 92 | FilterKind fk=SimpleFilter::MeanFilter,
|
|---|
| 93 | double a=1., double s=1.);
|
|---|
| 94 | SimpleFilter(Vector const & vc);
|
|---|
| 95 | ~SimpleFilter();
|
|---|
| 96 |
|
|---|
| 97 | inline FilterKind Type() { return fkind; }
|
|---|
| 98 |
|
|---|
| 99 | inline int WSize() const { return wsize; }
|
|---|
| 100 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
|---|
| 101 | Vector FilterCoefficients() const;
|
|---|
| 102 |
|
|---|
| 103 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
|---|
| 104 |
|
|---|
| 105 | virtual void init();
|
|---|
| 106 | virtual void run();
|
|---|
| 107 |
|
|---|
| 108 | protected:
|
|---|
| 109 | FilterKind fkind;
|
|---|
| 110 | int_8 totnscount; // Nombre total d'echantillon processe
|
|---|
| 111 | int wsize; // Taille de fenetre de travail
|
|---|
| 112 | double* coef; // Coefficients du filtre
|
|---|
| 113 |
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 160 | inline void KeepSpectra(string outname, int nb)
|
|---|
| 161 | { outppfname = outname; nb_keep = nb; }
|
|---|
| 162 | inline void ComputeMeanSpectra(bool fg)
|
|---|
| 163 | { c_meanspectra = fg; }
|
|---|
| 164 | protected:
|
|---|
| 165 | int_8 totnscount; // Nombre total d'echantillon processe
|
|---|
| 166 | int_8 totnbblock; // Nombre total de blocs pour FFT
|
|---|
| 167 | int wsize; // Taille de fenetre de travail
|
|---|
| 168 | Vector ffcoef; // Coefficients du filtre
|
|---|
| 169 | bool c_meanspectra;
|
|---|
| 170 | int nb_keep;
|
|---|
| 171 | string outppfname;
|
|---|
| 172 | };
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | // Classe SimpleFanOut
|
|---|
| 176 | // Recopie chaque entree sur M lignes de sortie
|
|---|
| 177 |
|
|---|
| 178 | class SimpleFanOut : public TOIProcessor {
|
|---|
| 179 | public:
|
|---|
| 180 | SimpleFanOut(int nbinput, int mfanout);
|
|---|
| 181 | ~SimpleFanOut();
|
|---|
| 182 |
|
|---|
| 183 | inline int NbInput() const { return nb_input; }
|
|---|
| 184 | inline int MFanOut() const { return m_fanout; }
|
|---|
| 185 | inline int_8 ProcessedSampleCount() const { return totnscount; }
|
|---|
| 186 |
|
|---|
| 187 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
|---|
| 188 |
|
|---|
| 189 | virtual void init();
|
|---|
| 190 | virtual void run();
|
|---|
| 191 |
|
|---|
| 192 | protected:
|
|---|
| 193 | int nb_input;
|
|---|
| 194 | int m_fanout;
|
|---|
| 195 | int_8 totnscount; // Nombre total d'echantillon processe
|
|---|
| 196 | };
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 | #endif
|
|---|