mtubandpass.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <string>
00004 #include <numeric>
00005 #include "Util.h"
00006 #include "TimeSeriesData.h"
00007 #include "statutils.h"
00008 #include "FilterFunc.h"
00009 
00010 using namespace std;
00011 using namespace gplib;
00012 
00013 string version = "$Id: mtubandpass.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
00014 
00015 /*!
00016  * \addtogroup UtilProgs Utility Programs
00017  *@{
00018  * \file
00019  * Apply a band pass filter to each component of the MT time series. The program
00020  * asks for the corner frequencies in Hz and the number of passes for the filter.
00021  * The output filename is determined by appending .fil to the input filename.
00022  */
00023 
00024 int main(int argc, char *argv[])
00025   {
00026     string infilename;
00027     cout << "This is mtufilter: Apply a band pass filter to MT time series"
00028         << endl << endl;
00029     cout << " Usage:      mtufilter infilename " << endl;
00030     cout << " Ending '.fil'  will be automatically assigned to outfilename"
00031         << endl << endl;
00032     cout << " This is Version: " << version << endl << endl;
00033     if (argc == 2)
00034       {
00035         infilename = argv[1];
00036       }
00037     else
00038       {
00039 
00040         infilename = AskFilename(" Mtu-Filename: ");
00041       }
00042 
00043     TimeSeriesData Data;
00044     Data.GetData(infilename);
00045     // get the lower corner frequency
00046     double lowfreq;
00047     cout << "Lower Corner frequency [Hz]: ";
00048     cin >> lowfreq;
00049 
00050     // get the lower corner frequency
00051     double upfreq;
00052     cout << "Upper Corner frequency [Hz]: ";
00053     cin >> upfreq;
00054 
00055     // calculate the dimensionless corner frequency for the filtering class
00056     const double lowfilfreq = lowfreq * Data.GetData().GetEx().GetSamplerate();
00057     const double upfilfreq = upfreq * Data.GetData().GetEx().GetSamplerate();
00058     // the more passes we do with this filter, the stronger the attenuation
00059     size_t npass = 1;
00060     cout << "Number of passes: ";
00061     cin >> npass;
00062 
00063     // make sure the all components have zero mean
00064     SubMean(Data.GetData().GetEx().GetData().begin(),
00065         Data.GetData().GetEx().GetData().end());
00066     SubMean(Data.GetData().GetEy().GetData().begin(),
00067         Data.GetData().GetEy().GetData().end());
00068     SubMean(Data.GetData().GetHx().GetData().begin(),
00069         Data.GetData().GetHx().GetData().end());
00070     SubMean(Data.GetData().GetHy().GetData().begin(),
00071         Data.GetData().GetHy().GetData().end());
00072     SubMean(Data.GetData().GetHz().GetData().begin(),
00073         Data.GetData().GetHz().GetData().end());
00074 
00075     //we can do several passes of the filter to get strong attenuation of high frequencies
00076     for (size_t i = 0; i < npass; ++i)
00077       {
00078         // apply the filter to one component and store the result in that component
00079         transform(Data.GetData().GetEx().GetData().begin(),
00080             Data.GetData().GetEx().GetData().end(),
00081             Data.GetData().GetEx().GetData().begin(), SimpleBp(lowfilfreq,upfilfreq));
00082         transform(Data.GetData().GetEy().GetData().begin(),
00083             Data.GetData().GetEy().GetData().end(),
00084             Data.GetData().GetEy().GetData().begin(), SimpleBp(lowfilfreq,upfilfreq));
00085         transform(Data.GetData().GetHx().GetData().begin(),
00086             Data.GetData().GetHx().GetData().end(),
00087             Data.GetData().GetHx().GetData().begin(), SimpleBp(lowfilfreq,upfilfreq));
00088         transform(Data.GetData().GetHy().GetData().begin(),
00089             Data.GetData().GetHy().GetData().end(),
00090             Data.GetData().GetHy().GetData().begin(), SimpleBp(lowfilfreq,upfilfreq));
00091         transform(Data.GetData().GetHz().GetData().begin(),
00092             Data.GetData().GetHz().GetData().end(),
00093             Data.GetData().GetHz().GetData().begin(), SimpleBp(lowfilfreq,upfilfreq));
00094       }
00095     // write data in the same format that we read it in
00096     Data.WriteBack(infilename + ".fil");
00097   }
00098 /*@}*/

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8