00001 #include <iostream>
00002 #include "WienerInterpolator.h"
00003 #include <boost/numeric/ublas/vector.hpp>
00004 #include <boost/numeric/ublas/vector_proxy.hpp>
00005 #include <algorithm>
00006 #include <iterator>
00007 #include "UniformRNG.h"
00008 #include <itpp/itbase.h>
00009 #include <itpp/srccode/lpcfunc.h>
00010 #include <fstream>
00011 #include <numeric>
00012 #include <nr.h>
00013 #include <nrutil.h>
00014 #include <gsl/gsl_math.h>
00015
00016 namespace ublas = boost::numeric::ublas;
00017 int main()
00018 {
00019 UniformRNG Random;
00020
00021 const int datasize = Random.GetNumber(1000);
00022 const int filterlength = std::min(datasize/(Random.GetNumber(10)+1)+1,datasize);
00023 const int inputlength = std::min(datasize,filterlength*(Random.GetNumber(10)+1));
00024
00025
00026
00027 float *nrdata;
00028 float *d;
00029 nrdata = vector(1,inputlength);
00030 d = vector(1,filterlength);
00031 float xms;
00032 ublas::vector<float> Data(datasize);
00033 itpp::vec ItppData(inputlength);
00034 itpp::vec ItppCoeff(filterlength);
00035 itpp::vec StabCoeff(filterlength);
00036
00037 for (int i = 0; i < datasize; ++i)
00038 {
00039 Data(i) = sin(static_cast<double>(i)/1.2)+ (0.5 - Random.GetNumber())*0.1;
00040
00041 }
00042 WienerInterpolator Wiener(filterlength);
00043 ublas::vector<float> Input(inputlength);
00044 ublas::vector<double> Prediction(datasize);
00045 for (int i = 0; i < inputlength; ++i)
00046 {
00047 Input(i) = Data(i);
00048 ItppData(i) = Data(i);
00049 Prediction(i) = Data(i);
00050 nrdata[i+1] = Data(i);
00051 }
00052 Wiener.AdaptFilter(Input,Input);
00053 memcof(&(Input[0])-1,inputlength,filterlength,&xms,d);
00054
00055 const double tolerance = 1e-3;
00056 std::cout << "Datasize: " << datasize << " Filterlength: " << filterlength << " Inputsize: " << inputlength<< std::endl;
00057 for (int i = 0; i < filterlength; ++i)
00058 {
00059 if ( gsl_fcmp(Wiener.GetWeights()(i),d[i+1],tolerance) != 0)
00060 {
00061 std::cout << "Index: " << i << " Own: " << Wiener.GetWeights()(i) << " NR: " << d[i+1] << std::endl;
00062 }
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 }