STFINV library: seek source wavelet correction filter
stfinvfdleastsquares.cc
Go to the documentation of this file.
1 
37 #define STFINV_STFINVFDLEASTSQUARES_CC_VERSION \
38  "STFINV_STFINVFDLEASTSQUARES_CC V1.2"
39 
40 #include <iostream>
41 #include <aff/functions/sqrsum.h>
45 #include <stfinv/debug.h>
46 #include <stfinv/tools.h>
47 
48 namespace stfinv {
49 
50  const char* const STFEngineFDLeastSquares::ID="fdlsq";
51 
52  const char* const STFEngineFDLeastSquares::description
53  ="least squares in the frequency domain";
54 
55  /*----------------------------------------------------------------------*/
56 
57  void STFEngineFDLeastSquares::help(std::ostream& os) const
58  {
60  } // void STFEngineFDLeastSquares::help(std::ostream& os) const
61 
62  /*----------------------------------------------------------------------*/
63 
64  void STFEngineFDLeastSquares::usage(std::ostream& os) const
65  {
67  } // void STFEngineFDLeastSquares::usage(std::ostream& os) const
68 
69  /*----------------------------------------------------------------------*/
70 
71  const char* STFEngineFDLeastSquares::name() const
72  {
73  return("STFEngineFDLeastSquares");
74  } // const char const* STFEngineFDLeastSquares::name() const
75 
76  /*----------------------------------------------------------------------*/
77 
79  {
80  // scale energy
81  std::istringstream is (this->parameter("waterlevel","1.e-3"));
82  is >> Mwaterlevel;
83  STFINV_debug(Mdebug&1, "STFEngineFDLeastSquares::initialize()",
84  "Mwaterlevel=" << Mwaterlevel);
86  "ERROR: parameter for option \"waterlevel\" not larger than 0");
87  } // void STFEngineFDLeastSquares::initialize()
88 
89  /*----------------------------------------------------------------------*/
90 
91  void STFEngineFDLeastSquares::classhelp(std::ostream& os)
92  {
94  os << std::endl;
95  stfinv::tools::report_engine_ID<STFEngineFDLeastSquares>(os);
96  } // void STFEngineFDLeastSquares::classhelp(std::ostream& os)
97 
98  /*----------------------------------------------------------------------*/
99 
100  void STFEngineFDLeastSquares::classusage(std::ostream& os)
101  {
103  os << std::endl;
104  Tbase::classusage(os);
105  os << std::endl;
106  stfinv::tools::report_engine_ID<STFEngineFDLeastSquares>(os);
107  } // void STFEngineFDLeastSquares::classusage(std::ostream& os)
108 
109  /*----------------------------------------------------------------------*/
110 
112  {
113  // read signals and calculate FFT
114  this->fftinput();
115 
116  // calculate waterlevel
117  double waterlevel=0.;
118  for (unsigned int i=0; i<this->nreceivers(); ++i)
119  {
120  waterlevel += this->weight(i)*this->weight(i)
121  *aff::func::sqrsum(this->synthetic(i));
122  } // for (unsigned int i=0; i<this->nreceivers(); ++i)
123  waterlevel *= Mwaterlevel;
124 
125  STFINV_debug(Mdebug&2, "STFEngineFDLeastSquares::exec()",
126  "waterlevel=" << waterlevel);
127 
128  STFINV_debug(Mdebug&2, "STFEngineFDLeastSquares::exec()",
129  "nfreq=" << this->nfreq());
130  // cycle through frequencies
131  for (unsigned int i=0; i<this->nfreq(); ++i)
132  {
133  STFINV_debug(Mdebug&4, "STFEngineFDLeastSquares::exec()",
134  "frequency=" << i);
135  TAspectrum syntheticref=this->syntheticcoeff(i);
136  TAspectrum recordingref=this->recordingcoeff(i);
137  STFINV_debug(Mdebug&4, "STFEngineFDLeastSquares::exec()",
138  "syntheticref.first(0)=" << syntheticref.first(0) << " " <<
139  "syntheticref.last(0)=" << syntheticref.last(0) << " "
140  "syntheticref.first(1)=" << syntheticref.first(1) << " " <<
141  "syntheticref.last(1)=" << syntheticref.last(1) << " ");
142  TAspectrum::Tvalue numerator, denominator;
143  denominator=waterlevel;
144  numerator=0.;
145  for (unsigned int j=0; j<this->nreceivers(); ++j)
146  {
147  numerator += this->weight(j)*this->weight(j)
148  *conj(syntheticref(j))*recordingref(j);
149  denominator += this->weight(j)*this->weight(j)
150  *conj(syntheticref(j))*syntheticref(j);
151  }
152  this->stfcoeff(i)=numerator/denominator;
153  } // for (unsigned int i=0; i<this->nfreq(); ++i)
154 
155  // provide results to user
156  this->fftoutput();
157  } // void STFEngineFDLeastSquares::exec()
158 
159 } // namespace stfinv
160 
161 /* ----- END OF stfinvfdleastsquares.cc ----- */
char stfinvfdleastsquares_summary_usage[]
unsigned int nreceivers() const
return number of receiver signals in use
Definition: stfinvbase.h:259
float Tvalue
Value type of samples.All references to time series samples in user workspace are based on this type...
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
virtual void exec()
Start engine.
#define STFINV_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:140
least squares in the frequency domain (prototypes)
int Mdebug
debug level
Definition: stfinvbase.h:336
Tseries::Tcoc synthetic(const unsigned int &i) const
return synthetic data at receiver i
Definition: stfinvbase.cc:311
virtual void usage(std::ostream &os=std::cout) const
print detailed description
static const char *const ID
ID used to select this engine.
virtual void help(std::ostream &os=std::cout) const
print online help
static void classusage(std::ostream &os=std::cout)
print detailed description
char stfinvfdleastsquares_description_usage[]
unsigned int nfreq() const
return number of frequencies in use
tools and utilities (prototypes)
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 ...
virtual const char * name() const
return name of engine
static void classhelp(std::ostream &os=std::cout)
print online help
void initialize()
initialize work space
#define STFINV_debug(C, N, M)
produce debug output
Definition: debug.h:49
static const char *const description
short description of this engine
static void classusage(std::ostream &os=std::cout)
print detailed description