Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Regression_Sine.C
Go to the documentation of this file.
1 //
2 //How to apply regression to subtract sinusoidal line at 100Hz
3 //Generate time series w(t) and x(t) each containing Gaussian white noise (unit variance)
4 //Construct the witness channel: A(t) = 0.1*w(t) + 0.25*sin(2pi*100*t)
5 //Construct the target channel: H(t) = x(t) + sin(2pi*100*t)
6 //Plot Fourier Transform of target and cleaned
7 //
8 
9 {
10  //Time
11  #define LENGHT 1200
12  #define RATE 2048
13  //Frequency near 180Hz
14  #define F1 95
15  #define F2 105
16 
17  double omega = TMath::TwoPi()*100;
18 
19  using namespace CWB;
20  int totalscratch=32;
21 
22  //Fill wavearray h with target channel
25  h.rate(RATE);
26  h.resize(N);
27  h.start(0);
28  h.stop(LENGHT+2*totalscratch);
29 
30  // time series is filled with white noise data:
31  TRandom3 rnd(0);
32  for(int i=0; i<N; i++) h[i] = rnd.Gaus();
33 
34  // add a sine wave @ 100Hz:
35  double T = 1./RATE;
36  for(int i=0; i<N; i++) h[i] += sin(omega*i*T);
37 
38  //Make WDM transform, resolution = 1Hz
39  int lev=h.rate()/2;
40  WDM<double> wdtf(lev, 2*lev, 6, 10);
42  tfmap.Forward(h, wdtf);
43 
44  //Defining auxiliary channels
46  x.rate(RATE);
47  x.resize(N);
48  x.start(0);
49  x.stop(LENGHT+2*totalscratch);
50 
51  // time series is filled with white noise data:
52  for(int i=0; i<N; i++) x[i] = 0.1*rnd.Gaus();
53 
54  // add a sine wave @ 100Hz:
55  T = 1./RATE;
56  for(int i=0; i<N; i++) x[i] += 0.25*sin(omega*i*T);
57 
58  //Adding target channel
59  regression r;
60  r.add(tfmap,const_cast<char*>("hchannel"));
61 
62  //Considering only the interested frequency band
63  r.mask(0);
64  r.unmask(0,F1,F2);
65 
66  //Adding witness channel
67  r.add(x,const_cast<char*>("witness"));
68 
69  //Calculate prediction
70  r.setFilter(5);
71  r.setMatrix(totalscratch);
72  r.solve(0., 4, 'h');
73  r.apply(0.2);
74 
75  //Draw plot of target and target-prediction
76  watplot plot;
77  gPad->SetLogy();
78  plot.plot(h,const_cast<char*>("alp"), 1, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
79  wavearray<double> clean = r.getClean();
80  plot.plot(clean,const_cast<char*>("same"), 2, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
81  plot.graph[0]->SetTitle("Black : noisy data | Red : cleaned data");
82  plot >> const_cast<char*>("Regression_Sine.png");
83 
84  //Write ranking for each frequency layer
85  wavearray<double> freq=r.vfreq;
87  cout << "Ranking:" << endl;
88  for (int i=0; i<freq.size(); i++) cout << freq.data[i] << " " << rank.data[i] << endl;
89  cout << endl;
90 
91  //Write eigenvalues for each frequency layer
92  cout << "Eigen-values" << endl;
93  wavearray<double>* eigen = new wavearray<double>[freq.size()];
94  for (int i=0; i<freq.size(); i++) eigen[i]=r.getVEIGEN(i);
95  for (int j=0; j<eigen[0].size(); j++)
96  {
97  for (int i=0; i<freq.size(); i++)
98  printf("%.3f\t",eigen[i].data[j]);
99  cout << endl;
100  }
101 }
TRandom3 rnd(0)
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:407
printf("total live time: non-zero lags = %10.1f \n", liveTot)
Definition: ced.hh:24
virtual void rate(double r)
Definition: wavearray.hh:123
#define F2
float * rank
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
#define LENGHT
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
std::vector< TGraph * > graph
Definition: watplot.hh:176
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
Definition: regression.cc:73
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
i drho i
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:132
int N
x plot
wavearray< double > h
void apply(double threshold=0., char c='a')
Definition: regression.cc:691
wavearray< double > getRank(int n)
Definition: regression.hh:134
WSeries< double > tfmap
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:592
wavearray< double > vfreq
Definition: regression.hh:171
size_t setFilter(size_t)
Definition: regression.cc:258
wavearray< double > getVEIGEN(int n=-1)
Definition: regression.cc:339
wavearray< double > getClean()
Definition: regression.hh:117
regression r
Definition: Regression_H1.C:44
WDM< double > wdtf(lev, 2 *lev, 6, 10)
double T
Definition: testWDM_4.C:11
virtual void stop(double s)
Definition: wavearray.hh:121
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
void unmask(int n, double flow=0., double fhigh=0.)
Definition: regression.cc:321
void mask(int n, double flow=0., double fhigh=0.)
Definition: regression.cc:303
double omega
Definition: testWDM_4.C:12
#define RATE
#define F1
DataType_t * data
Definition: wavearray.hh:301
int totalscratch
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:445