Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Test1.C
Go to the documentation of this file.
1 //Test 1: Removal of broadband noise using a single, highly correlated witness channel.
2 //You can prepare the channels with the desired correlation this way, for instance:
3 //Generate time series w(t) and x(t) each containing Gaussian white noise (unit variance)
4 //Construct the witness channel: A(t) = w(t)
5 //Construct the target channel: H(t) = x(t) + 0.8*w(t)
6 //Compare the ASD (or simply the RMS) of H(t) before and after regression.
7 //The regression should be able to reduce the noise amplitude by a factor of
8 // 1/sqrt(1^2+0.8^2) = 1/sqrt(1.64) ~ 0.78
9 
10 {
11  //Time
12  #define LENGHT 1200
13  #define SCRATCH 32
14  #define RATE 2048
15 
16  using namespace CWB;
17 
18  //define x channel properties -> gauss 1
19  int N = RATE*(LENGHT+2*SCRATCH);
21  x.rate(RATE);
22  x.resize(N);
23  x.start(0);
24  x.stop(LENGHT+2*SCRATCH);
25 
26  //define w channel properties -> gauss 2
28 
29  // time series is filled with white noise data:
30  TRandom3 rnd(0);
31  for(int i=0; i<N; i++) x[i] = rnd.Gaus();
32  for(int i=0; i<N; i++) w[i] = rnd.Gaus();
33 
34  //Fill target and witness
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.5, 0, '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 
75  wavearray<double> freq=r.vfreq;
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("Test1.png");
84 
85  exit(0);
86 }
virtual size_t size() const
Definition: wavearray.hh:127
static double g(double e)
Definition: GNGen.cc:98
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
float * rank
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
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
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
virtual double mean() const
Definition: wavearray.cc:1053
virtual double rms()
Definition: wavearray.cc:1188
wavearray< double > w
Definition: Test1.C:27
TCanvas * canvas
Definition: watplot.hh:174
x plot
TRandom3 rnd(0)
TCanvas * c1
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
static double A
Definition: geodesics.cc:8
size_t setFilter(size_t)
Definition: regression.cc:258
wavearray< double > getVEIGEN(int n=-1)
Definition: regression.cc:339
int N
Definition: Test1.C:19
wavearray< double > getClean()
Definition: regression.hh:117
regression r
Definition: Regression_H1.C:44
WDM< double > wdtf(lev, 2 *lev, 6, 10)
#define SCRATCH
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
#define LENGHT
DataType_t * data
Definition: wavearray.hh:301
#define RATE
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:445
exit(0)
wavearray< double > x
Definition: Test1.C:20