Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Test2G_Whitening.C
Go to the documentation of this file.
1 
2 #define USE_GAUS_NOISE
3 
4 // frame files list
5 #define FRLIST_NAME "S6A_LDR_L1_LDAS_C02_L2.frames"
6 // channel name
7 #define CHANNEL_NAME "L1:LDAS-STRAIN"
8 
10 
11 void
13 // this tutorial shows how to whiten colored gaussian data
14 
15  //Draw plot of strain & whitened PSD data
16  plot = new watplot("plot");
17  TCanvas *c1 = plot->canvas;
18  c1->SetCanvasSize(800,1200);
19  c1->Divide(2,4);
20 
21  // whitening parameters
22  double whiteWindow = 60.; // [sec] time window dT. if = 0 - dT=T, where T is segment duration
23  double whiteStride = 20.; // [sec] noise sampling time stride
24  // segment parameters
25  double segEdge = 8.; // wavelet boundary offset [sec]
26  double segLen = 616.; // Segment length [sec]
27  // frequency range
28  int RATE = 16384; // data sample rate
29 #ifdef USE_GAUS_NOISE
30  double fLow = 16.; // low frequency of the search
31 #else
32  double fLow = 48.; // low frequency of the search
33 #endif
34  double fHigh = 2048.; // high frequency of the search
35 
37 
38 #ifdef USE_GAUS_NOISE
39  // generate colored gaussian noise
40  TString fName = TString(gSystem->ExpandPathName("$HOME_WAT"))+
41  "/tools/cwb/plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt";
42 
43  CWB::Toolbox::getSimNoise(x, fName, 1000, 1);
44  x.resize(segLen*x.rate());
45 #else
46  // real data noise
47  double start = 931081124;
48  double stop = start+segLen;
49  // read frame lists
51  int nfiles=fr.getNfiles();
52  cout << "nfiles : " << nfiles << endl;
53  // get frame list into frfile structure
54  frfile FRF = fr.getFrList(start, stop, 0);
55  // read data into x from frame files
56  fr.readFrames(FRF,CHANNEL_NAME,x);
57  x.start(0);
58 #endif
59 
60  // ----------------------------------------------------------
61  // resample data from 16384 Hz -> 4096 Hz
62  // ----------------------------------------------------------
63  Meyer<double> B(1024); // set wavelet for resampling
64  WSeries<double> W; // WSeries used for resampling
65 
66  W.Forward(x,B,2);
67  W.getLayer(x,0); // extract resampled data
68 
69  RATE = RATE>>2; // 16384 -> 4096
70 
71  // ----------------------------------------------------------
72  // plot WDM strain data distribution
73  // ----------------------------------------------------------
74  double rms=x.rms();
75  TH1F* histS = new TH1F("histS","histS",100,-4*rms,+4*rms);
76  for(int i=0;i<x.size();i++) histS->Fill(x[i]);
77  c1->cd(1);
78  gStyle->SetLineColor(kBlack);
79  histS->Draw();
80  histS->SetTitle("Strain data samples distribution");
81 
82  // ----------------------------------------------------------
83  // plot strain PSD data
84  // ----------------------------------------------------------
85  c1->cd(2);
86  gPad->SetLogx();
87  gPad->SetLogy();
88  gPad->SetGridx();
89  gPad->SetGridy();
90  plot->plot(x, const_cast<char*>("alp"), 1, segEdge, segLen-segEdge, true, fLow, fHigh, true, 8);
91  plot->graph[0]->SetTitle("Strain data PSD");;
92 
93  // ----------------------------------------------------------
94  // initialize WDM used for whitening
95  // ----------------------------------------------------------
96  int level=10; // decomposition level
97  int rate = RATE>>level;
98  double dt = 1000./rate;
99  double df = RATE/2./double(1<<level);
100  cout << "level : " << level << "\t rate : " << rate
101  << "\t df(hz) : " << df << "\t dt(ms) : " << dt << endl;
102  int layers = 1<<level;
103  WDM<double> WDMlpr(layers,layers,6,10);
104 
105  // ----------------------------------------------------------
106  // Time Frequency x data transform
107  // ----------------------------------------------------------
108  WSeries<double> w; // mdc WSeries
109  w.Forward(x,WDMlpr); // x data TF tranform
110 
111  int wlayers = w.maxLayer()+1; // numbers of frequency bins (first & last bins have df/2)
112  int wslices = w.sizeZero(); // number of time bins
113 
114  float wdf = w.resolution(); // frequency bin resolution (hz)
115  float wdt = 1./(2*wdf); // time bin resolution (sec)
116 
117  int wedge = segEdge/wdt; // scratch data
118 
119  // ----------------------------------------------------------
120  // plot strain TF data coefficients
121  // ----------------------------------------------------------
122  c1->cd(3);
123  gPad->SetLogz();
124  plot->plot(w, 2, segEdge, segLen-segEdge,const_cast<char*>("COLZ"));
125  plot->hist2D->GetYaxis()->SetRangeUser(fLow, fHigh);
126  plot->hist2D->GetZaxis()->SetLabelSize(0.04);
127  char title[64];
128  sprintf(title,"Strain data TF sqrt((E00+E90)/2) - level:%d - dt:%g (ms) - df=%g (Hz)", level,dt,df);
129  plot->hist2D->SetTitle(title);
130  plot->hist2D=NULL;
131 
132  // ----------------------------------------------------------
133  // whitening x data
134  // ----------------------------------------------------------
135  WSeries<double> nRMS; // noise RMS
136  w.setlow(fLow);
137  w.sethigh(fHigh);
138  nRMS = w.white(whiteWindow,0,segEdge,whiteStride); // calculate noise rms
139  w.white(nRMS,1); // whiten 0 phase WSeries
140  w.white(nRMS,-1); // whiten 90 phase WSeries
141 
142  // ----------------------------------------------------------
143  // plot nRMS data
144  // ----------------------------------------------------------
145  // nRMS do not come from a TF transform
146  // nRMS params must be fixed before to pass to watplot
147  int levels = nRMS.getLevel()+1; // number of levels
148  int slices = nRMS.size()/levels; // number of nRMS samples
149  double length = slices*whiteStride; // nRMS len in sec
150  double fNinquist = nRMS.rate()/2.;
151  nRMS.rate(nRMS.size()/length);
152  WDM<double>* wdm = (WDM<double>*) nRMS.pWavelet;
153  wdm->nSTS=nRMS.size();
154 
155  c1->cd(4);
156  gPad->SetLogy();
157  gPad->SetLogz();
158  gPad->SetGridx();
159  gPad->SetGridy();
160  double start = nRMS.start();
161  double stop = nRMS.start()+nRMS.size()/nRMS.rate();
162  plot->plot(nRMS, 3, start, stop,const_cast<char*>("COLZ"));
163  plot->hist2D->GetYaxis()->Set(plot->hist2D->GetNbinsY(),0, fNinquist); // correct freq range
164  plot->hist2D->GetYaxis()->SetRangeUser(fLow, fHigh);
165  plot->hist2D->GetZaxis()->SetLabelSize(0.04);
166  sprintf(title,"nRMS TF data");
167  plot->hist2D->SetTitle(title);
168  plot->hist2D=NULL;
169 
170  // ----------------------------------------------------------
171  // plot whitened TF data coefficients
172  // ----------------------------------------------------------
173  c1->cd(5);
174  plot->plot(w, 2, segEdge, segLen-segEdge,const_cast<char*>("COLZ"));
175  plot->hist2D->GetYaxis()->SetRangeUser(fLow, fHigh);
176  sprintf(title,"Whiten data TF sqrt((E00+E90)/2) - level:%d - dt:%g (ms) - df=%g (Hz)", level,dt,df);
177  plot->hist2D->SetTitle(title);
178  plot->hist2D->GetZaxis()->SetLabelSize(0.04);
179 
180  // ----------------------------------------------------------
181  // plot WDM whitened TF data coefficients distribution
182  // ----------------------------------------------------------
183 
184  TH1F* histW = new TH1F("histW","histW",100,-4,+4);
185  for(int i=wedge;i<=wslices-wedge;i++) { // exclude scratch data
186  for(int j=1;j<=wlayers;j++) {
187  int I = i-1;
188  double J = (j-1)+0.01;
189  float aa = w.getSample(I,J); // phase 00 coefficients
190  float AA = w.getSample(I,-J); // phase 90 coefficients
191  histW->Fill(aa);
192  //histW->Fill(AA);
193  }
194  }
195  c1->cd(6);
196  gStyle->SetOptFit();
197  gStyle->SetLineColor(kBlack);
198  gPad->SetLogx(false);
199  histW->Draw();
200  histW->Fit("gaus"); // Fit Histogram
201  histW->SetTitle("Whitened WDM coefficients distribution");
202 
203  // ----------------------------------------------------------
204  // plot white PSD data
205  // ----------------------------------------------------------
206  w.Inverse();
207  c1->cd(7);
208  gPad->SetLogx();
209  gPad->SetGridx();
210  gPad->SetGridy();
211  plot->plot(w, const_cast<char*>("alp"), 1, segEdge, segLen-segEdge, true, fLow, fHigh, true, 8);
212  plot->graph[1]->SetTitle("Whitened data PSD");
213 
214  // ----------------------------------------------------------
215  // plot average & rms of the whitened data vs time
216  // ----------------------------------------------------------
217  int M = w.rate()/16;
218  int N = w.size()/M;
219  double R = w.rate()/M;
220  wavearray<double> TIM(N); TIM.start(0); TIM.rate(R);
221  wavearray<double> AVR(N); AVR.start(0); AVR.rate(R);
222  wavearray<double> RMS(N); RMS.start(0); RMS.rate(R);
223  for(int n=0;n<N;n++) {
224  double avr=0;
225  double rms=0;
226  for(int m=0;m<M;m++) {
227  int p=n*M+m;
228  avr+=w.data[p];
229  rms+=w.data[p]*w.data[p];
230  }
231  avr /= M;
232  rms = sqrt(rms/M-avr*avr);
233  AVR[n]=avr;
234  RMS[n]=rms;
235  TIM[n]=n*(1./double(M));
236  }
237  c1->cd(8);
238  gPad->SetGridx();
239  gPad->SetGridy();
240  plot->plot(AVR, const_cast<char*>("alp"), 1, segEdge, segLen-segEdge);
241  plot->graph[2]->SetTitle("AVR (black )RMS (red) of the whitened data");
242  plot->graph[2]->GetHistogram()->GetYaxis()->SetRangeUser(-1,2);
243  plot->plot(RMS, const_cast<char*>("same"), 2, segEdge, segLen-segEdge);
244 
245  return;
246 }
void sethigh(double f)
Definition: wseries.hh:114
virtual size_t size() const
Definition: wavearray.hh:127
int slices
int nfiles
double fHigh
virtual void rate(double r)
Definition: wavearray.hh:123
#define B
int n
Definition: cwb_net.C:10
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
TString("c")
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
#define CHANNEL_NAME
WDM< double > wdm(nLAYERS, nLAYERS, 6, 10)
CWB::frame fr(FRLIST_NAME)
std::vector< TGraph * > graph
Definition: watplot.hh:176
void setlow(double f)
Definition: wseries.hh:107
int layers
#define M
Definition: UniqSLagsList.C:3
void Test2G_Whitening()
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
double segEdge
Definition: test_config1.C:49
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
double whiteWindow
Definition: test_config1.C:72
#define N
TH2F * hist2D
Definition: watplot.hh:175
virtual double rms()
Definition: wavearray.cc:1188
wavearray< double > w
Definition: Test1.C:27
TCanvas * canvas
Definition: watplot.hh:174
int getLevel()
Definition: wseries.hh:91
static void getSimNoise(wavearray< double > &u, TString fName, int seed, int run)
Definition: Toolbox.cc:4809
unsigned long nSTS
Definition: WaveDWT.hh:125
TCanvas * c1
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:175
segLen
Definition: cwb_eced.C:7
frfile FRF[nIFO+1]
Definition: cwb_net.C:251
watplot * plot
int getNfiles()
Definition: frame.hh:92
double dt
#define RATE
char title[256]
Definition: SSeriesExample.C:1
double fLow
Definition: Meyer.hh:18
double whiteStride
Definition: test_config1.C:73
double resolution(int=0)
Definition: wseries.hh:137
#define FRLIST_NAME
void readFrames(char *filename, char *channel, wavearray< double > &w)
Definition: frame.cc:810
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
double df
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
frfile getFrList(int istart, int istop, int segEdge)
Definition: frame.cc:509
DataType_t * data
Definition: wavearray.hh:301
DataType_t getSample(int n, double m)
Definition: wseries.hh:167
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
char fName[256]
virtual void resize(unsigned int)
Definition: wavearray.cc:445
double length
Definition: TestBandPass.C:18
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:273
size_t sizeZero()
Definition: wseries.hh:126
int maxLayer()
Definition: wseries.hh:121
virtual WSeries< double > white(double, int, double=0., double=0.)
what it does: each wavelet layer is devided into k intervals.
Definition: wseries.cc:1128
double avr