simplenoisecancel.cc File Reference

#include <iostream>
#include <vector>
#include <fstream>
#include "RLSCanceller.h"
#include "LMSCanceller.h"

Include dependency graph for simplenoisecancel.cc:

Go to the source code of this file.

Functions

int main ()


Function Documentation

int main ( void   ) 

Definition at line 9 of file simplenoisecancel.cc.

00010 {
00011         const int filterlength = 100; // set the length of the filter
00012         const double mu = 1e-14; // the stepsize for adaptation
00013         const double secfactor = 5; // the factor between the value calculated and the value used
00014         const int shift= filterlength/4; // the shift in index between the first point in the segment and the value used as reference
00015         
00016         vector<double> input, desired;//declare vectors that hold the input data, the reference data
00017         // the filter output and the difference to the original time series
00018         string inputfilename, reffilename, outputfilename; // the names of the input and output files
00019         ifstream inputfile, reffile; // the file objects for reading
00020         ofstream outfile, weightfile,epsfile; // and writingy
00021         double currentnumber; // we have to read in a bunch of numbers and use this a temporary storage
00022         
00023         cout << "Inputfile: "; 
00024         cin >> inputfilename; // read in inputfilename 
00025         cout << "Reference Filename: ";
00026         cin >> reffilename; // and reference filename
00027         
00028         inputfile.open(inputfilename.c_str()); //open inputfile stream for reading
00029         reffile.open(reffilename.c_str()); // same for reference file stream
00030         outfile.open((reffilename+".clean").c_str()); //open outputfile with an automatically generated name
00031         weightfile.open((reffilename+".weight").c_str());
00032         epsfile.open((reffilename+".eps").c_str());
00033         while (inputfile.good()) // while no errors occur
00034         {
00035                 inputfile >> currentnumber; // read in a number from the input file
00036                 input.push_back(currentnumber); // add it to the end of the input vector
00037         }
00038         
00039         while (reffile.good()) // while no errors occur
00040         {
00041                 reffile >> currentnumber; // read in a number from the reference file
00042                 desired.push_back(currentnumber);// add it to the end of the reference vector
00043         }
00044         inputfile.close(); //close both files
00045         reffile.close();
00046         vector<double> output(input.size()), epsilon(input.size()); 
00047         LMSCanceller Canceller(filterlength); // declare a new object of type LMSCanceller
00048         Canceller.SetMu(mu);
00049         
00050         gplib::rvec currentinput(filterlength), currdesired(1), currout(1);
00051         copy(input.begin(),input.begin()+filterlength,currentinput.begin());
00052         //for (int i = filterlength-1; i >= 0; --i)
00053         //      currentinput(i) = input[filterlength-1-i];
00054                 //currdesired(0) = desired.at(filterlength/2); 
00055                  
00056                 //Canceller.CalcOutput(currentinput,currout);
00057             //output.at(0) = currout(0);
00058             //epsilon.at(0) = Canceller.GetEpsilon()(0);
00059         for (int i = 0; i < input.size()-filterlength-1; ++i)
00060         {
00061                 Canceller.CalcOutput(currentinput,currout);
00062                 Canceller.PrintWeights(weightfile);
00063                 currdesired(0) = desired.at(i+shift);
00064                         // Canceller.GetFilterOutput().front();
00065                 
00066                 Canceller.AdaptFilter(currentinput,currdesired);
00067                 output.at(i+filterlength-1) = currout(0);
00068                 epsilon.at(i+filterlength-1) = Canceller.GetEpsilon()(0);
00069                 rotate(currentinput.begin(),currentinput.begin()+1,currentinput.end());
00070                 currentinput(filterlength-1) = input.at(i+filterlength);
00071         }
00072         
00073         for (int i = shift; i < output.size(); ++i) //output the output data
00074                 outfile << output.at(i) << endl; //to outputfile
00075         for (int i = shift; i < epsilon.size(); ++i) //output the difference data
00076                 epsfile << epsilon.at(i) << endl; //to difference file
00077         //for (int i = 0; i < Canceller.Weights.size(); ++i)
00078         //      weightfile << Canceller.Weights.at(i) << endl;
00079         outfile.close(); // close file
00080         weightfile.close();
00081         epsfile.close();
00082 }


Generated on Thu Nov 22 14:04:39 2007 for GPLIB++ by  doxygen 1.5.1