Logo coherent WaveBurst  
Library Reference Guide
Logo
Test3.C
Go to the documentation of this file.
1 //Test 3: Similar, but witness channel includes more uncorrelated noise:
2 //Witness channel: A(t) = y(t) + w(t)
3 //Target channel: H(t) = x(t) + 0.8*w(t)
4 //Compare the ASD (or simply the RMS) of H(t) before and after regression.
5 //Since regression removes the w(t) correlated noise but adds an equal
6 //amount of y(t) noise, it should not be able to reduce the noise amplitude in H(t).
7 
8 {
9  //Time
10  #define LENGHT 1200
11  #define SCRATCH 32
12  #define RATE 2048
13 
14  using namespace CWB;
15 
16  //define x channel properties -> gauss 1
17  int N = RATE*(LENGHT+2*SCRATCH);
19  x.rate(RATE);
20  x.resize(N);
21  x.start(0);
22  x.stop(LENGHT+2*SCRATCH);
23 
24  //define w channel properties -> gauss 2
27 
28  // time series is filled with white noise data:
29  TRandom3 rnd(0);
30  for(int i=0; i<N; i++) x[i] = rnd.Gaus();
31  for(int i=0; i<N; i++) w[i] = rnd.Gaus();
32  for(int i=0; i<N; i++) y[i] = rnd.Gaus();
33 
34  //Fill target and witness
35  wavearray<double> A = w; A += y;
36  wavearray<double> H = x; w*= 0.8; H += w;
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  //Adding target channel
45  regression r;
46  r.add(tfmap,const_cast<char*>("hchannel"));
47 
48  //Adding witness channel
49  r.add(A,const_cast<char*>("witness"));
50 
51  //Calculate prediction
52  r.setFilter(5);
53  r.setMatrix(SCRATCH);
54  r.solve(0, 20, 'h');
55  r.apply(0.2);
56 
57  wavearray<double> clean=r.getClean();
58  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
59 
60  cout << "x : " << x.mean() << " " << x.rms() << endl;
61  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
62  clean -= x;
63  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
64 
65  wavearray<double> eigen=r.getVEIGEN(-1);
66  eigen.rate(11);
67  watplot plot;
68  TCanvas *c1 = plot.canvas;
69  c1->Divide(1,2);
70 
71  c1->cd(1);
72  plot.plot(eigen,const_cast<char*>("alp"),1);
73  plot.graph[0]->SetTitle("Eigen-values of all layers");
74 
77  c1->cd(2);
78  TGraph* g=new TGraph(freq.size(),freq.data,rank.data);
79  g->SetLineColor(1);
80  g->Draw("alp");
81  g->SetTitle("Ranking for all layers");
82 
83  c1->SaveAs("Test3.png");
84 
85 
86  exit(0);
87 
88 }
#define SCRATCH
static double g(double e)
Definition: GNGen.cc:116
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:425
Definition: ced.hh:42
virtual void rate(double r)
Definition: wavearray.hh:141
TRandom3 rnd(0)
wavearray< double > rank
Definition: Regression_H1.C:80
std::vector< TGraph * > graph
Definition: watplot.hh:194
wavearray< double > y
Definition: Test3.C:26
wavearray< double > x
Definition: Test3.C:18
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
Definition: regression.cc:91
virtual void start(double s)
Definition: wavearray.hh:137
i drho i
#define LENGHT
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:150
virtual double rms()
Definition: wavearray.cc:1206
virtual size_t size() const
Definition: wavearray.hh:145
#define RATE
TCanvas * canvas
Definition: watplot.hh:192
wavearray< double > freq
Definition: Regression_H1.C:79
x plot
TCanvas * c1
void apply(double threshold=0., char c='a')
Definition: regression.cc:709
wavearray< double > getRank(int n)
Definition: regression.hh:152
WSeries< double > tfmap
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:610
wavearray< double > vfreq
Definition: regression.hh:189
static double A
Definition: geodesics.cc:26
size_t setFilter(size_t)
Definition: regression.cc:276
wavearray< double > getVEIGEN(int n=-1)
Definition: regression.cc:357
wavearray< double > getClean()
Definition: regression.hh:135
regression r
Definition: Regression_H1.C:44
WDM< double > wdtf(lev, 2 *lev, 6, 10)
virtual double mean() const
Definition: wavearray.cc:1071
virtual void stop(double s)
Definition: wavearray.hh:139
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
DataType_t * data
Definition: wavearray.hh:319
wavearray< double > w
Definition: Test3.C:25
int N
Definition: Test3.C:17
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:463
exit(0)