Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ComputeSNR.C
Go to the documentation of this file.
1 //
2 // generate MDC & Read PSD from file & compute SNR
3 // Author : Gabriele Vedovato
4 
5 {
6  #define ADV_LIGO_PSD "$HOME_WAT/tools/cwb/plugins/strains/advLIGO_NSNS_Opt_8khz_one_side.txt"
7  #define DELTA_FREQ 0.125 // Hz
8 
9  //#define WNB_MDC
10  #define RD_MDC
11  //#define SGQ_MDC
12 
13  #define AMP_FACTOR 1e-21
14 
15  #define FLOW 32
16  #define FHIGH 2048
17 
18  #include <vector>
19 
20  TString psdName = gSystem->ExpandPathName(ADV_LIGO_PSD);
21 
24 
25 #ifdef WNB_MDC
26  wavearray<double> x = MDC.GetWNB(1000., 1000., 0.01);
27 #endif
28 #ifdef RD_MDC
29  wavearray<double> x = MDC.GetRD(1000., 0.2, 10.);
30 #endif
31 #ifdef SGQ_MDC
32  wavearray<double> x = MDC.GetSGQ(1053., 9);
33 #endif
34 
35  x*=AMP_FACTOR;
36  //MDC.Draw(x,MDC_FFT);return; // Draw Waveform in frequency domain
37  //MDC.Draw(x);return; // Draw Waveform in time domain
38 
39  // compute x energy in time domain
40  double Et=0;
41  double dt=1./x.rate();
42  for(int i=0;i<x.size();i++) Et+=x[i]*x[i]*dt;
43  cout << "Et = " << Et << endl;
44 
45  x.FFT(1);
46  double df=(double)x.rate()/(double)x.size();
47  x*=1./df; // double side spectrum
48 
49  // compute x energy in frequency domain
50  double Ef=0;
51  for(int i=0;i<x.size();i++) Ef+=x[i]*x[i]*df;
52  cout << "Ef = " << 2*Ef << endl;
53 
54  double fWidth = x.rate()/2; // bandwidth
55  double dFreq = df; // frequency resolution
56  wavearray<double> psd = TB.GetDetectorPSD(psdName,fWidth,dFreq); // psd is one side PSD
57  //double df=psd.rate()/psd.size();
58  cout << "PSD : " << " rate : " << psd.rate() << " size : " << psd.size() << " df " << df << endl;
59  psd*=1./sqrt(2); // single -> double side PSD
60 
61  // compute SNR
62  double fLow=FLOW;
63  double fHigh=FHIGH;
64  double snr=0;
65  for(int i=0;i<psd.size();i++) {
66  double freq=i*df;
67  if(freq<fLow || freq>fHigh) continue;
68  snr+=(x[2*i]*x[2*i]+x[2*i+1]*x[2*i+1])/pow(psd[i],2)*df;
69  }
70  snr*=2; // add negative side integration
71  snr=sqrt(snr);
72  cout << "SNR " << snr << endl;
73 
74  // define frequency array
76  for(int i=0;i<f.size();i++) f[i]=i*df;
77 
78  // define mdc amplitude array
80  for(int i=0;i<a.size();i++) a[i]=sqrt(x[2*i]*x[2*i]+x[2*i+1]*x[2*i+1]);
81 
82  TObjArray* token = TString(psdName).Tokenize(TString('/'));
83  TObjString* sname = (TObjString*)token->At(token->GetEntries()-1);
84  TString Title = sname->GetString();
85 
86  // display PSD
87  TCanvas canvas;
88  canvas.SetLogx();
89  canvas.SetLogy();
90  canvas.SetGridx();
91  canvas.SetGridy();
92  TGraph grMDC(psd.size(),f.data,a.data);
93  grMDC.SetMarkerColor(kBlue);
94  grMDC.SetLineColor(kBlue);
95  TGraph grPSD(psd.size(),f.data,psd.data);
96  grPSD.SetTitle(Title);
97  grPSD.SetMarkerColor(kRed);
98  grPSD.SetLineColor(kRed);
99  grPSD.GetHistogram()->GetXaxis()->SetRangeUser(8,8192);
100  grPSD.GetHistogram()->GetYaxis()->SetRangeUser(1e-24,1e-21);
101  grPSD.GetHistogram()->GetXaxis()->SetTitle("Hz");
102  grPSD.GetHistogram()->GetYaxis()->SetTitle("PSD");
103  grPSD.GetHistogram()->GetYaxis()->SetTitleOffset(1.2);
104 
105  grPSD.Draw("ALP");
106  grMDC.Draw("SAME");
107 }
108 
virtual size_t size() const
Definition: wavearray.hh:127
double fHigh
virtual void rate(double r)
Definition: wavearray.hh:123
wavearray< double > a(hp.size())
TString("c")
wavearray< double > GetSGQ(double frequency, double Q)
Definition: mdc.cc:2976
wavearray< double > psd(33)
return wmap canvas
i drho i
CWB::mdc MDC
Definition: ComputeSNR.C:23
CWB::Toolbox TB
Definition: ComputeSNR.C:5
double fWidth
Definition: DrawPSD.C:16
cout<< "SNR "<< snr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
#define AMP_FACTOR
Definition: mdc.hh:216
#define FLOW
wavearray< double > GetWNB(double frequency, double bandwidth, double duration, int seed=0, bool mode=0)
Definition: mdc.cc:3024
#define FHIGH
TObjArray * token
x *double Et
Definition: ComputeSNR.C:40
double e
static wavearray< double > GetDetectorPSD(TString fName, double fWidth=8192., double dFreq=1.)
Definition: Toolbox.cc:4986
double dt
Definition: ComputeSNR.C:41
double fLow
double df
wavearray< double > x
Definition: ComputeSNR.C:29
DataType_t * data
Definition: wavearray.hh:301
double dFreq
Definition: DrawPSD.C:17
snr * snr
Definition: ComputeSNR.C:71
#define ADV_LIGO_PSD
wavearray< double > GetRD(double frequency, double tau, double iota, bool polarization=0)
Definition: mdc.cc:3139
virtual void FFT(int=1)
Definition: wavearray.cc:814