15 #include <boost/random/lagged_fibonacci.hpp>
16 #include <boost/random/normal_distribution.hpp>
17 #include <boost/random/variate_generator.hpp>
20 using namespace gplib;
22 string version =
"$Id: addnoise.cpp 1844 2010-04-12 11:34:25Z mmoorkamp $";
24 void AddNoise(std::complex<double> &impelement,
double &noiseest,
25 const double relativenoiselevel,
const double absolutenoiselevel,
26 boost::lagged_fibonacci607 &generator)
29 complex<double> oldimp(impelement);
31 double realnoiselevel = max(std::abs(impelement.real() * relativenoiselevel),
34 double imagnoiselevel = max(std::abs(impelement.imag() * relativenoiselevel),
37 impelement = boost::variate_generator<boost::lagged_fibonacci607&,
38 boost::normal_distribution<> >(generator, boost::normal_distribution<>(
39 impelement.real(), realnoiselevel))();
41 impelement += complex<double> (0.0, 1.0)
42 * boost::variate_generator<boost::lagged_fibonacci607&,
43 boost::normal_distribution<> >(generator, boost::normal_distribution<>(
44 oldimp.imag(), imagnoiselevel))();
46 noiseest = max(relativenoiselevel * abs(oldimp), absolutenoiselevel);
49 int main(
int argc,
char *argv[])
51 string infilename, outfilename;
52 double relativenoiselevel, absolutenoiselevel;
54 boost::lagged_fibonacci607 generator(
55 static_cast<unsigned int> (std::time(0)));
56 complex<double> I(0.0, 1.0);
57 cout <<
"This is addnoise: Add random noise to MT impedance estimates."
59 cout <<
" Usage: addnoise infilename noiselevel" << endl;
61 <<
" The output files will have the same name as the input files + .ns "
63 cout <<
" This is Version: " <<
version << endl << endl;
67 outfilename = argv[2];
68 relativenoiselevel = atof(argv[3]);
69 absolutenoiselevel = atof(argv[4]);
74 infilename = AskFilename(
"Infilename: ");
75 cout <<
"Relative Noiselevel:";
76 cin >> relativenoiselevel;
77 cout <<
"Absolute noiselevel:";
78 cin >> absolutenoiselevel;
79 outfilename = infilename +
".ns";
83 double zxxerr, zxyerr, zyxerr, zyyerr;
84 for (
unsigned int i = 0; i < Data.
GetMTData().size(); ++i)
87 absolutenoiselevel, generator);
89 absolutenoiselevel, generator);
91 absolutenoiselevel, generator);
93 absolutenoiselevel, generator);
94 Data.
SetMTData().at(i).SetErrors(zxxerr, zxyerr, zyxerr, zyyerr);
virtual void GetData(const std::string filename)
read in data from file, determines format by ending
int main(int argc, char *argv[])
The class MTStation is used to store the transfer functions and related information for a MT-site...
void WriteAsMtt(const std::string filename)
Write data in goettingen .mtt format.
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
std::vector< MTTensor > & SetMTData()
Get the full vector of Tensor elements for reading and writing.
void AddNoise(std::complex< double > &impelement, double &noiseest, const double relativenoiselevel, const double absolutenoiselevel, boost::lagged_fibonacci607 &generator)