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

Generated on Wed Jul 23 16:35:58 2008 for GPLIB++ by  doxygen 1.5.5