MtuDespike.cpp
Go to the documentation of this file.00001 #include "MtuFormat.h"
00002 #include "CDespike.h"
00003 #include "CSpikeStats.h"
00004 #include <iostream>
00005 #include <iomanip>
00006 #include <fstream>
00007 #include <string>
00008 #include <sstream>
00009 #include <algorithm>
00010
00011 const double filterfraction=0.05;
00012 const int sectionlength = 4800;
00013 const int spikelength = 50;
00014 const int trailpoints = 10;
00015 const int nValueBins = 1000;
00016 const int nDerivBins = 1000;
00017 const int MinEstimates = 2;
00018 const int iterations = 1;
00019
00020
00021 using namespace std;
00022
00023
00024 void CleanComponent(TimeSeriesComponent &CurrentComponent, CDespike &Despiker,
00025 CSpikeStats &SpikeStats, ttsdata &NoiseTs)
00026 {
00027 titdata sectionstart;
00028 int estimates = 0;
00029 int insertpoints = 0;
00030 titdata spikestart;
00031
00032 SpikeStats.Data = &(CurrentComponent.GetData());
00033 SpikeStats.AnalyseSpikes();
00034 Despiker.HeightThreshold = SpikeStats.HeightThreshold;
00035 Despiker.Data = &(CurrentComponent.GetData());
00036 for (sectionstart = CurrentComponent.GetData().begin();
00037 (sectionstart + sectionlength) < CurrentComponent.GetData().end(); sectionstart+=sectionlength)
00038 {
00039 estimates = Despiker.StackSpikes(sectionstart,sectionstart+sectionlength);
00040 if (estimates > MinEstimates)
00041 {
00042 Despiker.RemoveSpikes(sectionstart,sectionstart+sectionlength);
00043 for (int i = 0; i < estimates; ++i)
00044 {
00045 spikestart = NoiseTs.begin() + Despiker.SpikeIndices.at(i) -trailpoints;
00046 copy(Despiker.SpikeForm.begin(),Despiker.SpikeForm.end(),spikestart);
00047 }
00048 }
00049 }
00050
00051
00052
00053
00054
00055
00056 SpikeStats.Data = NULL;
00057 Despiker.Data = NULL;
00058 }
00059
00060 int main(void)
00061 {
00062 MtuFormat TestData;
00063 CDespike Despiker;
00064 CSpikeStats SpikeStats;
00065 ttsdata ExNoiseTs;
00066 ttsdata EyNoiseTs;
00067 ofstream noisetsfile;
00068 string infilename, outfilename,iteration;
00069
00070
00071 cout << "Inputfile: ";
00072 cin >> infilename;
00073 TestData.GetData(infilename);
00074
00075 cout << "Outputfile: ";
00076 cin >> outfilename;
00077
00078 Despiker.Time = &(TestData.GetTime());
00079 Despiker.samplerate = TestData.GetSamplerate();
00080 Despiker.SpikeLength = spikelength;
00081 Despiker.TrailPoints = trailpoints;
00082 SpikeStats.Time = &(TestData.GetTime());
00083 SpikeStats.nValueBins = nValueBins;
00084 SpikeStats.nDerivBins = nDerivBins;
00085 SpikeStats.samplerate = TestData.GetSamplerate();
00086 SpikeStats.HeightFraction = filterfraction;
00087 ExNoiseTs.assign(TestData.GetEx().GetData().size(),0);
00088 EyNoiseTs.assign(TestData.GetEy().GetData().size(),0);
00089 CleanComponent(TestData.GetEx(),Despiker,SpikeStats,ExNoiseTs);
00090 CleanComponent(TestData.GetEy(),Despiker,SpikeStats,EyNoiseTs);
00091 SpikeStats.WriteStats(infilename + TestData.GetEx().GetName());
00092 Despiker.WriteSpikeForm(infilename + TestData.GetEx().GetName());
00093
00094 cout << "Writing data ..." << flush;
00095 noisetsfile.open((infilename+".noise").c_str());
00096 for (int i = 0; i < ExNoiseTs.size(); ++i)
00097 {
00098 noisetsfile << setw(10) << ExNoiseTs.at(i) << " " << EyNoiseTs.at(i) << endl;
00099 }
00100 noisetsfile.close();
00101 TestData.WriteData(outfilename);
00102 SpikeStats.Time = NULL;
00103 Despiker.Time = NULL;
00104
00105 cout << " done" << endl;
00106 }