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,
39 boost::normal_distribution<>(impelement.real(), realnoiselevel))();
41 impelement += complex<double>(0.0, 1.0)
42 * boost::variate_generator<boost::lagged_fibonacci607&,
43 boost::normal_distribution<> >(generator,
44 boost::normal_distribution<>(oldimp.imag(), imagnoiselevel))();
46 noiseest = max(relativenoiselevel * abs(oldimp), absolutenoiselevel);
49 int main(
int argc,
char *argv[])
51 string infilename, outfilename;
53 boost::lagged_fibonacci607 generator(static_cast<unsigned int>(std::time(0)));
55 cout <<
"This is addnoise: Add random noise to MT impedance estimates." << endl
57 cout <<
" Usage: addnoise infilename noiselevel" << endl;
58 cout <<
" The output files will have the same name as the input files + .ns " << endl
60 cout <<
" This is Version: " <<
version << endl << endl;
62 infilename = AskFilename(
"Infilename: ");
64 cout <<
"Minimum period:";
67 cout <<
"Shiftfactor:";
69 outfilename = infilename +
".rhons";
72 for (
unsigned int i = 0; i < Data.
GetMTData().size(); ++i)
76 Data.
SetMTData().at(i).SetZxx() *= shiftfactor;
77 Data.
SetMTData().at(i).SetZxy() *= shiftfactor;
78 Data.
SetMTData().at(i).SetZyx() *= shiftfactor;
79 Data.
SetMTData().at(i).SetZyy() *= shiftfactor;
84 outfilename = infilename +
".phins";
85 for (
unsigned int i = 0; i < Data.
GetMTData().size(); ++i)
89 dcomp Zxx = Data.
SetMTData().at(i).SetZxx();
90 dcomp Zxy = Data.
SetMTData().at(i).SetZxy();
91 dcomp Zyx = Data.
SetMTData().at(i).SetZyx();
92 dcomp Zyy = Data.
SetMTData().at(i).SetZyy();
93 Data.
SetMTData().at(i).SetZxx() = abs(Zxx)
94 * dcomp(cos(shiftfactor), sin(shiftfactor));
95 Data.
SetMTData().at(i).SetZxy() = abs(Zxy)
96 * dcomp(cos(shiftfactor), sin(shiftfactor));
97 Data.
SetMTData().at(i).SetZyx() = abs(Zyx)
98 * dcomp(cos(shiftfactor), sin(shiftfactor));
99 Data.
SetMTData().at(i).SetZyy() = abs(Zyy)
100 * dcomp(cos(shiftfactor), sin(shiftfactor));
int main(int argc, char *argv[])
virtual void GetData(const std::string filename)
read in data from file, determines format by ending
void AddNoise(std::complex< double > &impelement, double &noiseest, const double relativenoiselevel, const double absolutenoiselevel, boost::lagged_fibonacci607 &generator)
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.
trealdata GetFrequencies() const
return the available frequencies in a single vector