12 const int filterlength = 100;
13 const double mu = 1e-14;
14 const double secfactor = 5;
15 const int shift = filterlength / 4;
17 vector<double> input, desired;
19 string inputfilename, reffilename, outputfilename;
20 ifstream inputfile, reffile;
21 ofstream outfile, weightfile, epsfile;
24 cout <<
"Inputfile: ";
26 cout <<
"Reference Filename: ";
29 inputfile.open(inputfilename.c_str());
30 reffile.open(reffilename.c_str());
31 outfile.open((reffilename +
".clean").c_str());
32 weightfile.open((reffilename +
".weight").c_str());
33 epsfile.open((reffilename +
".eps").c_str());
34 while (inputfile.good())
36 inputfile >> currentnumber;
37 input.push_back(currentnumber);
40 while (reffile.good())
42 reffile >> currentnumber;
43 desired.push_back(currentnumber);
47 vector<double> output(input.size()), epsilon(input.size());
51 gplib::rvec currentinput(filterlength), currdesired(1), currout(1);
52 copy(input.begin(), input.begin() + filterlength, currentinput.begin());
60 for (
int i = 0; i < input.size() - filterlength - 1; ++i)
62 Canceller.CalcOutput(currentinput, currout);
63 Canceller.PrintWeights(weightfile);
64 currdesired(0) = desired.at(i + shift);
67 Canceller.AdaptFilter(currentinput, currdesired);
68 output.at(i + filterlength - 1) = currout(0);
69 epsilon.at(i + filterlength - 1) = Canceller.GetEpsilon()(0);
70 rotate(currentinput.begin(), currentinput.begin() + 1,
72 currentinput(filterlength - 1) = input.at(i + filterlength);
75 for (
int i = shift; i < output.size(); ++i)
76 outfile << output.at(i) << endl;
77 for (
int i = shift; i < epsilon.size(); ++i)
78 epsfile << epsilon.at(i) << endl;
Implements a LMS adaptive filter.