sinrls.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 "RLSCanceller.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 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 = 3;
00025         RLSCanceller Filter(filterlength); 
00026         UniformRNG Random;
00027         Filter.SetLambda(lambda);
00028         Filter.SetDelta(delta);
00029         
00030         ApplyFilter Canceller(Filter);
00031         
00032         TimeSeriesComponent  reference, input;
00033         
00034         for (int i = 0; i < nsamples; ++i)
00035         {
00036                 reference.GetData().push_back(2.0*cos( 2.0 * PI * i/period)+Random.GetNumber(-noiselevel,noiselevel));
00037                 input.GetData().push_back(sin( 2.0 * PI * i/period));
00038         }
00039 
00040         Canceller.AddReferenceChannel(reference);
00041         Canceller.AddInputChannel(input);
00042         Canceller.SetShift(shift);
00043         Canceller.FilterData();
00044         
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         //copy(Canceller.GetOutChannels().front()->GetData().begin(),Canceller.GetOutChannels().front()->GetData().end(),ostream_iterator<double>(cleanfile,"\n"));
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         
00064         
00065         /*
00066         weightfile.open((noisefilename+".weights").c_str());
00067         for (i = 0; i < Canceller.WeightHistory.size(); ++i)
00068         {
00069                 for (j = 0; j < Configuration.filterlength*ntimeseries; ++j)
00070                 {
00071                         weightfile << j << " " << i << " " << Canceller.WeightHistory.at(i).at(j) << " " << endl;
00072                         //weightfile << Canceller.WeightHistory.at(i).at(j) << " ";
00073                 }
00074                 //weightfile << endl;
00075         }
00076         weightfile.close();*/
00077 }

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