00001 #include <fstream>
00002 #include <iostream>
00003 #include <vector>
00004 #include <string>
00005 #include <algorithm>
00006 #include "AMRLSCanceller.h"
00007 #include "ApplyFilter.h"
00008 #include "TimeSeriesComponent.h"
00009 #include "UniformRNG.h"
00010 using namespace std;
00011
00012 int main()
00013 {
00014 ofstream weightfile;
00015
00016
00017 const int filterlength = 5;
00018 const double lambda = 0.9999;
00019 const double delta = 1.1;
00020 const double alpha = 0.001;
00021 const int nsamples = 2000;
00022 const double period = 35.2;
00023 const double PI = acos(-1.0);
00024 const double noiselevel = 0.5;
00025 const int shift = 3;
00026 AMRLSCanceller Filter(filterlength,delta,lambda,alpha);
00027 UniformRNG Random;
00028
00029 ApplyFilter Canceller(Filter);
00030
00031 TimeSeriesComponent reference, input;
00032
00033 for (int i = 0; i < nsamples; ++i)
00034 {
00035 reference.GetData().push_back(2.0*cos( 2.0 * PI * i/period)+Random.GetNumber(-noiselevel,noiselevel));
00036 input.GetData().push_back(sin( 2.0 * PI * i/period));
00037 }
00038
00039 Canceller.AddReferenceChannel(reference);
00040 Canceller.AddInputChannel(input);
00041 Canceller.SetShift(shift);
00042 cout << "Initial Lambda: " << lambda << endl;
00043 Canceller.FilterData();
00044 cout << "Final Lambda: " << Filter.GetLambda() << endl;
00045
00046
00047 ofstream cleanfile("test.clean");
00048 for (int i = 0; i < nsamples - filterlength-shift; ++i)
00049 cleanfile << i << " " << Canceller.GetOutChannels().front()->GetData().at(i) << " " << reference.GetData().at(i) << " "
00050 << 2.0*cos( 2.0 * PI * i/period) << endl;
00051
00052 ofstream difffile("test.diff");
00053 for (int i = 0; i < nsamples - filterlength-shift; ++i)
00054 difffile << i << " " << Canceller.GetOutChannels().front()->GetData().at(i) -2.0*cos( 2.0 * PI * i/period)
00055 << " " << reference.GetData().at(i) - 2.0*cos( 2.0 * PI * i/period) << endl;
00056 ofstream epsfile("test.eps");
00057 copy(Canceller.GetEpsValues().front().begin(),Canceller.GetEpsValues().front().end(),ostream_iterator<double>(epsfile,"\n"));
00058
00059 cout << "Last Weights: " << endl;
00060 Filter.PrintWeights(cout);
00061 cout << endl;
00062
00063 }