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