UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hilbert_transform_inline.hpp
1 /* hilbert_transform_inline.hpp */
2 /* $Id: hilbert_transform_inline.hpp 21022 2011-07-11 11:45:03Z urij $ */
3 #ifndef __hilbert_transform_inline_hpp
4 #define __hilbert_transform_inline_hpp
5 
6 template <typename FFT_T>
7 bool Hilbert::transform(FFT_T &fft, Trace &trace, int direction)
8 {
9  // check direction
10  if (direction != -1 && direction != 1)
11  {
12  printf ("S2Corr::hilbertTransform: warning: incorrect direction (%d), fixed to 1.\n",
13  direction);
14  direction = 1;
15  }
16 
17  // FFT with rotated frequency scale, where f=0 at the center
18  fft.setRotateFlag(true);
19 
20 #warning proper t0 calc should be fixed in CDFT2D_FFTW
21  double t0 = trace.header().t0;
22 
23  // calc spectrum
24  Trace trace_im(trace.header(), trace.size(), 0.);
25  fft.setDirection(1);
26  //fft.setNormType(CDFT2D::INORM);
27  if (!fft.calc(trace, trace_im))
28  {
29  printf ("S2Corr::hilbertTransform: error: can't calc direct FFT.\n");
30  return false;
31  }
32 
33  // calc Hilbert transform in spectrum domain
34  for (size_t i=0; i<trace.size(); i++)
35  {
36  double w = trace.header().t0 + i*trace.header().timestep;
37  double sig_w = (w>0)?1:(-1);
38  if (w == 0.)
39  sig_w = 0.;
40 
41  double re = direction*sig_w*trace_im[i];
42  trace_im[i] = -direction*sig_w*trace[i];
43  trace[i] = re;
44  }
45 
46  // inverse Fourier
47  fft.setDirection(-1);
48  if (!fft.calc(trace, trace_im))
49  {
50  printf ("S2Corr::hilbertTransform: error: can't calc inverse FFT.\n");
51  return false;
52  }
53  trace.header().t0 = t0;
54 
55  return true;
56 }
57 
58 
59 #endif /* hilbert_transform_inline.hpp */
bool transform(FFT_T &fft, Trace &trace, int direction=1)
Definition: hilbert_transform_inline.hpp:7
size_t size() const
const Header & header() const
Definition: trace.hpp:196
TimeT timestep
Definition: trace.hpp:122
TimeT t0
Definition: trace.hpp:119
Definition: trace.hpp:14