Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Regression_Sine_parameters.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 //Compare different regression parameters
7 //Plot Fourier Transform of target and cleaned
8 //
9 
10 
11 {
12  //Time
13  #define LENGHT 1200
14  #define RATE 2048
15  //Frequency near 180Hz
16  #define F1 95
17  #define F2 105
18 
19  //Auxiliary channels
20 
21  using namespace CWB;
22  int totalscratch=32;
23 
24  //Fill wavearray h with target channel
27  h.rate(RATE);
28  h.resize(N);
29  h.start(0);
30  h.stop(LENGHT+2*totalscratch);
31 
32  // time series is filled with white noise data:
33  TRandom3 rnd(0);
34  for(int i=0; i<N; i++) h[i] = rnd.Gaus();
35 
36  // add a sine wave @ 100Hz:
37  double T = 1./RATE;
38  double omega = TMath::TwoPi()*100;
39  for(int i=0; i<N; i++) h[i] += sin(omega*i*T);
40 
41  //Make WDM transform, resolution = 1Hz
42  int lev=h.rate()/2;
43  WDM<double> wdtf(lev, 2*lev, 6, 10);
45  tfmap.Forward(h, wdtf);
46 
47  //Adding auxiliary channels
49  x.rate(RATE);
50  x.resize(N);
51  x.start(0);
52  x.stop(LENGHT+2*totalscratch);
53 
54  for(int i=0; i<N; i++) x[i] = 0.1*rnd.Gaus();
55  // add a sine wave @ 100Hz:
56  T = 1./RATE;
57  omega = TMath::TwoPi()*100;
58  for(int i=0; i<N; i++) x[i] += 0.25*sin(omega*i*T);
59 
60  //Adding channels
61  regression r;
62  r.add(tfmap,const_cast<char*>("hchannel"));
63  r.mask(0);
64  r.unmask(0,F1,F2);
65  r.add(x,const_cast<char*>("witness"));
66 
67  regression r2=r;
68  regression r3=r;
69  regression r4=r;
70 
71  //Calculate prediction
72  //r.setFilter(10);
73  //r.setMatrix(totalscratch,.95);
74  //r.solve(0.2, 0, 'h');
75  //r.apply(0.2);
76  r.setFilter(5);
77  r.setMatrix(totalscratch);
78  r.solve(0., 4, 'h');
79  r.apply(0.2);
80 
81  r2.setFilter(5);
82  r2.setMatrix(totalscratch,.95);
83  r2.solve(0, 4, 'h');
84  r2.apply(0.8);
85 
86  r3.setFilter(5);
87  r3.setMatrix(totalscratch,.95);
88  r3.solve(0, 2, 'h');
89  r3.apply(0.2);
90 
91  r4.setFilter(2);
92  r4.setMatrix(totalscratch,.95);
93  r4.solve(0., 4, 'h');
94  r4.apply(0.2);
95 
96  //Draw plot of target and target-prediction
97  TCanvas *c1 = new TCanvas("comp","comp",0,0,800,600);
98  c1->Divide(2,2);
99 
100  watplot plot(const_cast<char*>("plot"));
101 
102  c1->cd(1);
103  gPad->SetLogy();
104  plot.plot(h,const_cast<char*>("alp"), 1, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
105  wavearray<double> clean = r.getClean();
106  plot.plot(clean,const_cast<char*>("same"), 2, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
107  plot.graph[0]->SetTitle("Black : noisy data | Red : cleaned data");
108 
109  c1->cd(2);
110  gPad->SetLogy();
111  plot.plot(h,const_cast<char*>("alp"), 1, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
112  clean = r2.getClean();
113  plot.plot(clean,const_cast<char*>("same"), 2, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
114  plot.graph[2]->SetTitle("Black : noisy data | Red : cleaned data");
115 
116  c1->cd(3);
117  gPad->SetLogy();
118  plot.plot(h,const_cast<char*>("alp"), 1, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
119  clean = r3.getClean();
120  plot.plot(clean,const_cast<char*>("same"), 2, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
121  plot.graph[4]->SetTitle("Black : noisy data | Red : cleaned data");
122 
123  c1->cd(4);
124  gPad->SetLogy();
125  plot.plot(h,const_cast<char*>("alp"), 1, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
126  clean = r4.getClean();
127  plot.plot(clean,const_cast<char*>("same"), 2, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
128  plot.graph[6]->SetTitle("Black : noisy data | Red : cleaned data");
129 
130  c1->SaveAs("Regression_Sine_parameters.png");
131 
132 }
static double r3
Definition: geodesics.cc:8
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:407
Definition: ced.hh:24
virtual void rate(double r)
Definition: wavearray.hh:123
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
#define F1
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
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
i drho i
x plot
static double r2
Definition: geodesics.cc:8
#define RATE
#define F2
TCanvas * c1
void apply(double threshold=0., char c='a')
Definition: regression.cc:691
WSeries< double > tfmap
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:592
wavearray< double > h
size_t setFilter(size_t)
Definition: regression.cc:258
wavearray< double > getClean()
Definition: regression.hh:117
#define LENGHT
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
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:445
TRandom3 rnd(0)