6 #include <boost/random/lagged_fibonacci.hpp>
7 #include <boost/random/normal_distribution.hpp>
8 #include <boost/random/variate_generator.hpp>
9 #include <boost/bind.hpp>
12 using namespace gplib;
21 int main(
int argc,
char* argv[])
24 string datafilename, outfilename;
25 double relnoise, absnoise;
27 string version =
"$Id: seisnoise.cpp 1882 2014-06-12 08:15:20Z mmoorkamp $";
29 cout <<
"Program " << version << endl;
30 cout <<
" Add random noise to a seismogram" << endl;
31 cout <<
" Input is a single component file, output a sac file with added noise"
34 <<
" The noise level is specified relative to the maximum amplitude and as a minimum absolute value."
39 datafilename = argv[1];
40 outfilename = argv[2];
41 relnoise = atof(argv[3]);
42 absnoise = atof(argv[4]);
46 datafilename = AskFilename(
"Input filename: ");
47 outfilename = AskFilename(
"Output filename: ");
48 cout <<
"Relative Noise level: ";
50 cout <<
"Absolute Noise level: ";
54 const double maxelem = *max_element(Data.
GetData().begin(), Data.
GetData().end());
55 boost::lagged_fibonacci607 generator(static_cast<unsigned int>(std::time(0)));
56 boost::normal_distribution<> noise_dist(0.0, std::max(relnoise * maxelem, absnoise));
57 boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > noise(
58 generator, noise_dist);
62 boost::bind(plus<double>(), _1, boost::bind(noise)));
int ReadData(const std::string &filename, tseismicdataformat format=sac)
Read in data from a file, as we cannot determine the type from the ending we have to provide it...
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
int main(int argc, char *argv[])
int WriteAsSac(const std::string &filename) const
Write the data in sac binary format.