Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wavelinefilter.hh
Go to the documentation of this file.
1 #ifndef linefilter_HH
2 #define linefilter_HH
3 
4 #include <iosfwd>
5 #include <list>
6 #include <vector>
7 #include "wseries.hh"
8 
9 #include <complex>
10 
11 typedef std::complex<float> f_complex;
12 typedef double wavereal;
14 
15 struct linedata {
16  double T_current;
17  float frequency;
18  float intensity;
19  unsigned int first;
20  std::vector<f_complex> amplitude;
21  std::vector<float> line;
22  std::vector<float> noise;
23  std::vector<float> filter;
24 };
25 
26 /** The linefilter class containes methods to track and remove quasi-
27  * monochromatic lines. a TSeries by 2^N. The TSeries
28  * data are filtered before decimation to remove aliasing.
29  * @memo Line Removal.
30  * @version 1.2 ; Modified November 01, 2000
31  * @version 1.3 ; Modified November 17, 2000
32  * @author Sergey Klimenko
33  */
34 class linefilter {
35 public:
36  /** Build an empty linefilter.
37  * @memo Default constructor.
38  */
39  linefilter(void);
40 
41  /** @memo linefilter constructor
42  * filter type (default fid = 1) and time interval T to estimate and
43  * remove interference (T=0 - the whole input TS is used).
44  * @memo Constructor.
45  *@memo Set parameters of the line filter
46  *@param f - line base frequency
47  *@param T - time interval to estimate interference
48  * (T=0 - the whole TS is used)
49  *@param fid - filter ID:
50  * 1 - use resampling and FFT with noise floor estimation
51  * 0 - use resampling and FFT, no noise floor estimation
52  * -1 - heterodyne estimation of amplitude and phase, frequency=const
53  * -2 - -1 + Hann window
54  * -3 - the same as -2, but sin(), cos() and Hann() are tabulated
55  *@param nT - number of interval T sub0divisions
56  */
57  linefilter(double f, double T = 0., int fid = 1, int nT = 1);
58 
59  /** Build a linefilter identical to an existing filter.
60  * @memo Copy constructor.
61  */
62  linefilter(const linefilter& x);
63 
64  /** Destroy the linefilter object and release the function storage.
65  * @memo Virtual destructor.
66  */
67  ~linefilter(void);
68 
69 
70  /** Clone a linefilter
71  */
72  linefilter* clone(void) const;
73 
74  /** Operate on wavearray object
75  */
76  void apply(WaveData& ts);
77 
78  /***setFilter*********************************************************
79  *@memo Set parameters of the line filter
80  *@param nF - first harmonic
81  *@param nL - last harmonic
82  *@param nS - skip nS-1 harmonics (take nF, nF+nS, nF+2nS,....)
83  *@param nD - wavelet decimation factor
84  *@param nB - nB/T is a frequency band to estimate noise
85  *@param nR - order of Resample Interpolating Filter
86  *@param nW - order of the decimating lifting wavelet
87  *********************************************************************/
88  void setFilter(int nF = 1,
89  int nL = 0,
90  int nS = 1,
91  int nD = -1,
92  int nB = 5,
93  int nR = 6,
94  int nW = 8);
95 
96  /***setFScan*********************************************************
97  *@memo Set parameters for getFrequency()
98  *@param f - base frequency: if f<=0 - don't scan frequency,
99  *@ f=0 - don't change frequency specified (by linefilter)
100  *@param sn - limit on signal to noise ratio
101  *@param fS - initial range of frequency scan in units of fft bin
102  *@param nS - number of steps during frequency scan
103  *********************************************************************/
104  void setFScan(double f = 0.,
105  double sn = 2.,
106  double fS = 0.45,
107  int nS = 20);
108 
109 
110  /** Clear/release the internal History vector and reset the current
111  * time.
112  */
113  void reset();
114  void resize(size_t=0);
115 
116  inline double getStartTime(void) const;
117  inline double getCurrentTime(void) const;
118  inline bool inUse(void) const;
119 
120 //private:
121 
122  int FilterID;
123  double Frequency; // fundamental line frequency
124  double Window;
125  double Stride;
126  unsigned int nFirst; // first line harmonic
127  unsigned int nLast; // last line harmonic
128  int nStep; // skip harmonics (take nF, nF+nS, nF+2nS,....)
129  int nScan; // # of frequency steps to scan frequency
130  unsigned int nBand; // frequency band in fft bins to average noise
131  int nSubs; // number of data subsets to estimate signal PSD
132  double fBand; // frequency step in fft bins to scan frequency
133  int nLPF; // decimation factor
134  int nWave; // order of the interpolating wavelet
135  bool clean; // true if to clean data
136  bool badData; // false if valid data
137  bool noScan; // true if Frequency is fixed
138  int nRIF; // order of Resample Interpolating Filter
139  double SNR; // limit on SNR used by makeFilter
140  bool reFine; // refine frequency if true (set by SNR<0)
141  size_t dumpStart; // first lineList index used to dump data
144 
145  double CurrentTime;
146  double StartTime;
147  double Sample;
148 
149  wavearray<double> ct; // tabulated cos()
150  wavearray<double> st; // tabulated cos()
151  wavearray<double> wt; // tabulated window
152 
153  std::list<linedata> lineList;
154 
158 
159  WaveData getPSD(const WaveData &, int = 1);
160  double makeFilter(const WaveData &, int = 0);
162 
163  /***getHeteroLine****************************************************
164  *@memo reconstruct line amplitude and phase using heterodyne method
165  *@param input time series
166  *********************************************************************/
168 
169  double getOmega(const WaveData &, int = 2);
170  double fScan(const WaveData &);
171  double Interference(WaveData &, double);
172 
173  wavearray<float> getTrend(int, char);
174  bool DumpTrend(const char*, int = 0);
175  bool LoadTrend(const char*);
176 
177  inline double newRate(double);
178  unsigned int maxLine(int);
179  inline double axb(double, double);
180  inline double wrap(double);
181  inline long intw(double);
182 
183 };
184 
185 inline double linefilter::newRate(double rate)
186 {
187  double f = rate/Frequency;
188  f *= (nLPF >= 0) ? 1 : 2;
189  return (int(f)+1)*Frequency;
190 }
191 
192 inline double linefilter::axb(double a, double b)
193 {return (a-long(a))*long(b) + (b-long(b))*long(a) + (a-long(a))*(b-long(b));}
194 
195 inline long linefilter::intw(double a)
196 {return (a>0) ? long(a+0.5) : long(a-0.5);}
197 
198 inline double linefilter::wrap(double a)
199 {
200  long l = a>0 ? long(a/PI/2. + 0.5) : long(a/PI/2. - 0.5);
201  return a - 2*PI*l;
202 }
203 
204 inline double linefilter::getStartTime(void) const {
205  return StartTime;
206 }
207 
208 inline double linefilter::getCurrentTime(void) const {
209  return CurrentTime;
210 }
211 
212 inline bool linefilter::inUse(void) const {
213  return (StartTime != 0.);
214 }
215 
216 #endif // linefilter_HH
wavearray< double > ct
unsigned int nBand
std::list< linedata > lineList
tuple f
Definition: cwb_online.py:91
double newRate(double)
bool inUse(void) const
The linefilter class containes methods to track and remove quasi- monochromatic lines.
wavearray< double > a(hp.size())
double StartTime
WaveData Filter
unsigned int nLast
void setFilter(int nF=1, int nL=0, int nS=1, int nD=-1, int nB=5, int nR=6, int nW=8)
double getStartTime(void) const
void apply(WaveData &ts)
Operate on wavearray object.
double getCurrentTime(void) const
wavearray< double > wt
std::vector< float > line
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
WaveData LineSD
float frequency
WaveData NoiseSD
void reset()
Clear/release the internal History vector and reset the current time.
double SeedFrequency
double wrap(double)
nT
Definition: cbc_plots.C:659
#define PI
Definition: watfun.hh:14
linefilter * clone(void) const
Clone a linefilter.
std::vector< f_complex > amplitude
double Frequency
bool LoadTrend(const char *)
unsigned int nFirst
float intensity
unsigned int first
double CurrentTime
double wavereal
linedata getLine(WaveData &)
wavearray< float > getTrend(int, char)
std::vector< float > filter
long intw(double)
WaveData getPSD(const WaveData &, int=1)
void resize(size_t=0)
void setFScan(double f=0., double sn=2., double fS=0.45, int nS=20)
double getOmega(const WaveData &, int=2)
wavearray< double > st
double axb(double, double)
double T
Definition: testWDM_4.C:11
linefilter(void)
Build an empty linefilter.
bool DumpTrend(const char *, int=0)
double makeFilter(const WaveData &, int=0)
wavearray< double > ts(N)
std::complex< float > f_complex
int l
Definition: cbc_plots.C:434
double fScan(const WaveData &)
linedata getHeteroLine(WaveData &)
double T_current
wavearray< wavereal > WaveData
~linefilter(void)
Destroy the linefilter object and release the function storage.
size_t dumpStart
double Interference(WaveData &, double)
std::vector< float > noise
unsigned int maxLine(int)