00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 #include <complex>
00011 #include <ctime>
00012 #include "MTStation.h"
00013 #include "Util.h"
00014 #include <boost/random/lagged_fibonacci.hpp>
00015 #include <boost/random/normal_distribution.hpp>
00016 #include <boost/random/variate_generator.hpp>
00017
00018 using namespace std;
00019
00020
00021 string version = "$Id: addnoise.cpp 1706 2008-06-06 07:14:04Z mmoorkamp $";
00022
00023 void AddNoise(std::complex<double> &impelement, double &noiseest,
00024 const double noiselevel, boost::lagged_fibonacci607 &generator) {
00025 complex<double> oldimp(impelement);
00026 impelement = boost::variate_generator<boost::lagged_fibonacci607&,
00027 boost::normal_distribution<> >(generator,
00028 boost::normal_distribution<>(impelement.real(),
00029 fabs(impelement.real()* noiselevel)))();
00030 impelement += complex<double>(0.0,1.0)*boost::variate_generator<boost::lagged_fibonacci607&,
00031 boost::normal_distribution<> >(generator,
00032 boost::normal_distribution<>(oldimp.imag(),
00033 fabs(oldimp.imag()* noiselevel)))();
00034 noiseest = noiselevel * abs(oldimp);
00035 }
00036
00037 int main(int argc, char *argv[]) {
00038 string infilename, outfilename;
00039 double noiselevel;
00040 MTStation Data;
00041 boost::lagged_fibonacci607
00042 generator(static_cast<unsigned int>(std::time(0)));
00043 complex<double> I(0.0, 1.0);
00044 cout << "This is addnoise: Add random noise to MT impedance estimates."
00045 << endl<< endl;
00046 cout << " Usage: addnoise infilename noiselevel" << endl;
00047 cout
00048 << " The output files will have the same name as the input files + .ns "
00049 << endl << endl;
00050 cout << " This is Version: " << version << endl << endl;
00051 if (argc > 3) {
00052 infilename = argv[1];
00053 outfilename = argv[2];
00054 noiselevel = atof(argv[3]);
00055 }
00056
00057 if (argc == 3) {
00058 infilename = argv[1];
00059
00060 noiselevel = atof(argv[2]);
00061 } else {
00062
00063 infilename = AskFilename("Infilename: ");
00064 cout << "Noiselevel:";
00065 cin >> noiselevel;
00066 outfilename = infilename + ".ns";
00067 }
00068
00069 Data.GetData(infilename);
00070 double zxxerr, zxyerr, zyxerr, zyyerr;
00071 for (unsigned int i = 0; i < Data.GetMTData().size(); ++i) {
00072 AddNoise(Data.SetMTData().at(i).SetZxx(), zxxerr, noiselevel, generator);
00073 AddNoise(Data.SetMTData().at(i).SetZxy(), zxyerr, noiselevel, generator);
00074 AddNoise(Data.SetMTData().at(i).SetZyx(), zyxerr, noiselevel, generator);
00075 AddNoise(Data.SetMTData().at(i).SetZyy(), zyyerr, noiselevel, generator);
00076 Data.SetMTData().at(i).SetErrors(zxxerr, zxyerr, zyxerr, zyyerr);
00077 }
00078 Data.WriteAsMtt(outfilename);
00079 }