10 #include <boost/bind.hpp>
13 using namespace gplib;
15 string version =
"$Id: DelayFilter.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
20 transform(Original.begin(), Original.end() - shiftsteps, Shifted.begin()
21 + shiftsteps, Original.begin(), minus<double> ());
22 const double factor = 1. / sqrt(2.);
23 transform(Original.begin(), Original.end(), Original.begin(), boost::bind(
24 multiplies<double> (), _1, factor));
29 const int blocklength = 2400;
30 const int nsegments = ts.size() / blocklength;
31 const double threshold = 1e4;
34 vector<double>::const_iterator currstart(ts.begin()), currend(ts.begin()
36 vector<double> differences(blocklength, 0.0);
37 for (
int i = 0; i < nsegments; ++i)
39 adjacent_difference(currstart, currend, differences.begin());
40 vector<double>::iterator firstspike = find_if(differences.begin(),
41 differences.end(), boost::bind(greater<double> (), boost::bind(
42 (
double(*)(
double)) &abs, _1), threshold));
43 vector<double>::iterator nextspike = firstspike;
44 while (nextspike != differences.end())
46 nextspike = find_if(firstspike + 1, differences.end(), boost::bind(
47 greater<double> (), boost::bind((
double(*)(
double)) &abs, _1),
49 if (nextspike != currend)
51 spikedist += distance(firstspike, nextspike);
54 firstspike = nextspike;
56 currstart += blocklength;
57 currend += blocklength;
59 cout <<
"Spike count: " << spikecount <<
" Avg. Dist: " << spikedist
67 string infilename, outfilename, search;
70 int startindex, endindex, maxindex = 0;
71 const double searchstart = 0.2;
72 const double searchend = 1.0;
76 cout <<
"This is dfilter: Apply a delay filter to MT time series file"
78 cout <<
"At this point no command line parameters, only interactive."
80 cout <<
"This is Version: " <<
version << endl << endl;
82 cout <<
"Input Filename: ";
84 OriginalData.
GetData(infilename);
85 cout <<
"Output Filename: ";
87 cout <<
" Enter 'a' for automatic, or number of points to shift: ";
92 vector<complex<double> > ExSpectrum(seglength / 2 + 1);
94 cout <<
"Performing search" << endl;
100 startindex = round(searchstart / freqstep);
101 endindex = round(searchend / freqstep);
102 for (
int i = startindex; i < endindex; ++i)
104 if (abs(ExSpectrum.at(i)) > absmax)
107 absmax = abs(ExSpectrum.at(i));
112 cout <<
"Spike frequency: " << maxindex * freqstep <<
" Height: "
117 istringstream convStream(search);
118 convStream >> shiftsteps;
123 cout <<
"Shifted by: " << shiftsteps <<
" exact: "
126 ShiftedData = OriginalData;
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
void SubShiftedComponent(vector< double > &Original, vector< double > &Shifted, const int shiftsteps)
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
TimeSeriesComponent & GetEx()
double GetSamplerate()
The samplerate is stored in each component, we just return the samplerate of Hx assuming they are all...
TimeSeriesComponent & GetHy()
void WriteAsMtu(std::string filename_base)
Write data to file in Phoenix MTU format.
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
void FindSpikeDistances(const vector< double > &ts)
This functor returns the weighting factor for the Hanning window, given the relative position (0...
TimeSeriesComponent & GetEy()
TimeSeriesComponent & GetHz()
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.