sinlms.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 #include "UniformRNG.h"
00011 using namespace std;
00012 
00013 int main()
00014 {
00015         ofstream weightfile;
00016 
00017         
00018         const int filterlength = 2;
00019         const double mu = 0.05;
00020         const int nsamples = 2000;
00021         const double period = 35.2;
00022         const double PI = acos(-1.0);
00023         const double noiselevel = 0.5;
00024         const int shift = 0;
00025         LMSCanceller Filter(filterlength); 
00026         UniformRNG Random;
00027         Filter.SetMu(mu);
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         Canceller.FilterData();
00043         
00044         
00045         
00046         ofstream cleanfile("test.clean");
00047         for (int i = 0; i < nsamples - filterlength-shift; ++i)
00048                 cleanfile << i << " " << Canceller.GetOutChannels().front()->GetData().at(i) << " " << reference.GetData().at(i) << " " 
00049                                          << 2.0*cos( 2.0 * PI * i/period) << endl;
00050         //copy(Canceller.GetOutChannels().front()->GetData().begin(),Canceller.GetOutChannels().front()->GetData().end(),ostream_iterator<double>(cleanfile,"\n"));
00051         ofstream difffile("test.diff");
00052         for (int i = 0; i < nsamples - filterlength-shift; ++i)
00053                 difffile << i << " " << Canceller.GetOutChannels().front()->GetData().at(i) -2.0*cos( 2.0 * PI * i/period)  
00054                           << " " << reference.GetData().at(i) - 2.0*cos( 2.0 * PI * i/period) << endl;
00055         ofstream epsfile("test.eps");
00056         copy(Canceller.GetEpsValues().front().begin(),Canceller.GetEpsValues().front().end(),ostream_iterator<double>(epsfile,"\n"));
00057         
00058         cout << "Last Weights: " << endl;
00059         Filter.PrintWeights(cout);
00060         cout << endl;
00061         
00062         
00063         
00064         /*
00065         weightfile.open((noisefilename+".weights").c_str());
00066         for (i = 0; i < Canceller.WeightHistory.size(); ++i)
00067         {
00068                 for (j = 0; j < Configuration.filterlength*ntimeseries; ++j)
00069                 {
00070                         weightfile << j << " " << i << " " << Canceller.WeightHistory.at(i).at(j) << " " << endl;
00071                         //weightfile << Canceller.WeightHistory.at(i).at(j) << " ";
00072                 }
00073                 //weightfile << endl;
00074         }
00075         weightfile.close();*/
00076 }

Generated on Mon Sep 15 12:54:34 2008 for GPLIB++ by  doxygen 1.5.5