Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DrawPhaseShift.C
Go to the documentation of this file.
1 {
2  //
3  // DrawPhaseShift.C : Applies phase shift to sinusoid and draw original and shifted signals
4  // Author : Gabriele Vedovato
5 
6  #define PHASE_SHIFT 90 // phase shift degrees
7  #define SAVE_PLOT // save plot to file
8 
9  // create signal
10  wavearray<double> x(16384);
11  x.rate(512); // sample rate
12  double Pi = TMath::Pi();
13  double dt = 1./x.rate();
14  double F = 10; // frequency Hz
15  for(int i=0;i<x.size();i++) x[i] = sin(2*Pi*F*dt*i);
16 
17  // init plot stuff
18  watplot plot(const_cast<char*>("plot"),200,20,800,500);
19  char gtitle[256];
20  sprintf(gtitle,"Test Phase Shift : Original(black) - phase shifted(Red)");
21  plot.gtitle(gtitle,"time(sec)","amplitude");
22  plot.goptions(const_cast<char*>("alp"), 1, 0., 0.2);
23  // draw signal
24  x >> plot;
25 
26  // aplies phase shift
27  x.FFTW(1);
28  TComplex C;
29  double pShift=-PHASE_SHIFT/360.*TMath::TwoPi();
30  cout << "pShift : " << pShift << endl;
31  for (int ii=0;ii<(int)x.size()/2;ii++) {
32  TComplex X(x.data[2*ii],x.data[2*ii+1]);
33  X=X*C.Exp(TComplex(0.,pShift)); // Phase Shift
34  x.data[2*ii]=X.Re();
35  x.data[2*ii+1]=X.Im();
36  }
37  x.FFTW(-1);
38 
39  // draw phase shift signal
40  x >> plot;
41 
42 #ifdef SAVE_PLOT
43  // save plot to file
44  TString gfile="phase_shift_plot.png";
45  plot >> gfile;
46 #endif
47 }
static const double C
Definition: GNGen.cc: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
plot gtitle(gtitle,"frequency (Hz)","strain/#sqrt{Hz}")
i drho i
x plot
i() int(T_cor *100))
double Pi
double F
#define PHASE_SHIFT
double dt
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TString gfile