00001 #include <fstream>
00002 #include <iostream>
00003 #include <vector>
00004 #include <string>
00005 #include <algorithm>
00006 #include "LMSCanceller.h"
00007 #include "RLSCanceller.h"
00008 #include "ApplyFilter.h"
00009 #include "TimeSeriesComponent.h"
00010 using namespace std;
00011
00012 int main()
00013 {
00014 ofstream weightfile;
00015
00016
00017 const int filterlength = 2;
00018 const double mu = 0.1;
00019 const int nsamples = 500;
00020 const double period = 5.2;
00021 const double PI = acos(-1.0);
00022 LMSCanceller Filter(filterlength);
00023 Filter.SetMu(mu);
00024
00025 ApplyFilter Canceller(Filter);
00026
00027 TimeSeriesComponent reference, input;
00028
00029 for (int i = 0; i < nsamples; ++i)
00030 {
00031 reference.GetData().push_back(2.0*cos( 2.0 * PI * i/period));
00032 input.GetData().push_back(sin( 2.0 * PI * i/period));
00033 }
00034
00035 Canceller.AddReferenceChannel(reference);
00036 Canceller.AddInputChannel(input);
00037 Canceller.SetShift(0);
00038 Canceller.FilterData();
00039
00040
00041
00042
00043 ofstream cleanfile("test.clean");
00044 copy(Canceller.GetOutChannels().front()->GetData().begin(),Canceller.GetOutChannels().front()->GetData().end(),ostream_iterator<double>(cleanfile,"\n"));
00045
00046
00047 ofstream epsfile("test.eps");
00048 copy(Canceller.GetEpsValues().front().begin(),Canceller.GetEpsValues().front().end(),ostream_iterator<double>(epsfile,"\n"));
00049
00050 cout << "Last Weights: " << endl;
00051 Filter.PrintWeights(cout);
00052 cout << endl;
00053 cout << "Optimum: " << endl;
00054 cout << 2 * 1./tan(2*PI/period) << " " << - 2 * 1./sin(2*PI/period) << endl;
00055 cout << endl;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 }