Signal Processing/perftest.cpp

Go to the documentation of this file.
00001 //testing the performance of the LMS-Canceller to see difference between std::vector and ublas
00002 
00003 #include <iostream>
00004 #include <vector>
00005 #include <fstream>
00006 #include "LMSCanceller.h"
00007 
00008 using namespace std;
00009 
00010 int main()
00011 {
00012         const int iterations = 100; 
00013         const int filterlength = 206; // set the length of the filter
00014         const double mu = 0.5; // the stepsize for adaptation, a negative value indicates automatic calculation
00015         const double secfactor = 5; // the factor between the value calculated and the value used
00016         const int shift=0; // the shift in index between the first point in the segment and the value used as reference
00017         
00018         vector<double> input, desired;//declare vectors that hold the input data, the reference data
00019         // the filter output and the difference to the original time series
00020         string inputfilename, reffilename, outputfilename; // the names of the input and output files
00021         ifstream inputfile, reffile; // the file objects for reading
00022         ofstream outfile, weightfile,epsfile; // and writingy
00023         double currentnumber; // we have to read in a bunch of numbers and use this a temporary storage
00024         
00025         cout << "Inputfile: "; 
00026         cin >> inputfilename; // read in inputfilename 
00027         cout << "Reference Filename: ";
00028         cin >> reffilename; // and reference filename
00029         
00030         inputfile.open(inputfilename.c_str()); //open inputfile stream for reading
00031         reffile.open(reffilename.c_str()); // same for reference file stream
00032         outfile.open((reffilename+".clean").c_str()); //open outputfile with an automatically generated name
00033         weightfile.open((reffilename+".weight").c_str());
00034         epsfile.open((reffilename+".eps").c_str());
00035         while (inputfile.good()) // while no errors occur
00036         {
00037                 inputfile >> currentnumber; // read in a number from the input file
00038                 input.push_back(currentnumber); // add it to the end of the input vector
00039         }
00040         
00041         while (reffile.good()) // while no errors occur
00042         {
00043                 reffile >> currentnumber; // read in a number from the reference file
00044                 desired.push_back(currentnumber);// add it to the end of the reference vector
00045         }
00046         inputfile.close(); //close both files
00047         reffile.close();
00048         vector<double> output(input.size()), epsilon(input.size()); 
00049         LMSCanceller Canceller(filterlength); // declare a new object of type LMSCanceller
00050         Canceller.SetMu(mu);
00051         for (int a = 0; a < iterations; ++a)
00052         {
00053                 gplib::rvec currentinput(filterlength), currdesired(1);
00054                 copy(input.begin(),input.begin()+filterlength,currentinput.begin());
00055                 currdesired(0) = desired.at(filterlength+1); // so far we try to predict
00056                 for (size_t i = 1; i < input.size()-filterlength-1; ++i)
00057                 {
00058                         // needs to be fixed output.at(i+filterlength) = Canceller.CalcOutput(currentinput,currdesired)(0);
00059                         // Canceller.AdaptFilter(currentinput);
00060                         rotate(currentinput.begin(),currentinput.begin()+1,currentinput.end());
00061                         currdesired(0) = desired.at(filterlength+i+1);
00062                         currentinput(filterlength-1) = input.at(i+filterlength);
00063                         // Canceller.GetFilterOutput().front();
00064                         epsilon.at(i+filterlength) = Canceller.GetEpsilon()(0);
00065                 }
00066         }
00067         for (size_t i = shift; i < output.size(); ++i) //output the output data
00068                 outfile << output.at(i) << endl; //to outputfile
00069         for (size_t i = shift; i < epsilon.size(); ++i) //output the difference data
00070                 epsfile << epsilon.at(i) << endl; //to difference file
00071         //for (int i = 0; i < Canceller.Weights.size(); ++i)
00072         //      weightfile << Canceller.Weights.at(i) << endl;
00073         outfile.close(); // close file
00074         weightfile.close();
00075         epsfile.close();
00076 }

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