simplenoisecancel.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <vector>
00003 #include <fstream>
00004 #include "RLSCanceller.h"
00005 #include "LMSCanceller.h"
00006
00007 using namespace std;
00008 using namespace gplib;
00009
00010 int main()
00011 {
00012 const int filterlength = 100;
00013 const double mu = 1e-14;
00014 const double secfactor = 5;
00015 const int shift = filterlength / 4;
00016
00017 vector<double> input, desired;
00018
00019 string inputfilename, reffilename, outputfilename;
00020 ifstream inputfile, reffile;
00021 ofstream outfile, weightfile, epsfile;
00022 double currentnumber;
00023
00024 cout << "Inputfile: ";
00025 cin >> inputfilename;
00026 cout << "Reference Filename: ";
00027 cin >> reffilename;
00028
00029 inputfile.open(inputfilename.c_str());
00030 reffile.open(reffilename.c_str());
00031 outfile.open((reffilename + ".clean").c_str());
00032 weightfile.open((reffilename + ".weight").c_str());
00033 epsfile.open((reffilename + ".eps").c_str());
00034 while (inputfile.good())
00035 {
00036 inputfile >> currentnumber;
00037 input.push_back(currentnumber);
00038 }
00039
00040 while (reffile.good())
00041 {
00042 reffile >> currentnumber;
00043 desired.push_back(currentnumber);
00044 }
00045 inputfile.close();
00046 reffile.close();
00047 vector<double> output(input.size()), epsilon(input.size());
00048 LMSCanceller Canceller(filterlength);
00049 Canceller.SetMu(mu);
00050
00051 gplib::rvec currentinput(filterlength), currdesired(1), currout(1);
00052 copy(input.begin(), input.begin() + filterlength, currentinput.begin());
00053
00054
00055
00056
00057
00058
00059
00060 for (int i = 0; i < input.size() - filterlength - 1; ++i)
00061 {
00062 Canceller.CalcOutput(currentinput, currout);
00063 Canceller.PrintWeights(weightfile);
00064 currdesired(0) = desired.at(i + shift);
00065
00066
00067 Canceller.AdaptFilter(currentinput, currdesired);
00068 output.at(i + filterlength - 1) = currout(0);
00069 epsilon.at(i + filterlength - 1) = Canceller.GetEpsilon()(0);
00070 rotate(currentinput.begin(), currentinput.begin() + 1,
00071 currentinput.end());
00072 currentinput(filterlength - 1) = input.at(i + filterlength);
00073 }
00074
00075 for (int i = shift; i < output.size(); ++i)
00076 outfile << output.at(i) << endl;
00077 for (int i = shift; i < epsilon.size(); ++i)
00078 epsfile << epsilon.at(i) << endl;
00079
00080
00081 outfile.close();
00082 weightfile.close();
00083 epsfile.close();
00084 }