STFINV library: seek source wavelet correction filter
stfinvnormalize.cc
Go to the documentation of this file.
1 
35 #define STFINV_STFINVNORMALIZE_CC_VERSION \
36  "STFINV_STFINVNORMALIZE_CC V1.0"
37 
38 #include <stfinv/stfinvnormalize.h>
39 #include <aff/functions/sqrsum.h>
40 #include <stfinv/debug.h>
41 #include <cmath>
42 
43 namespace stfinv {
44 
45  const char* const STFEngineNormalize::ID="fdnorm";
46 
47  const char* const STFEngineNormalize::description
48  ="Fourier domain normalization";
49 
50  /*----------------------------------------------------------------------*/
51 
52  void STFEngineNormalize::help(std::ostream& os) const
53  {
55  } // void STFEngineNormalize::help(std::ostream& os) const
56 
57  /*----------------------------------------------------------------------*/
58 
59  const char* STFEngineNormalize::name() const
60  {
61  return("STFEngineNormalize");
62  } // const char const* STFEngineNormalize::name() const
63 
64  /*----------------------------------------------------------------------*/
65 
67  {
68  // scale energy
69  std::istringstream is (this->parameter("waterlevel","1.e-3"));
70  is >> Mwaterlevel;
71  STFINV_debug(Mdebug&1, "STFEngineNormalize::initialize()",
72  "Mwaterlevel=" << Mwaterlevel);
74  "ERROR: parameter for option \"waterlevel\" not larger than 0");
75  } // void STFEngineNormalize::initialize()
76 
77  /*----------------------------------------------------------------------*/
78 
80  {
81  // read signals and calculate FFT
82  this->fftinput();
83 
84  // cycle through frequencies
85  // calculate weighted energy of all synthetic traces
86  Tseries syntheticenergy(0,this->nfreq()-1);
87  syntheticenergy=0.;
88  double totalsyntheticenergy=0.;
89  for (unsigned int i=0; i<this->nfreq(); ++i)
90  {
91  TAspectrum syntheticref=this->syntheticcoeff(i);
92  for (unsigned int j=0; j<this->nreceivers(); ++j)
93  {
94  syntheticenergy(i) += this->weight(j)*this->weight(j)
95  *std::norm(syntheticref(j));
96  }
97  totalsyntheticenergy += syntheticenergy(i);
98  }
99 
100  // calculate waterlevel
101  double waterlevel=Mwaterlevel*totalsyntheticenergy/this->nfreq();
102 
103  double weightsum=aff::func::sqrsum(this->weights());
104 
105  for (unsigned int i=0; i<this->nfreq(); ++i)
106  {
107  double recordingenergy=0.;
108  TAspectrum recordingref=this->recordingcoeff(i);
109  TAspectrum syntheticref=this->syntheticcoeff(i);
110  for (unsigned int j=0; j<this->nreceivers(); ++j)
111  {
112  recordingenergy += this->weight(j)*this->weight(j)
113  *std::norm(recordingref(j));
114  }
115 
116  double modulus
117  =std::sqrt(recordingenergy/(syntheticenergy(i)+waterlevel));
118 
119  double phase = 0.;
120  for (unsigned int j=0; j<this->nreceivers(); ++j)
121  {
122  phase += this->weight(j)*
123  (std::arg(recordingref(j))-std::arg(syntheticref(j)));
124  }
125  phase /= weightsum;
126 
127  this->stfcoeff(i)=std::polar(modulus, phase);
128  } // for (unsigned int i=0; i<this->nfreq(); ++i)
129 
130  // provide results to user
131  this->fftoutput();
132  } // void STFEngineNormalize::exec()
133 
134  /*----------------------------------------------------------------------*/
135 
136  void STFEngineNormalize::classhelp(std::ostream& os)
137  {
138  os << "class STFEngineNormalize ("
139  << STFEngineNormalize::ID << ")\n";
140  os << STFEngineNormalize::description << "\n" << std::endl;
142  os << "DESCRIBE HERE\n"
143  << "A waterlevel as a fraction of the signal energy of the\n"
144  << "input synthetics is applied. If per receiver scaling is\n"
145  << "selected, the receivers will be weighted in the deconvolution.\n";
146  os << "Options and parameters:\n"
147  << "waterlevel=l waterlevel to be applied for regularization."
148  << std::endl;
149  Tbase::classhelp(os);
150  } // void STFEngineNormalize::classhelp(std::ostream& os)
151 
152 } // namespace stfinv
153 
154 /* ----- END OF stfinvnormalize.cc ----- */
static void classhelp(std::ostream &os=std::cout)
print online help
unsigned int nreceivers() const
return number of receiver signals in use
Definition: stfinvbase.h:259
double weight(const unsigned int &i) const
return weight for signal at receiver i
Definition: stfinvbase.h:303
void fftinput()
copy input signals to workspace and transform input workspace to Fourier domain
Tfftengine::TAspectrum TAspectrum
type of array for Fourier transforms
suport debugging in libstfinv (prototypes)
Root namespace of library.
Definition: doxygen.txt:43
TAspectrum recordingcoeff(const unsigned int &i) const
return reference to Fourier coeffients of recorded data for frequency i
TAspectrum::Tvalue & stfcoeff(const unsigned int &i) const
return reference to Fourier coefficients of stf for frequency i
std::string parameter(const std::string &key, const std::string &defvalue="false") const
return the value of a parameters
Definition: stfinvbase.cc:279
double Mwaterlevel
waterlevel
static void classhelp(std::ostream &os=std::cout)
print online help
virtual void exec()
Start engine.
#define STFINV_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:140
int Mdebug
debug level
Definition: stfinvbase.h:336
a Fourier domain engine which finds a normalizing source wavelet (prototypes)
#define STFINV_illegal
Abort if function is called illegally.
Definition: error.h:154
void initialize()
initialize work space
unsigned int nfreq() const
return number of frequencies in use
virtual const char * name() const
return name of engine
static const char *const description
short description of this engine
TAspectrum syntheticcoeff(const unsigned int &i) const
return reference to Fourier coefficients of synthetics for frequency i
void fftoutput()
convolve synthetics with Fourier transform of stf and transform convolved synthetics and stf to time ...
static const char *const ID
ID used to select thsi engine.
#define STFINV_debug(C, N, M)
produce debug output
Definition: debug.h:49
aff::Series< Tvalue > Tseries
Type of sample values.
Definition: stfinvbase.h:56
aff::Series< double > weights() const
return weights array
Definition: stfinvbase.h:306
virtual void help(std::ostream &os=std::cout) const
print online help