Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseFunctionWDM.C
Go to the documentation of this file.
1 {
2  // this macro extract the WDM Base Wave Function and compute time. frequency RMS
3  // rms are used to compute the time,frequency pixel erros for chirp mass in netcluster::mchirp
4 
5  #define nLAYERS 32 // layers used in TF WDM transform
6  #define RATE 512
7  #define DURATION 2 // sec
8 
9  #define TIME_PIXEL_INDEX 100
10  #define FREQ_PIXEL_INDEX 20
11 
12  // define wavearray time series
13  int Rate = RATE; // sampling rate (Hz)
14  int Duration = DURATION; // duration (seconds)
15  int N = Rate*Duration; // number of samples
16  wavearray<double> ts(N); // time series container
17  ts.rate(Rate); // set rate
18  ts=0; // set array to zero
19 
20  // produce the TF map:
21  WDM<double> wdm(nLAYERS, nLAYERS, 6, 10); // define a WDM transform (32 bands)
22  WSeries<double> tf; // TF map container
23 
24  cout << endl;
25  cout << "ts size = " << ts.size() << " ts rate = " << ts.rate() << endl;
26  tf.Forward(ts, wdm); // apply the WDM to the time series
27  int levels = tf.getLevel();
28  //cout << "levels = " << levels << endl;
29  cout << "tf size = " << tf.size() << endl;
30 
31  double dF = tf.resolution(); // frequency bin resolution (hz)
32  double dT = 1./(2*dF); // time bin resolution (sec)
33 
34  cout << "rate(hz) : " << RATE << "\t layers : " << nLAYERS
35  << "\t dF(hz) : " << dF << "\t dT(ms) : " << dT*1000. << endl;
36 
37  // compute tfmap index
38  int itime = TIME_PIXEL_INDEX;
39  int ifreq = FREQ_PIXEL_INDEX;
40  int index = (levels+1)*itime+ifreq;
41 
42  // compute pixel time and frequency resolution
43  double time = itime*dT;
44  double freq = (ifreq>0) ? ifreq*dF : dF/4;
45  cout << endl;
46  cout << "PIXEL TIME = " << time << " sec " << endl;
47  cout << "PIXEL FREQ = " << freq << " Hz " << endl;
48  cout << endl;
49 
50  // get WDM Base Function
52  int j00 = wdm->getBaseWave(index,x,false);
53  x.resize(N);
54  x.rate(RATE);
55 
56  // plot WDM base function
58  gx.Draw(GWAT_TIME);
59 
60  cout << endl;
61 
62  // ------------------------------------------------------
63  // compute the mean and rms time
64  // ------------------------------------------------------
65 
66  double dt = 1./x.rate();
67  //cout << "sample time - dt (ms) = " << dt*1000 << endl;
68  double tee=0.;
69  double tavr=0.;
70  for(int i=0;i<x.size();i++) {
71  double t = i*dt;
72  tavr+=x[i]*x[i]*t;
73  tee+=x[i]*x[i];
74  }
75  tavr/=tee;
76  cout << "mean time : " << tavr << endl;
77 
78  double trms=0.;
79  for(int i=0;i<x.size();i++) {
80  double t = i*dt;
81  trms+=x[i]*x[i]*pow(t-tavr,2);
82  }
83  trms/=tee;
84  trms=sqrt(trms);
85  cout << "rms time : " << trms*1000 << " (ms) " << endl;
86 
87  cout << endl;
88 
89  // ------------------------------------------------------
90  // compute the mean and rms frequency
91  // ------------------------------------------------------
92 
93  x.FFT(1);
94 
95  double df = (double)RATE/x.size();
96  //cout << "frequency resolution : df (Hz) = " << df << endl;
97  double fee=0.;
98  double favr=0.;
99  for(int i=0;i<x.size()/2;i++) {
100  double f = i*df;
101  double e = x[2*i]*x[2*i]+x[2*i+1]*x[2*i+1];
102  favr+=e*f;
103  fee+=e;
104  }
105  favr/=fee;
106  cout << "mean frequency : " << favr << endl;
107 
108  double frms=0.;
109  for(int i=0;i<x.size()/2;i++) {
110  double f = i*df;
111  double e = x[2*i]*x[2*i]+x[2*i+1]*x[2*i+1];
112  frms+=e*pow(f-favr,2);
113  }
114  frms/=fee;
115  frms=sqrt(frms);
116  cout << "rms frequency : " << frms << " (Hz) " << endl;
117 
118 }
wavearray< double > t(hp.size())
virtual size_t size() const
Definition: wavearray.hh:127
int getBaseWave(int m, int n, SymmArray< double > &w)
Definition: WDM.cc:305
int j00
tuple f
Definition: cwb_online.py:91
virtual void rate(double r)
Definition: wavearray.hh:123
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
WDM< double > wdm(nLAYERS, nLAYERS, 6, 10)
i drho i
int getLevel()
Definition: wseries.hh:91
double time[6]
Definition: cbc_plots.C:435
int Duration
gwavearray< double > * gx
int Rate
#define nLAYERS
double e
int ifreq
#define FREQ_PIXEL_INDEX
#define DURATION
double dt
#define RATE
WSeries< double > tf
wavearray< double > ts(N)
wavearray< int > index
double resolution(int=0)
Definition: wseries.hh:137
#define TIME_PIXEL_INDEX
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
double df
double * itime
double dT
Definition: testWDM_5.C:12
virtual void resize(unsigned int)
Definition: wavearray.cc:445
virtual void FFT(int=1)
Definition: wavearray.cc:814
int N