Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Regression_Sine_Bic.C
Go to the documentation of this file.
1 //
2 //How to apply regression to subtract sinusoidal line at 100 +/- 2 Hz
3 //Note: in this example we do not clean the carrier line at 100 Hz
4 //Generate time series w(t), v(t) and x(t) each containing Gaussian white noise (unit variance)
5 //Construct the witness channel: A(t) = 0.1*w(t) + 0.2*sin(2pi*100*t)
6 //Construct the witness channel: B(t) = 0.1*v(t) + 0.2*sin(2pi*2*t)
7 //Construct the target channel: H(t) = x(t) + 0.5*sin(2pi*100*t)*sin(2pi*2*t)
8 //Use Bicoherence of A*B to clean the lines at 100 +/-2 Hz
9 //Plot Fourier Transform of target and cleaned
10 
11 
12 {
13  //Time
14  #define LENGHT 1200
15  #define RATE 2048
16  //Frequency near 180Hz
17  #define F1 95
18  #define F2 105
19 
20  double omega = TMath::TwoPi()*100;
21  double omega_lf = TMath::TwoPi()*2;
22 
23  using namespace CWB;
24  int totalscratch=32;
25 
26  //Fill wavearray h with target channel
29  h.rate(RATE);
30  h.resize(N);
31  h.start(0);
32  h.stop(LENGHT+2*totalscratch);
33 
34  // time series is filled with white noise data:
35  TRandom3 rnd(0);
36  for(int i=0; i<N; i++) h[i] = rnd.Gaus();
37 
38  // add a sine wave @ 100Hz:
39  double T = 1./RATE;
40  for(int i=0; i<N; i++) h[i] += sin(omega*i*T);
41  for(int i=0; i<N; i++) h[i] += sin(omega*i*T) + 0.5*sin(omega*i*T)*sin(omega_lf*i*T);
42 
43  //Make WDM transform, resolution = 1Hz
44  int lev=h.rate()/2;
45  WDM<double> wdtf(lev, 2*lev, 6, 10);
47  tfmap.Forward(h, wdtf);
48 
49  //Defining auxiliary channels with describe carrier at 100Hz
51  x.rate(RATE);
52  x.resize(N);
53  x.start(0);
54  x.stop(LENGHT+2*totalscratch);
55 
56  // time series is filled with white noise data:
57  for(int i=0; i<N; i++) x[i] = 0.1*rnd.Gaus();
58 
59  // add a sine wave @ 100Hz:
60  T = 1./RATE;
61  for(int i=0; i<N; i++) x[i] += 0.2*sin(omega*i*T);
62 
63  //Defining auxiliary channels which describe low frequency
64  wavearray<double> x_lf;
65  x_lf.rate(RATE);
66  x_lf.resize(N);
67  x_lf.start(0);
68  x_lf.stop(LENGHT+2*totalscratch);
69 
70  // time series is filled with white noise data:
71  for(int i=0; i<N; i++) x_lf[i] = 0.1*rnd.Gaus();
72 
73  // add a sine wave @ 100Hz:
74  T = 1./RATE;
75  for(int i=0; i<N; i++) x_lf[i] += 0.2*sin(omega_lf*i*T);
76 
77  //Adding target channel
78  regression r;
79  r.add(tfmap,const_cast<char*>("hchannel"));
80 
81  //Considering only the interested frequency band
82  r.mask(0);
83  r.unmask(0,F1,F2);
84 
85  //Adding witness channel
86  r.add(x,const_cast<char*>("witness"));
87  r.add(x_lf,const_cast<char*>("witness_lf"));
88  //Constructing channel describing multi-linear coupling
89  r.add(1,2,const_cast<char*>("bic_witness"));
90  //masking carrier channels and
91  r.mask(1);
92  r.mask(2);
93 
94  //Calculate prediction
95  r.setFilter(5);
96  r.setMatrix(totalscratch);
97  r.solve(0., 4, 'h');
98  r.apply(0.2);
99 
100  //Draw plot of target and target-prediction
101  watplot plot;
102  gPad->SetLogy();
103  plot.plot(h,const_cast<char*>("alp"), 1, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
104  wavearray<double> clean = r.getClean();
105  plot.plot(clean,const_cast<char*>("same"), 2, totalscratch, totalscratch+LENGHT, true, F1, F2, true, 50);
106  plot.graph[0]->SetTitle("Black : noisy data | Red : cleaned data");
107  plot >> const_cast<char*>("Regression_Sine_Bic.png");
108 
109  //Write ranking for each frequency layer
110  wavearray<double> freq=r.vfreq;
112  cout << "Ranking:" << endl;
113  for (int i=0; i<freq.size(); i++) cout << freq.data[i] << " " << rank.data[i] << endl;
114  cout << endl;
115 
116  //Write eigenvalues for each frequency layer
117  cout << "Eigen-values" << endl;
118  wavearray<double>* eigen = new wavearray<double>[freq.size()];
119  for (int i=0; i<freq.size(); i++) eigen[i]=r.getVEIGEN(i);
120  for (int j=0; j<eigen[0].size(); j++)
121  {
122  for (int i=0; i<freq.size(); i++)
123  printf("%.3f\t",eigen[i].data[j]);
124  cout << endl;
125  }
126 }
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
float * rank
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
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
TRandom3 rnd(0)
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
#define LENGHT
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
#define F2
wavearray< double > getClean()
Definition: regression.hh:117
wavearray< double > h
#define RATE
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 totalscratch
DataType_t * data
Definition: wavearray.hh:301
double omega_lf
#define F1
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:445