//============================================================================ // Name : MaxLloydQuantisierer.cpp // Author : Ruediger Knoerig // Version : // Copyright : GPL // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <fstream> #include <itpp/itbase.h> #include <itpp/base/random.h> #include "MaxLloydQuantizer.h" using namespace std; using namespace itpp; int main() { //vec x="0 0.01 2.8 3.4 1.99 3.6 5 3.2 4.5 7.1 7.9"; //vec x="0 1 2 3"; //Uniform_RNG stat(-2.0,2.0); Laplace_RNG stat; vec x=stat(100000); /*const int N=1000; vec x(N); double dw=2.0*pi*10.0/N; double w=0.0; for(int k=0;k<N;k++,w+=dw) x(k)=sin(w);*/ //cout << "x = " << x << endl; unsigned int R=5; MaxLloydQuantizer<double> quantisierer; quantisierer.setTargetRate(R); cout << "Training " << (quantisierer.train2(x,1e-20,1000000) ? "erfolgreich." : "nicht erfolgreich.") << endl; ofstream kennline("kennline.txt"); double minv=itpp::min(x)-1.0; double maxv=itpp::max(x)+1.0; double step=(maxv-minv)/1000; for(double w=minv;w <= maxv; w+=step) { kennline << w << " " << quantisierer.inv_quant(quantisierer.quantize(w)) << endl; } ofstream signal("signal.txt"); for(int k=0;k<x.length();k++) { double xv=x(k); unsigned int qv=quantisierer.quantize(xv); signal << k << "\t" << xv << "\t" << quantisierer.inv_quant(qv) << endl; } return 0; }