Signal Processing/testlmscancel.cpp

Go to the documentation of this file.
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         //*RefComp = *Canceller.GetOutChannels().front();
00042         //ReferenceData.WriteAsMtu(noisefilename+".clean");
00043         ofstream cleanfile("test.clean");
00044         copy(Canceller.GetOutChannels().front()->GetData().begin(),Canceller.GetOutChannels().front()->GetData().end(),ostream_iterator<double>(cleanfile,"\n"));
00045         //copy(Canceller.GetEpsValues().front().begin(),Canceller.GetEpsValues().front().end(),RefComp->GetData().begin());
00046         //ReferenceData.WriteAsMtu(noisefilename+".eps");
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         //copy(Canceller.Epsilon->begin(),Canceller.Epsilon->end(),prefcomponent->begin());
00057         //ReferenceData.WriteAsMtu(noisefilename+".eps");
00058         //copy(Canceller.Desired->begin(),Canceller.Desired->end(),prefcomponent->begin());
00059         //ReferenceData.WriteAsMtu(noisefilename+".clean");
00060         
00061         /*
00062         weightfile.open((noisefilename+".weights").c_str());
00063         for (i = 0; i < Canceller.WeightHistory.size(); ++i)
00064         {
00065                 for (j = 0; j < Configuration.filterlength*ntimeseries; ++j)
00066                 {
00067                         weightfile << j << " " << i << " " << Canceller.WeightHistory.at(i).at(j) << " " << endl;
00068                         //weightfile << Canceller.WeightHistory.at(i).at(j) << " ";
00069                 }
00070                 //weightfile << endl;
00071         }
00072         weightfile.close();*/
00073 }

Generated on Wed Jul 23 16:35:58 2008 for GPLIB++ by  doxygen 1.5.5