52
File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 1 of 52 :::::::::::::: Angles_tb.cpp :::::::::::::: # include <cstdlib> # include <cmath> # include <iostream> # include <iomanip> # include <fstream> using namespace std; # include "Core.hpp" # include "Angles.hpp" string GnuTerm; //----------------------------------------------------------------------------- // Purpose: // // Explore Angles Space using Class Angles // // Discussion: // // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 2013.02.07 // // // Author: // // Young Won Lim // // Parameters: // //----------------------------------------------------------------------------- int main (int argc, char * argv[]) { // ---------------------------------------------------------------- // nIter : Number of Iteration = Height of binary angle tree // nAngle : Number of Angles = Number of Leaf Nodes // th : threshold for breaking the cordic algorithm's loop // ---------------------------------------------------------------- int nIter = 10; int nAngle = 1 << nIter; double th = 0.0; // ---------------------------------------------------------------- // GnuTerm : for gnuplot (wxt: monitor, emf: file) // nSamples : determines the number of uniform samples over [-pi/2, +pi/2] // plotEn : enable plotting // ---------------------------------------------------------------- GnuTerm = "wxt"; int nSamples = 1000; int plotEn = 1; // ---------------------------------------------------------------- // useTh : thresholding // useThDisp : display thresholding statistics

print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 1 of 52

::::::::::::::Angles_tb.cpp::::::::::::::# include <cstdlib># include <cmath># include <iostream># include <iomanip># include <fstream>

using namespace std;

# include "Core.hpp"# include "Angles.hpp"

string GnuTerm;

//-----------------------------------------------------------------------------// Purpose:// // Explore Angles Space using Class Angles// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.02.07// //// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------

int main (int argc, char * argv[]) {

// ---------------------------------------------------------------- // nIter : Number of Iteration = Height of binary angle tree // nAngle : Number of Angles = Number of Leaf Nodes // th : threshold for breaking the cordic algorithm's loop // ---------------------------------------------------------------- int nIter = 10; int nAngle = 1 << nIter; double th = 0.0; // ---------------------------------------------------------------- // GnuTerm : for gnuplot (wxt: monitor, emf: file) // nSamples : determines the number of uniform samples over [-pi/2, +pi/2] // plotEn : enable plotting // ---------------------------------------------------------------- GnuTerm = "wxt"; int nSamples = 1000; int plotEn = 1; // ---------------------------------------------------------------- // useTh : thresholding // useThDisp : display thresholding statistics

Page 2: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 2 of 52

// useATAN : use atan() instead angles array values // ---------------------------------------------------------------- int useTh =0; int useThDisp =0; int useATAN =0;

cout << "******* GnuTerm =" << GnuTerm << endl;

//====================================================================# include "Angles_tb.param.cpp"//====================================================================

cout << "cordic_tb01 parameters " << endl; cout << "----------------------------------------------------------\n"; cout << " nIter = " << nIter << endl; cout << " nAngle = " << nAngle << endl; cout << " th = " << th << endl; cout << "----------------------------------------------------------\n"; cout << " GnuTerm = " << GnuTerm << endl; cout << " nSamples = " << nSamples << endl; cout << " plotEn = " << plotEn << endl; cout << "----------------------------------------------------------\n"; cout << " useTh = " << useTh << endl; cout << " useThDisp = " << useThDisp << endl; cout << " useATAN = " << useATAN << endl; cout << "----------------------------------------------------------\n";

//====================================================================// # include "cordic_check.cpp"//====================================================================

int flag_basic = 0; int flag_atree_stat = 0; int flag_uscale_stat = 1;

//-------------------------------------------------------------------------- // LeafAngles : Angles Class for leaf nodes only

// AllAngles : Angles Class for all nodes (internal nodes included) //-------------------------------------------------------------------------- Angles LeafAngles(nIter, nAngle); Angles AllAngles(nIter, 2*nAngle-1); //-------------------------------------------------------------------------- // a. compute_angle : compute angle and binary number string // compute_angle_arrays : init and compute array A[] & Ap[] // b. plot_angle_tree : plot binary angle trees //-------------------------------------------------------------------------- // 1. plot_circle_angle : plot angle vectors on a unit circle // 2. plot_line_angle : plot angle vectors on a linear scal // 3. calc_tscale_statistics : find Angles Statistics --> member data // 4. plot_tscale_statistics : plot delta distribution and angle-delta //*5. plot_stat_residual_angles : plot residuals-angle and residuals-index //*6. calc_uscale_statistics // 7. plot_uscale_statistics //*8. plot_uscale_residual_angles // 9. plot_quantization : plot non-uniform quantization of CORDIC //-------------------------------------------------------------------------- //*: call cordic() //--------------------------------------------------------------------------

Page 3: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52

//-------------------------------------------------------------------------- if (flag_basic) { //-------------------------------------------------------------------------- // b. plot_angle_tree : plot binary angle trees // 1. plot_circle_angle : plot angle vectors on a unit circle // 2. plot_line_angle : plot angle vectors on a linear scal // 9. plot_quantization : plot non-uniform quantization of CORDIC //--------------------------------------------------------------------------

/* b */ LeafAngles.plot_angle_tree(); /* b */ AllAngles.plot_angle_tree();

//* 1 */ LeafAngles.plot_circle_angle(); //* 1 */ AllAngles.plot_circle_angle();

//* 2 */ LeafAngles.plot_line_angle(); //* 2 */ AllAngles.plot_line_angle();

//* 9 */ LeafAngles.plot_quantization(); //* 9 */ AllAngles.plot_quantization();

}

//....................................... LeafAngles.setUseTh(useTh); LeafAngles.setUseThDisp(useThDisp); LeafAngles.setUseATAN(useATAN); LeafAngles.setThreshold(th); //....................................... AllAngles.setUseTh(useTh); AllAngles.setUseThDisp(useThDisp); AllAngles.setUseATAN(useATAN); AllAngles.setThreshold(th); //.......................................

//-------------------------------------------------------------------------- if (flag_atree_stat) { //--------------------------------------------------------------------------

// angle tree statistics //-------------------------------------------------------------------------- // 3. calc_tscale_statistics : find Angles Statistics --> member data // 4. plot_tscale_statistics : plot delta distribution and angle-delta // 5. plot_tscale_residual_angles : plot residuals-angle and residuals-index //--------------------------------------------------------------------------

/* 3 */ LeafAngles.calc_tscale_statistics(); /* 3 */ AllAngles.calc_tscale_statistics();

int binNum =100; /* 4 */ LeafAngles.plot_tscale_statistics(binNum); /* 4 */ AllAngles.plot_tscale_statistics(binNum);

/* 5 */ LeafAngles.plot_tscale_residual_angles(); // cordic() /* 5 */ AllAngles.plot_tscale_residual_angles(); // cordic()

}

//-------------------------------------------------------------------------- if (flag_uscale_stat) { //-------------------------------------------------------------------------- // uniform scale statistics

Page 4: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 4 of 52

//-------------------------------------------------------------------------- // 6. calc_uscale_statistics // 7. plot_uscale_statistics // 8. plot_uscale_residual_angles //-------------------------------------------------------------------------- int nPoint = nAngle*4;

//...................................... // to pass parameters use class uStat // ARm, ADm, RAmm, DAmm, HRAm, HDAm //...................................... uStat S;

/* 6 */ LeafAngles.calc_uscale_statistics(S, nPoint); // cordic() /* 6 */ AllAngles.calc_uscale_statistics(S, nPoint); // cordic()

/* 7 */ LeafAngles.plot_uscale_statistics(S, nPoint); /* 7 */ AllAngles.plot_uscale_statistics(S, nPoint);

/* 8 */ LeafAngles.plot_uscale_residual_angles(100000); // cordic() /* 8 */ AllAngles.plot_uscale_residual_angles(100000); // cordic()

}

return 0;

}

::::::::::::::Angles.hpp::::::::::::::# include <iostream># include <iomanip># include <fstream># include <string>// # include <cstdlib>// # include <cmath># include <vector># include <algorithm># include <map>

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Interface Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.02.20//// Author://

Page 5: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 5 of 52

// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------

extern string GnuTerm;const double pi = 3.141592653589793;const double K = 1.646760258121;

// to pass parameters use class uStattypedef map<double, double> Map;typedef Map::iterator mI;

typedef multimap<double, double> MMap;typedef MMap::iterator mmI;

class uStat { public: Map ARm; // map : angle - residual Map ADm; // map : angle - difference (of adjacent residuals) MMap RAmm; // multimap : residual - angle MMap DAmm; // multimap : difference - angle Map HRCm; // map : residual - count for a histogram Map HDCm; // map : difference -count for a histogram

double min_ang; double max_ang;

double min_res; double max_res; double avg_res; double std_res;

double min_diff; double max_diff; double avg_diff; double std_diff;};

class Angles{

public:

Angles(); Angles(int nIter, int nAngle); ~Angles(); void setNIter (int val) { nIter = val;}; void setNAngle (int val) { nAngle = val;}; void setNPoint (int val) { nPoint = val;}; void setThreshold (double val) { threshold = val;}; void setUseTh (int val) { useTh = val;}; void setUseThDisp (int val) { useThDisp = val;}; void setUseATAN (int val) { useATAN = val;};

int getNIter () { return nIter; }; int getNAngle () { return nAngle; }; int getNPoint () { return nPoint; }; double getThreshold () { return threshold; }; int getUseTh () { return useTh; };

Page 6: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 6 of 52

int getUseThDisp () { return useThDisp; }; int getUseATAN () { return useATAN; };

int getLeaf () { return Leaf; };

//-------------------------------------------------------------------------- // a. compute_angle : compute angle and binary number string // compute_angle_arrays : init and compute array A[] & Ap[] // b. plot_angle_tree : plot binary angle trees //-------------------------------------------------------------------------- // 1. plot_circle_angle : plot angle vectors on a unit circle // 2. plot_line_angle : plot angle vectors on a linear scal // 3. calc_tscale_statistics : find Angles Statistics --> member data // 4. plot_tscale_statistics : plot delta distribution and angle-delta //*5. plot_tscale_residual_angles : plot residuals-angle and residuals-index //*6. calc_uscale_statistics // 7. plot_uscale_statistics //*8. plot_uscale_residual_angles // 9. plot_quantization : plot non-uniform quantization of CORDIC //-------------------------------------------------------------------------- //*: call cordic() //--------------------------------------------------------------------------

/* a */ double compute_angle (int idx, int level, char *s); /* */ void compute_angle_arrays (); /* b */ void plot_angle_tree (); /* 1 */ void plot_circle_angle (); /* 2 */ void plot_line_angle (); /* 3 */ void calc_tscale_statistics (); /* 4 */ void plot_tscale_statistics (int); /* 5 */ void plot_tscale_residual_angles (); /* 6 */ void calc_uscale_statistics (uStat&, int); /* 7 */ void plot_uscale_statistics (uStat&, int); /* 8 */ void plot_uscale_residual_angles (int); /* 9 */ void plot_quantization ();

double *A; // angle array double *B; // sorted angle array

char **Ap; // angle path array

double get_avg_delta () { return avg_delta; }; double get_std_delta () { return std_delta; }; double get_min_delta () { return min_delta; }; double get_max_delta () { return max_delta; }; double get_min_angle () { return min_angle; }; double get_max_angle () { return max_angle; };

double get_ssr () { return ssr; }; // sum of the squares of the residuals double get_mse () { return mse; }; // mean squared error double get_rms () { return rms; }; // root mean square error double get_max_err () { return max_err; }; // maximum of squared errors

double get_threshold () { return threshold; };

void set_avg_delta (double val) { avg_delta = val; }; void set_std_delta (double val) { std_delta = val; }; void set_min_delta (double val) { min_delta = val; }; void set_max_delta (double val) { max_delta = val; }; void set_min_angle (double val) { min_angle = val; }; void set_max_angle (double val) { max_angle = val; };

Page 7: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 7 of 52

void set_ssr (double val) { ssr = val; }; // sum of the squares of the residuals void set_mse (double val) { mse = val; }; // mean squared error void set_rms (double val) { rms = val; }; // root mean square error void set_max_err (double val) { max_err = val; }; // maximum of squared errors

void set_threshold (double val) { threshold = val; };

int is_tscale_stat_done() {return tscale_stat_done; }; int is_uscale_stat_done() {return uscale_stat_done; };

void set_tscale_stat_done(int val) { tscale_stat_done =1; }; void set_uscale_stat_done(int val) { uscale_stat_done =1; };

private: int nIter; int nAngle; int nPoint; int Leaf;

int useTh; int useThDisp; int useATAN;

double avg_delta; double std_delta; double min_delta; double max_delta; double min_angle; double max_angle;

double ssr; // sum of the squares of the residuals double mse; // mean squared error double rms; // root mean square error double max_err; // maximum of squared errors

double threshold;

int tscale_stat_done; int uscale_stat_done;

};

double compute_threshold(int nIter);

//-------------------------------------------------------------------------- // 1. plot_circle_angle : plot angle vectors on a unit circle // 3. calc_tscale_statistics : find Angles Statistics --> member data

// 7. plot_uscale_statistics //*8. plot_uscale_residual_angles // 9. plot_quantization : plot non-uniform quantization of CORDIC // // eg01.bin_ang_tree.emf // // eg02.cumul_ang_tree.emf // // eg03.leaf.ang_circle.emf // eg03.all.ang_circle.emf // //-------------------------------------------------------------------------- // 2. plot_line_angle : plot angle vectors on a linear scal

Page 8: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 8 of 52

// eg02.leaf.ang_line.i1.emf // eg02.all .ang_line.i1.emf //-------------------------------------------------------------------------- // 4. plot_tscale_statistics : plot delta distribution and angle-delta // eg04.leaf.t_delta_dist.[th0.001].emf (histogram of the delta's) // eg04.all .t_delta_dist.[th0.001].emf (histogram of the delta's) // // eg04.leaf.t_angle_delta.[th0.001].emf (angle vs delta angle) // eg04.all .t_angle_delta.[th0.001].emf (angle vs delta angle) //-------------------------------------------------------------------------- //*5. plot_tscale_residual_angles : plot residuals-angle and residuals-index // eg05.leaf.t_index_res.n1000.x1.[th0.001].emf (index vs residual angles) // eg05.all .t_index_res.n1000.x1.[th0.001].emf (index vs residual angles) // // eg05.leaf.t_angle_res.n1000.x1.[th0.001].emf (angle vs residual angles) // eg05.all .t_angle_res.n1000.x1.[th0.001].emf (angle vs residual angles) //-------------------------------------------------------------------------- //*6. calc_uscale_statistics //-------------------------------------------------------------------------- // // eg09.leaf.resfac_ssr.emf // eg09.all.resfac_ssr.emf // // eg10.leaf.offfac_ssr.emf // eg10.all.offfac_ssr.emf // // eg11.leaf.idx_res_us.emf // eg11.all.idx_res_us.emf // // eg12.leaf.ang_res_us.emf // eg12.all.ang_res_us.emf // // eg13.leaf.quantization.emf // eg13.all.quantization.emf //--------------------------------------------------------------------------

::::::::::::::Angles.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm>

# include "Core.hpp"# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Angles Class Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified:

Page 9: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 9 of 52

//// 2013.02.20//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------//// Angles::Angles() : A(NULL), nIter(3), nAngle(8)// void Angles::setNIter(int nIter) // void Angles::setNAngle(int nAngle) // void Angles::setThreshold(double th) // int Angles::getNIter() // int Angles::getNAngle() // double Angles::getThreshold() //// double compute_threshold(int nIter) // //-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Class Angles' Member Functions//-----------------------------------------------------------------------------Angles::Angles() : nIter(3), nAngle(8){ Leaf = 1; cout << "A is not initialized " << endl; cout << "nIter = " << nIter << endl; cout << "nAngle = " << nAngle << endl;

avg_delta = std_delta = min_angle = max_angle = 0.0; ssr = mse = rms = max_err = 0.0;

threshold = 0.0;

//................................. compute_angle_arrays();

//.................................

}

//..................................................Angles::Angles(int nIter, int nAngle) : nIter(nIter), nAngle(nAngle){ if (nAngle == (1 << nIter)) { Leaf = 1; cout << "A LeafAngles Object is created " ; } else { Leaf = 0; cout << "An AllAngles Object is created " ; }

cout << "(nIter = " << nIter << ", "; cout << "nAngle = " << nAngle << ")" <<endl;

avg_delta = std_delta = min_angle = max_angle = 0.0; ssr = mse = rms = max_err = 0.0;

threshold = 0.0;

Page 10: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 10 of 52

//................................. compute_angle_arrays(); //.................................

}

//..................................................Angles::~Angles(){

free(A); for (int i=0; i < nAngle; i++) { free(Ap[i]); } free(Ap);

}

//---------------------------------------------------------------------------------double compute_threshold(int nIter) {

int nAngle = 1 << nIter;

Angles AllAngles(nIter, 2*nAngle-1);

AllAngles.calc_tscale_statistics(); /* 3 */

double th = AllAngles.get_avg_delta();

// th = (AllAngles.get_max_angle() - AllAngles.get_max_angle(); // th /= AllAngles.getNAngle();

cout << "* Computed threshold is to be used : " << th << endl; return th;

}

/***** for (i=0; i<20; i+=4) { for (j=0; j<4; ++j) { r = atan( 1. / (1 << (i+j)) ) / atan( 1. / (1 << i) ) * 100; cout << "index = " << i+j << " --> r = " << r << endl; } }

return 0;}********************/

::::::::::::::Angles.1.plot_circle_angle.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector>

Page 11: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 11 of 52

# include <algorithm>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.01.17//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Plot angle vectors on the unit circle//-----------------------------------------------------------------------------void Angles::plot_circle_angle (){ int i; ofstream myout;

cout << "* plot_circle_angle ... " ; if (Leaf) cout << "(LeafAngles)" << endl; else cout << "(AllAngles)" << endl;

if (nIter > 10) { cout << "nIter = " << nIter << " is too large to plot! " << endl; return; }

// writing angle data on a unit circle myout.open("angle.dat"); for (i=0; i<nAngle; i++) { myout << "0.0 0.0 " << cos(A[i]) << " " << sin(A[i]) << " " << endl; } myout.close();

// writing gnuplot commands myout.open("command.gp"); myout << "set terminal " << GnuTerm << endl; if (Leaf) { myout << "set output 'eg03.leaf.ang_circle.emf'" << endl; myout << "set title \"Leaf Angles on a unit circle \" " << endl; } else { myout << "set output 'eg03.all.ang_circle.emf'" << endl; myout << "set title \"All Angles on a unit circle \" " << endl; }

Page 12: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 12 of 52

myout << "set xlabel \"x\" " << endl; myout << "set ylabel \"y\" " << endl; myout << "set size square" << endl; myout << "set xrange [-1:+1]" << endl; myout << "set yrange [-1:+1]" << endl; myout << "set object 1 circle at 0, 0 radius 1" << endl; myout << "plot 'angle.dat' using 1:2:3:4 "; myout << "with vectors head filled lt 3" << endl; myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

return;

}

::::::::::::::Angles.2.plot_line_angle.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm># include <cstring>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// 2. plot_line_angle()// plot those allowed angles in each level in a linear scale// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.02.15//// Author://// Young Won Lim//// Parameters:// Output : // eg02.leaf.ang_line.i1.emf// eg02.all.ang_line.i1.emf////-----------------------------------------------------------------------------

void plot_line_angle_gnuplot(int ei, double xmin, double xmax, int Leaf, int useTh){ ofstream myout;

Page 13: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 13 of 52

// writing gnuplot commands myout.open("command.gp");

char LorA[] = "Leaf"; (Leaf) ? strcpy(LorA, "Leaf") : strcpy(LorA, "All");

char emfname[30] = "eg02.____.ang_line._.emf"; char emfindex[10]; sprintf(emfindex, "i%d", ei); strcpy(emfname, "eg02."); (Leaf) ? strcat(emfname, "Leaf.") : strcat(emfname, "All."); strcat(emfname, "ang_line."); strcat(emfname, emfindex); strcat(emfname, ".emf");

cout << emfname << endl;

myout << "set terminal " << GnuTerm << endl; myout << "set title \""<< LorA << " Angles on a linear scale" ; myout << "(" << emfindex << ")\" " << endl; myout << "set output '" << emfname << "'" << endl;

myout << "set xlabel \"angles in radian\" " << endl; myout << "set ylabel \"\" " << endl; myout << "set yrange [0:+2]" << endl; myout << "set xrange [" << xmin << ":" << xmax << "]" << endl; myout << "plot 'angle.dat' using 1:2:3:4 "; myout << "with vectors head filled lt 3" << endl; myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

}

//-----------------------------------------------------------------------------// plot those allowed angles in each level in a linear scale//-----------------------------------------------------------------------------void Angles::plot_line_angle (){

cout << "* plot_line_angle ... "; if (Leaf) cout << "(LeafAngles)" << endl; else cout << "(AllAngles)" << endl;

ofstream myout;

myout.open("angle.dat");

for (int i=0; i<nAngle; ++i) { // cout << "A[" << i << "] = " << A[i] << endl; myout << scientific << A[i] << " 0.0 0.0 1.0" << endl; }

myout.close();

int emfIndex = 0; int emfNum = 0; double xmin = 0.;

Page 14: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 14 of 52

double xmax = 0.;

if (nIter < 10) { emfIndex = 0; xmin = -2; xmax = +2; plot_line_angle_gnuplot(emfIndex, xmin, xmax, Leaf, useTh);

} else if (nIter < 21 ) { emfIndex = 0; xmin = -2; xmax = +2;

emfNum = 4;

cout << "Enter the number of ranges : "; cin >> emfNum; cout << endl;

// plot_line_angle_gnuplot(emfIndex, xmin, xmax, Leaf, useTh);

for (int i=0; i<emfNum; ++i) { xmin = -2 + 4./emfNum *i; xmax = -2 + 4./emfNum *(i+1);

plot_line_angle_gnuplot(emfIndex, xmin, xmax, Leaf, useTh); }

} else { cout << "nIter = " << nIter << " is too large to plot! " << endl; }

// cout << "nIter = " << nIter << endl; // cout << "nAngle = " << nAngle << endl;

return;

}

::::::::::::::Angles.3.calc_tscale_statistics.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// calc_tscale_statistics () // from tree scale angles,// compute the sorted vector BV - min, max// compute the difference vector DV - min, max, avg, std// // Discussion://

Page 15: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 15 of 52

//// Licensing://// This code is Distributed under the GNU LGPL license. //// Modified://// 2013.02.22//// Author://// Young Won Lim//// Parameters:// min_angle, max_angle,// min_delta, max_delta, avg_delta, std_delta////-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Find Angles Statistics --> member DVata //-----------------------------------------------------------------------------void Angles::calc_tscale_statistics (){

cout << "* calc_tscale_statistics... "; if (Leaf) cout << "(LeafAngles)" << " nAngle = " << nAngle << endl; else cout << "(AllAngles)" << " nAngle = " << nAngle << endl;

//-------------------------------------------------------------------------- // BV - the sorted angle vector of the angle array A // DV - the delta angle vector of BV //-------------------------------------------------------------------------- vector <double> BV, DV; vector <double> ::iterator first, last;

// BV : sorted angle vector for (int i=0; i < nAngle; ++i) BV.push_back(A[i]);

sort(BV.begin(), BV.end());

// DV : difference angle vector --> delta distribution for (int i=0; i < nAngle-1; ++i) DV.push_back(BV[i+1]- BV[i]);

sort(DV.begin(), DV.end());

for (int i=0; i < nAngle; ++i) { // cout << "A[" << i << "]=" << setw(12) << setprecision(8) << A[i] << endl; // cout << "BV[" << i << "]=" << setw(12) << setprecision(8) << BV[i] << endl; }

// mean & std of the delta distribution double mean, std;

mean = 0.0; for (int i=0; i < DV.size(); ++i) mean += DV[i]; mean /= DV.size();

Page 16: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 16 of 52

std = 0.0; for (int i=0; i < DV.size(); ++i) std += ((DV[i]-mean) * (DV[i]-mean)); std /= DV.size(); std = sqrt(std);

set_min_angle( BV[0] ); set_max_angle( BV[BV.size()-1] );

cout << " min angle = " << get_min_angle() << endl; cout << " max angle = " << get_max_angle() << endl; cout << " -----------------" << endl;

set_min_delta( DV[0] ); set_max_delta( DV[DV.size()-1] ); set_avg_delta( mean ); set_std_delta( std );

cout << " min delta = " << get_min_delta() << endl; cout << " max delta = " << get_max_delta() << endl; cout << " avg delta = " << get_avg_delta() << endl; cout << " std delta = " << get_std_delta() << endl; cout << " -----------------" << endl;

double udelta = (BV[BV.size()-1] - BV[0]) / nAngle; // computed unifrom DVelta

cout << " uniform delta = " << udelta << " = (max-min) / nAngle " << endl;

return;}

::::::::::::::Angles.4.plot_tscale_statistics.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm># include <cstring># include <string># include <map>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified:

Page 17: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 17 of 52

//// 2013.02.26//// Author://// Young Won Lim//// Parameters:// eg04.leaf.t_delta_dist.[th0.001].emf (histogram of the delta's)// eg04.all .t_delta_dist.[th0.001].emf (histogram of the delta's)// // eg04.leaf.t_angle_delta.[th0.001].emf (angle vs delta angle)// eg04.all .t_angle_delta.[th0.001].emf (angle vs delta angle)////-----------------------------------------------------------------------------// void Angles::plot_tscale_statistics (int binNum = 50)// void P4A_make_plot_data// (Angles *Ang, int binNum, vector <double> & BV, vector & DV, int *H) // void P4B_make_plot_data(int binNum, vector <double> & DV) // void P4C_make_plot_data (Angles *Ang)// void P4A_run_gnuplot(int binNum, Stat & S, Angles *Ang)// void P4B_run_gnuplot (Stat & S, Angles *Ang)// void P4_make_emfname(Angles *Ang, const char *inStr, char *emfname)// void P4_make_title(Angles *Ang, const char *inStr, char *title)// void P4_make_nodeStr(Angles *Ang, char *nodeStr)//-----------------------------------------------------------------------------

// to pass parameters use class Statclass Stat { public: double avg; double median; double udelta; double mind; double maxd;};

//-----------------------------------------------------------------------------void P4_make_nodeStr(Angles *Ang, char *nodeStr){ (Ang->getLeaf()) ? strcpy(nodeStr, "Leaf_") : strcpy(nodeStr, "All_");

char levelStr[80] =""; sprintf(levelStr,"%d", Ang->getNIter()); strcat(nodeStr, levelStr);}

//-----------------------------------------------------------------------------void P4_make_emfname(Angles *Ang, const char *inStr, char *emfname){ char nodeStr[80] = "Leaf_"; P4_make_nodeStr(Ang, nodeStr);

strcpy(emfname, "eg04.____.t_delta_dist.--%g.emf"); sprintf(emfname, "eg04.%s.%s.", nodeStr, inStr); char thStr[80] =""; if (Ang->getUseTh()) { sprintf(thStr, "th%g", Ang->getThreshold()); if (Ang->getUseTh()) { strcat(emfname, "."); strcat(emfname, thStr); } }

Page 18: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 18 of 52

strcat(emfname, ".emf");}

//-----------------------------------------------------------------------------void P4_make_title(Angles *Ang, const char *inStr, char *title){ char nodeStr[80] = "Leaf_"; P4_make_nodeStr(Ang, nodeStr); char thStr[80] =""; if (Ang->getUseTh()) { sprintf(thStr, "th%g", Ang->getThreshold()); }

sprintf(title, "%s (%s) %s", inStr, nodeStr, thStr);}

//-----------------------------------------------------------------------------// Plot the histogram of delta angles //-----------------------------------------------------------------------------void P4A_run_gnuplot(int binNum, Stat & S, Angles *Ang){

ofstream myout;

char emfname[80]; strcpy(emfname, "eg04.____.t_delta_dist.--%g.emf"); P4_make_emfname(Ang, "t_delta_dist", emfname);

char title[80]; P4_make_title(Ang, "TSacle Delta Angle Distribution ", title);

char binStr[80] =""; sprintf(binStr, " bin%d", binNum); strcat(title, binStr);

char xlabel[80] = "TScale delta (= adjacent angle difference) bins";

// writing gnuplot commands myout.open("command.gp");

myout << "set terminal " << GnuTerm << endl; myout << "set output '" << emfname << "'" << endl; myout << "set title \"" << title << "\" " << endl; myout << "set xlabel \" " << xlabel << "\" " << endl; myout << "set ylabel \"delta bin's frequency\" " << endl;

myout << "set yrange [0:+1]" << endl;

char str1[80], str2[80];

sprintf(str1, "set arrow from %g, %g to %g, %g\n", S.avg, 0.0, S.avg, 0.5); sprintf(str2, "set label \"avg delta \" at %g, %g right\n", S.avg, 0.5); myout << str1 << str2;

sprintf(str1, "set arrow from %g, %g to %g, %g\n", S.median, 0.0, S.median, 0.7); sprintf(str2, "set label \"median delta \" at %g, %g right\n", S.median, 0.7); myout << str1 << str2;

sprintf(str1, "set arrow from %g, %g to %g, %g\n", S.udelta, 0.0, S.udelta, 0.8); sprintf(str2, "set label \"uniform delta \" at %g, %g right\n", S.udelta, 0.8); myout << str1 << str2;

Page 19: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 19 of 52

myout << "plot 'angle.dat' with linespoints" << endl; myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

return;}

//-----------------------------------------------------------------------------// Plot angles vs. delta angles (to find dense area)//-----------------------------------------------------------------------------void P4B_run_gnuplot (Stat & S, Angles *Ang){

ofstream myout;

char emfname[80]; strcpy(emfname, "eg04.____.t_angle_delta.--%g.emf"); P4_make_emfname(Ang, "t_angle_delta", emfname);

char title[80]; P4_make_title(Ang, "TSacle angle vs delta angles ", title);

char xlabel[80] = "increasing angle order";

// writing gnuplot commands myout.open("command.gp");

myout << "set terminal " << GnuTerm << endl; myout << "set output '" << emfname << "'" << endl; myout << "set title \"" << title << "\" " << endl; myout << "set xlabel \" " << xlabel << "\" " << endl; myout << "set ylabel \"Delta (adjacent angle difference) \" " << endl;

char str1[80], str2[80];

sprintf(str1, "set arrow from %g, %g to %g, %g\n", -1.0, S.avg, +1.0, S.avg); sprintf(str2, "set label \"avg delta \" at %g, %g left\n", -1.5, S.avg*1.02); myout << str1 << str2;

sprintf(str1, "set arrow from %g, %g to %g, %g\n", -1.0, S.udelta, +1.0, S.udelta); sprintf(str2, "set label \"uniform delta \" at %g, %g right\n", +1.5, S.udelta*1.02); myout << str1 << str2;

sprintf(str1, "set arrow from %g, %g to %g, %g\n", -1.0, S.median, +1.0, S.median); sprintf(str2, "set label \"median delta \" at %g, %g right\n", +0.0, S.median*1.02); myout << str1 << str2;

sprintf(str1, "set arrow from %g, %g to %g, %g\n", -0.7853, S.mind, -0.7853, S.maxd); sprintf(str2, "set label \"-pi/4 \" at %g, %g right\n", -0.7853, S.mind); myout << str1 << str2;

sprintf(str1, "set arrow from %g, %g to %g, %g\n", +0.7853, S.mind, +0.7853, S.maxd); sprintf(str2, "set label \"+pi/4 \" at %g, %g right\n", +0.7853, S.mind); myout << str1 << str2;

myout << "plot 'angle.dat' with linespoints" << endl; myout << "pause mouse keypress" << endl;

Page 20: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 20 of 52

myout.close();

system("gnuplot command.gp");

return;

}

//-----------------------------------------------------------------------------// make plot data for delta distribution (histogram)//-----------------------------------------------------------------------------void P4A_make_plot_data(Angles *Ang, int binNum, vector <double> & BV, vector <double> & DV, Stat & S, int *H) {

// BV : sorted angle vector for (int i=0; i < Ang->getNAngle(); ++i) BV.push_back(Ang->A[i]);

sort(BV.begin(), BV.end());

// DV : difference angle vector --> delta distribution for (int i=0; i < Ang->getNAngle()-1; ++i) DV.push_back(BV[i+1]- BV[i]);

sort(DV.begin(), DV.end());

double frac = 0.25, findex = frac * DV.size(); int index = (int) findex;

S.avg = Ang->get_avg_delta(); S.median = DV[index]; S.udelta = (BV[BV.size()-1] - BV[0]) / Ang->getNAngle(); S.mind = Ang->get_min_delta(); S.maxd = Ang->get_max_delta();

cout << " DV.size()/2= " << DV.size()/2; cout << " median: DV[DV.size()/2]= " << DV[DV.size()/2] << endl; cout << " S.median= DV[DV.size()*" << frac << "]= " << S.median << endl;

// computed unifrom delta & bin size double udelta = (BV[BV.size()-1] - BV[0]) / Ang->getNAngle(); double binSize = (DV[DV.size()-1] - DV[0]) / binNum;

// compute the histogram array H double pb ; double lbound, ubound;

for (int i=0; i<DV.size(); i++) for (int j=0; j<binNum; ++j) { lbound = DV[0] + binSize * j; ubound = DV[0] + binSize * (j+1); if ((lbound <= DV[i]) && (DV[i] < ubound)) { H[j]++; } }

ofstream myout;

// write histogram data from delta array myout.open("angle.dat");

Page 21: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 21 of 52

for (int j=0; j<binNum; j++) { pb = H[j] * (1. / DV.size()); lbound = DV[0] + binSize * j; myout << scientific << lbound << " " ; myout << scientific << pb << endl; }

myout.close();

}

//-----------------------------------------------------------------------------// make plot data for angles vs. delta angles (to find dense area)//-----------------------------------------------------------------------------void P4B_make_plot_data(int binNum, vector <double> & BV, vector <double> & DV) { ofstream myout;

// write histogram data from delta array myout.open("angle.dat"); double pb, lbound; double binSize = (DV[DV.size()-1] - DV[0]) / binNum;

for (int i=0; i<BV.size()-1; i++) { myout << scientific << BV[i] << " "; myout << scientific << BV[i+1] - BV[i] << endl; }

myout.close();

}

typedef map<double, double> Map;typedef Map::iterator mapI;

typedef multimap<double, double> MMap;typedef MMap::iterator mmapI;//-----------------------------------------------------------------------------// List all the delta angles //-----------------------------------------------------------------------------void P4C_make_plot_data (Angles *Ang){

vector <double> BV, DV;

// BV : sorted angle vector for (int i=0; i < Ang->getNAngle(); ++i) BV.push_back(Ang->A[i]);

sort(BV.begin(), BV.end());

MMap deltaMMap; Map deltaMap;

double angle, delta; char dStr[80];

// BV : sorted angle vector for (int i=0; i < Ang->getNAngle(); ++i) { angle = BV[i]; if (i == Ang->getNAngle()-1) delta = BV[i] - BV[i-1]; else delta = BV[i+1] - BV[i];

Page 22: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 22 of 52

deltaMMap.insert(make_pair(delta, angle)); deltaMap.insert(make_pair(delta, angle)); }

mmapI it1, it2;

for (it1=deltaMMap.begin(); it1!=deltaMMap.end(); it1++) { double delta = (*it1).first; double angle = (*it1).second;

// cout << " delta =" << delta <<" angles =" << angle << endl;

} mapI i1, i2;

int sum =0; int index =0;

ofstream myout;

myout.open("angle.dat");

for (i1=deltaMap.begin(); i1!=deltaMap.end(); i1++) { double delta = (*i1).first; double angle = (*i1).second; int count = deltaMMap.count(delta);

sum += count; index++;

// cout << " d =" << delta <<" a =" << angle << " count=" << count << endl; myout << scientific << delta << " "; myout << scientific << (double) count/Ang->getNAngle() << endl;

}

myout.close();

cout << " the number of distinct delta's = " << index << endl; cout << " total count: " << sum << " = nAngle:" << Ang->getNAngle() << endl;

}

//-----------------------------------------------------------------------------// Plot Delta Distribution and Angle-Delta //-----------------------------------------------------------------------------void Angles::plot_tscale_statistics (int binNum = 50){

cout << "* plot_tscale_statistics... "; if (Leaf) cout << "(LeafAngles)" << " nAngle = " << nAngle << endl; else cout << "(AllAngles)" << " nAngle = " << nAngle << endl;

if (~is_tscale_stat_done()) //.......................................... calc_tscale_statistics(); //..........................................

//-------------------------------------------------------------------------- // BV - the sorted angle vector of the angle array A

Page 23: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 23 of 52

// DV - the delta angle vector of BV // H - the histogram array // S - avg, median, udelta, mind, maxd; //-------------------------------------------------------------------------- vector <double> BV, DV; int *H = (int *) calloc (binNum, sizeof (int)); Stat S;

cout << " + Delta Distribution Plot \n" ; //.......................................... P4A_make_plot_data(this, binNum, BV, DV, S, H); //.......................................... P4A_run_gnuplot(binNum, S, this); //..........................................

cout << " + List Delta's \n" ; //.......................................... P4C_make_plot_data (this); //.......................................... P4A_run_gnuplot(binNum, S, this); //..........................................

cout << " + Angle-Delta Plot \n" ; //.......................................... P4B_make_plot_data(binNum, BV, DV); //.......................................... P4B_run_gnuplot (S, this); //..........................................

}

::::::::::::::Angles.5.plot_tscale_residual_angles.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm># include <cstring>

# include "Angles.hpp"# include "Core.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// plot_tscale_residual_angles()// [residual angles in the reg z after cordic iterations]// // Discussion:////// Licensing:

Page 24: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 24 of 52

//// This code is distributed under the GNU LGPL license. //// Modified://// 2013.02.18//// Author://// Young Won Lim//// Parameters:// Outputs:// eg05.leaf.t_index_res.x1.[th0.001].emf (index vs residual angles)// eg05.all.t_index_res.x1.[th0.001].emf (index vs residual angles)// // eg05.leaf.t_angle_res.x1.[th0.001].emf (angle vs residual angles)// eg05.all.t_angle_res.x1.[th0.001].emf (angle vs residual angles)////-----------------------------------------------------------------------------// void Angles::plot_tscale_residual_angles ()// void P5_make_plot_data(int modeI, int sampling, Angles *Ang, Core *C)// void P5_run_gnuplot(int modeI, int sampling, Angles *Ang, Core *C)// void P5_make_emfname(Angles *Ang, int modeI, int sampling, char *emfname)// void P5_make_title(Angles *Ang, int modeI, int sampling, char *title)// void P5_make_nodeStr(Angles *Ang, char *nodeStr)

//-----------------------------------------------------------------------------void P5_make_nodeStr(Angles *Ang, char *nodeStr){ (Ang->getLeaf()) ? strcpy(nodeStr, "Leaf_") : strcpy(nodeStr, "All_");

char levelStr[80] =""; sprintf(levelStr,"%d", Ang->getNIter()); strcat(nodeStr, levelStr);}

//-----------------------------------------------------------------------------void P5_make_emfname(Angles *Ang, int modeI, int sampling, char *emfname){ char nodeStr[80] = "Leaf_"; P5_make_nodeStr(Ang, nodeStr);

if (modeI) strcpy(emfname, "eg05.____.t_angle_res.x%d.--%f.emf"); else strcpy(emfname, "eg05.____.t_index_res.x%d.--%f.emf");

if (modeI) sprintf(emfname, "eg05.%s.t_angle_res.", nodeStr); else sprintf(emfname, "eg05.%s.t_index_res.", nodeStr);

char factor[80] = ""; sprintf(factor, "x%d", sampling); strcat(emfname, factor);

char thStr[80] =""; if (Ang->getUseTh()) { sprintf(thStr, "th%g", Ang->getThreshold()); if (Ang->getUseTh()) { strcat(emfname, "."); strcat(emfname, thStr); } }

strcat(emfname, ".emf");}

Page 25: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 25 of 52

//-----------------------------------------------------------------------------void P5_make_title(Angles *Ang, int modeI, int sampling, char *title){ char inStr[80] = "TSacle Index vs. Residual Angles"; if (modeI) strcpy(title, "Angles vs. Residual Angles ");

char nodeStr[80] = "Leaf_"; P5_make_nodeStr(Ang, nodeStr); char thStr[80] =""; if (Ang->getUseTh()) { sprintf(thStr, "th%g", Ang->getThreshold()); }

char factor[80] = ""; sprintf(factor, "x%d", sampling);

sprintf(title, "%s (%s) %s %s", inStr, nodeStr, thStr, factor);

}

//-----------------------------------------------------------------------------// modeI=0 Use A[i] for Index vs Residual Angles angles Plot// modeI=1 Use b[i] for Angle vs Residual Angles angles Plot//-----------------------------------------------------------------------------void P5_run_gnuplot(int modeI, int sampling, Angles *Ang, Core *C){ ofstream myout;

char emfname[80]; P5_make_emfname(Ang, modeI, sampling, emfname); char title[80]; P5_make_title(Ang, modeI, sampling, title);

char xlabel[80] = "TScale Increasing Index Order"; if (modeI) strcpy(xlabel, "TScale Increasing Angle Order");

char ustring[80] = "1:3"; if (modeI) strcpy(ustring, "2:3");

// writing gnuplot commands myout.open("command.gp");

myout << "set terminal " << GnuTerm << endl; myout << "set output '" << emfname << "'" << endl; myout << "set title \"" << title << "\" " << endl; myout << "set xlabel \" " << xlabel << "\" " << endl; myout << "set ylabel \"Residual Angles in the z reg\" " << endl; myout << "plot 'angle.dat' using " << ustring << " with linespoints " << endl;

myout << "pause mouse keypress" << endl;

myout.close();

system("gnuplot command.gp");

}

//-----------------------------------------------------------------------------// I=0 Use A[i] for Index vs Residual Angles angles Plot// I=1 Use b[i] for Angle vs Residual Angles angles Plot//-----------------------------------------------------------------------------void P5_make_plot_data(int modeI, int sampling, Angles *Ang, Core *C)

Page 26: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 26 of 52

{ ofstream myout;

double x, y, z; double nBreak;

// not member but local variables double se, ssr, mse, rms, min_err, max_err; se = ssr = mse = rms = 0.0; min_err = +1.0e+10; max_err = -1.0e+10;

double *Arr;

if (modeI==0) { cout << " + TScale Index vs. residual angles plot" << endl; Arr = Ang->A; // residual angles in increasing index values } else { cout << " + TScale Angle vs. residual angles plot" << endl; Arr = Ang->B; // residual angles in increasing angle values }

// writing residue errors myout.open("angle.dat");

for (int i=0; i<Ang->getNAngle(); i++) { x = 1.0; y = 0.0; z = Arr[i];

C->setNBreakInit(i); //........................................................... C->cordic(&x, &y, &z); //........................................................... nBreak = C->getNBreak();

se = z * z; ssr += se; if (se > max_err) max_err = se;

if (se < min_err) min_err = se;

// cout << "A[" << i << "]= "; // cout << fixed << right << setw(10) << setprecision(7) << A[i]; // cout << " z= " ; // cout << fixed << right << setw(10) << setprecision(7) << z << endl;

if (i%sampling == 0) { myout << fixed << i << " "; myout << scientific << Arr[i] << " " ; myout << scientific << z << endl; } }

myout.close();

mse = ssr / Ang->getNAngle(); rms = sqrt(mse);

// max_err = sqrt(max_err);

cout << " No of points = " << Ang->getNAngle() ;

Page 27: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 27 of 52

cout << " (nBreak = " << nBreak << " : " ; cout << 100. * nBreak / Ang->getNAngle() << " % )" << endl;

printf(" SSR: Sum of Squared Residual Angles = ") ; printf("%12.7f (= %g) \n", ssr, ssr); printf(" MSR: Mean Squared Residual Angles = ") ; printf("%12.7f (= %g) \n", mse, mse); printf(" RMS: Root Mean Squared Residual Angles = ") ; printf("%12.7f (= %g) \n", rms, rms); printf(" Min Squared Residual Angle Error = ") ; printf("%12.7f (= %g) \n", min_err, min_err); printf(" Max Squared Residual Angle Error = ") ; printf("%12.7f (= %g) \n", max_err, max_err); // cout << fixed << right << setw(12) << setprecision(7) << ssr << endl; // cout << fixed << right << setw(12) << setprecision(7) << mse << endl; // cout << fixed << right << setw(12) << setprecision(7) << rms << endl; // cout << fixed << right << setw(12) << setprecision(7) << max_err << endl;

}

//-----------------------------------------------------------------------------// plot residual errors// Residual Angles-Angle Plot and Residual Angles-Index Plot//-----------------------------------------------------------------------------void Angles::plot_tscale_residual_angles (){ int i; int sampling;

cout << "* plot_tscale_residual_angles ... "; if (getLeaf()) cout << "(LeafAngles)" << endl; else cout << "(AllAngles)" << endl;

if (nIter < 10) { sampling = 1; } else if (nIter < 21 ) { cout << "Enter the sampling factor : "; cin >> sampling; } else { cout << "nIter = " << nIter << " is too large to plot! " << endl; return; }

// B : sorted angles array vector <double> BB; vector <double> ::iterator first, last; for (int i=0; i < nAngle; ++i) BB.push_back(A[i]); sort(BB.begin(), BB.end()); for (int i=0; i < nAngle; ++i) B[i] = BB[i];

Core C;

char path[32]; int nBreak =0; C.setPath(path); C.setLevel(nIter); C.setThreshold(threshold); C.setNBreak(nBreak);

Page 28: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 28 of 52

C.setUseTh(useTh); C.setUseThDisp(useThDisp); C.setUseATAN(useATAN);

//.............................................................. // I=0 Use A[i] for Index-Residual Angles Plot // I=1 Use B[i] for Angle-Residual Angles Plot //.............................................................. for (int I=0; I<2; I++) { P5_make_plot_data(I, sampling, this, &C); P5_run_gnuplot(I, sampling, this, &C); } //..............................................................

return;

}

::::::::::::::Angles.6.calc_uscale_statistics.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm># include <map>

# include "Angles.hpp"# include "Core.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.03.15//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------// void Angles::calc_uscale_statistics (int nPoint =10000)// void find_residual_angles(int nPoint, Angles *Ang, Core *C, uStat & S)// void calc_statistics(int nPoint, uStat & S) // void make_histogram(int nPoint, MMap & A, Map & H, const char * inStr)// double find_min(Map & H) // double find_max(Map & H) // double find_avg(Map & H)

Page 29: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 29 of 52

// double find_std(Map & H, double avg)

//-----------------------------------------------------------------------------double find_min(Map & H) { mI si = H.begin(); return ((*si).first); // minimum of a range (res or diff)}

//-----------------------------------------------------------------------------double find_max(Map & H) { mI ei = H.end(); ei--; return ((*ei).first); // maximum of a range (res or diff)}

//-----------------------------------------------------------------------------double find_avg(Map & H){ mI i1;

double avg=0.0; int count = 0; for (i1=H.begin(); i1!=H.end(); i1++) { double tmp = (*i1).first; avg += tmp; count++; } avg /= count; // average of a range (res or diff) return (avg);}

//-----------------------------------------------------------------------------double find_std(Map & H, double avg){ mI i1;

double std=0.0; int count = 0;

for (i1=H.begin(); i1!=H.end(); i1++) { double tmp = (*i1).first; std += ((tmp - avg) * (tmp - avg)); count++; } std /= count; // std dev of a range (res or diff) return (std);}

//-----------------------------------------------------------------------------// make_histogram(nPoint, S.RAmm, S.HRCm, "residual");// make_histogram(nPoint, S.DAmm, S.HDCm, "difference of residual");//-----------------------------------------------------------------------------void make_histogram(int nPoint, MMap & A, Map & C, const char * inStr){ double tmp; int sum, cnt; int index = 0;

sum = 0.0;

mI i1;

Page 30: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 30 of 52

for (i1=C.begin(); i1!=C.end(); i1++) {

tmp = (*i1).first; cnt = A.count(tmp); (*i1).second = cnt; sum += cnt; index++;// cout << "1st= " << (*i1).first << " "; // cout << "2nd= " << (*i1).second << " ";// cout << " " << inStr << endl;

}

cout << " the number of distinct " << inStr << " angles = " << index << endl; cout << " total count: " << sum << " = nPoint:" << nPoint << endl;

return;

for (i1=C.begin(); i1!=C.end(); i1++) { tmp = (*i1).first; cnt = (*i1).second;

(*i1).second = (double) cnt/ (double) sum; }

}

//-----------------------------------------------------------------------------// Calculate statistics //-----------------------------------------------------------------------------void calc_statistics(int nPoint, uStat & S) { double mean, std; double diff, res, ang; int count = 0;

mI si, ei, i1;

S.min_ang = find_min(S.ARm); S.max_ang = find_max(S.ARm); printf("---------------------------------\n"); printf(" min angle = %g \n", S.min_ang); printf(" max angle = %g \n", S.max_ang); printf(" #step angle = %g ", (S.max_ang-S.min_ang)/nPoint); printf("= (max_angle-min_angle) / nPoint \n");

//--------------------------------------------------------- S.min_res = find_min(S.HRCm); S.max_res = find_max(S.HRCm);

S.avg_res = find_avg(S.HRCm); S.std_res = find_std(S.HRCm, S.avg_res);

printf("---------------------------------\n"); printf(" min residual = %g \n", S.min_res); printf(" max residual = %g \n", S.max_res); printf(" avg residual = %g \n", S.avg_res); printf(" std residual = %g \n", S.std_res); printf(" #rms residual = %g ", sqrt(S.avg_res));

Page 31: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 31 of 52

printf("= sqrt(avg_res) \n"); printf(" uniform residual = %g ", (S.max_res-S.min_res)/nPoint); printf("= (max_res-min_res) / nPoint \n");

//--------------------------------------------------------- S.min_diff = find_min(S.HDCm); S.max_diff = find_max(S.HDCm);

S.avg_diff = find_avg(S.HDCm); S.std_diff = find_std(S.HDCm, S.avg_diff);

printf("---------------------------------\n"); printf(" min diff = %g \n", S.min_diff); printf(" max diff = %g \n", S.max_diff); printf(" avg diff = %g \n", S.avg_diff); printf(" std diff = %g \n", S.std_diff); printf(" #rms diff = %g ", sqrt(abs(S.avg_diff))); printf("= sqrt(abs(avg_diff)) \n"); printf(" uniform diff = %g ", (S.max_diff-S.min_diff)/nPoint); printf("= (max_diff-min_diff) / nPoint \n"); printf("---------------------------------\n");

}

//-----------------------------------------------------------------------------// Calculate statistics on the uniform scale//-----------------------------------------------------------------------------// ssr : sum of the squares of the residuals// mse : mean squared error// rms : root mean square error// max_err : maximum of squared errors//-----------------------------------------------------------------------------// ssr : sum of the squares of the residuals// ang = min_angle + avg_delta * offFactor ; // ang += (avg_delta / resFactor); //-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Find residual angles on a uniform scale //-----------------------------------------------------------------------------void find_residual_angles(int nPoint, Angles *Ang, Core *C, uStat & S){ double x, y, z; double nBreak;

// not member but local variables double se, ssr, mse, rms, min_err, max_err; se = ssr = mse = rms = 0.0; min_err = +1.0e+10; max_err = -1.0e+10;

double ang = Ang->get_min_angle(); double step = (Ang->get_max_angle() - Ang->get_min_angle()) / nPoint; int n = 0; double old_z = 0., diff = 0.;

S.ARm.clear(); S.ADm.clear(); S.RAmm.clear();

Page 32: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 32 of 52

S.DAmm.clear(); S.HRCm.clear(); S.HDCm.clear();

cout << "nPoint =" << nPoint << " init ang=" << ang << " step=" << step << endl;

while (ang < Ang->get_max_angle()) { x = 1.0; y = 0.0; z = ang;

C->setNBreakInit(n); //........................................................... C->cordic(&x, &y, &z); //........................................................... nBreak = C->getNBreak();

se = z * z; ssr += se; if (se > max_err) max_err = se; if (se < min_err) min_err = se; diff = z - old_z;

// printf("ang = %g diff = %g \n", ang, diff);

S.ARm.insert ( make_pair (ang, se) ); S.RAmm.insert ( make_pair (se, ang) ); S.HRCm.insert ( make_pair (se, ang) ); // overwrite

S.ADm.insert ( make_pair (ang, diff) ); S.DAmm.insert ( make_pair (diff, ang) ); S.HDCm.insert ( make_pair (diff, ang) ); // overwrite

// HRCm, HDCm stores the latest item --> to find unique res & diff // in make_histogram(), frequency count is stored in second field old_z = z; ang += step; n++; }

mse = ssr / n; rms = sqrt(mse);

printf(" No of points = %d \n", n); printf(" (nBreak = %d : %g %% )\n", nBreak, 100.*nBreak/n);

printf(" SSR: Sum of Squared Residual Angles (Sum z*z) \n") ; printf(" MSR: Mean Squared Residual Angles (SSR/nPoint) \n") ; printf(" RMS: Root Mean Squared Residual Angles (sqrt(MSR)) \n") ; printf(" Min Squared Residual Angles (Min z*z) \n") ; printf(" Max Squared Residual Angles (Max z*z) \n") ;

printf(" SSR: (Sum z*z) = %15.9f (= %g) \n", ssr, ssr) ; printf(" MSR: (SSR/nPoint) = %15.9f (= %g) \n", mse, mse) ; printf(" RMS: (sqrt(MSR)) = %15.9f (= %g) \n", rms, rms) ; printf(" Min (Min z*z) = %15.9f (= %g) \n", min_err, min_err) ; printf(" Max (Max z*z) = %15.9f (= %g) \n", max_err, max_err) ;

}

Page 33: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 33 of 52

//-----------------------------------------------------------------------------// calculate uniform scale statistics//-----------------------------------------------------------------------------void Angles::calc_uscale_statistics ( uStat & S, int nPoint =10000){

int n; int sampling;

if (~is_tscale_stat_done()) cout << ".........................................." << endl; calc_tscale_statistics(); cout << ".........................................." << endl;

cout << "* calc_uscale_statistics ... "; if (Leaf) cout << "(LeafAngles Resolution)" << endl; else cout << "(AllAngles Resolution)" << endl;

/* if (nIter < 10) { sampling = 1; } else if (nIter < 21 ) { cout << "Enter the sampling factor : "; cin >> sampling; } else { cout << "nIter = " << nIter << " is too large to plot! " << endl; return; }*/

if (nPoint < 0) { cout << "Overflow in nPoint=" << nPoint << endl; return; }

Core C;

char path[32]; int nBreak =0; C.setPath(path); C.setLevel(nIter); C.setThreshold(threshold); C.setNBreak(nBreak); C.setUseTh(useTh); C.setUseThDisp(useThDisp); C.setUseATAN(useATAN);

setNPoint(nPoint);

//..................................................... find_residual_angles(nPoint, this, &C, S); //.....................................................

//----------------------------------------------------------------------------- // Map ARm; // Map : angle - residual // Map ADm; // Map : angle - difference (of adjacent residuals) // MMap RAmm; // multiMap : residual - angle // MMap DAmm; // multiMap : difference - angle // Map HRCm; // Map : residual - angle for a histogram

Page 34: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 34 of 52

// Map HDCm; // Map : difference -angle for a histogram //-----------------------------------------------------------------------------

//..................................................... calc_statistics(nPoint, S); //.....................................................

//.............................................. make_histogram(nPoint, S.RAmm, S.HRCm, "residual"); make_histogram(nPoint, S.DAmm, S.HDCm, "difference of residual"); //..............................................

return;

}

::::::::::::::Angles.7.plot_uscale_statistics.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm># include <cstring># include <string>

# include "Angles.hpp"

using namespace std;

int prec = 2;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.03.22//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------

class gpData { public: char GnuTerm[80]; char LorA[80]; char emfname[80];

Page 35: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 35 of 52

char nStr[80]; char factor[80]; char thStr[80]; char title[80]; char xlabel[80]; char ustring[80];};

//-----------------------------------------------------------------------------// Plot the histogram of residue or differece //-----------------------------------------------------------------------------void P7A_run_gnuplot(Angles *Ang, int sampling, int nPoint, int mode){ gpData G;

strcat(G.GnuTerm, GnuTerm.c_str());

sprintf(G.LorA, "%s", Ang->getLeaf() ? "Leaf" : "All");

// if (mode) strcpy(G.emfname, "eg07.____.u_dff_hist.n%d.x%d.--%f.emf"); // else strcpy(G.emfname, "eg07.____.u_res_hist.n%d.x%d.--%f.emf");

sprintf(G.emfname, "eg07.%s.u_%s_hist.", G.LorA, (mode) ? "dff" : "res" ); sprintf(G.nStr, "n%d", nPoint); sprintf(G.factor, "x%d", sampling);

strcat(G.emfname, G.nStr); strcat(G.emfname, G.factor);

if (Ang->getUseTh()) { sprintf(G.thStr, "th%g", Ang->getThreshold()); strcat(G.emfname, "."); strcat(G.emfname, G.thStr); }

strcat(G.emfname, ".emf"); if (mode) strcpy(G.title, "Difference Residue vs. Frequency Angles "); else strcpy(G.title, "Residue vs. Frequency Angles ");

strcat(G.title, G.LorA); strcat(G.title, G.factor); strcat(G.title, G.thStr);

if (mode) strcpy(G.xlabel, "Difference residue in the increasing order"); else strcpy(G.xlabel, "Residue in the increasing order");

strcpy(G.ustring, "1:2");

ofstream myout;

// writing gnuplot commands myout.open("command.gp");

myout << "set terminal " << GnuTerm << endl; myout << "set output '" << G.emfname << "'" << endl; myout << "set title \"" << G.title << "\" " << endl; myout << "set xlabel \" " << G.xlabel << "\" " << endl; myout << "set ylabel \"frequency\" " << endl; myout << "plot 'angle.dat' using " << G.ustring << " with impulses " << endl;

// myout << "set style fill solid" << endl; // myout << "set boxwidth 0.01 relative" << endl; // myout << "plot 'angle.dat' using " << G.ustring << " with boxes " << endl;

Page 36: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 36 of 52

//myout << "set style data histograms" << endl; //myout << "set style histogram cluster" << endl; //myout << "set style fill solid 1.0 border lt -1" << endl; //myout << plot for [COL=2:4:2] ’file.dat’ using COL

myout << "pause mouse keypress" << endl;

myout.close();

system("gnuplot command.gp");

}

//-----------------------------------------------------------------------------// Plot residue or differece vs angles //-----------------------------------------------------------------------------void P7B_run_gnuplot(Angles *Ang, int sampling, int nPoint, int mode){ gpData G;

strcat(G.GnuTerm, GnuTerm.c_str());

sprintf(G.LorA, "%s", Ang->getLeaf() ? "Leaf" : "All");

// if (mode) strcpy(G.emfname, "eg07.____.u_dff_hist.n%d.x%d.--%f.emf"); // else strcpy(G.emfname, "eg07.____.u_res_hist.n%d.x%d.--%f.emf");

sprintf(G.emfname, "eg07.%s.u_%s_hist.", G.LorA, (mode) ? "dff" : "res" ); sprintf(G.nStr, "n%d", nPoint); sprintf(G.factor, "x%d", sampling);

strcat(G.emfname, G.nStr); strcat(G.emfname, G.factor);

if (Ang->getUseTh()) { sprintf(G.thStr, "th%g", Ang->getThreshold()); strcat(G.emfname, "."); strcat(G.emfname, G.thStr); }

strcat(G.emfname, ".emf"); if (mode) strcpy(G.title, "Difference Residue vs. Frequency Angles "); else strcpy(G.title, "Residue vs. Frequency Angles ");

strcat(G.title, G.LorA); strcat(G.title, G.factor); strcat(G.title, G.thStr);

if (mode) strcpy(G.xlabel, "Difference residue in the increasing order"); else strcpy(G.xlabel, "Residue in the increasing order");

strcpy(G.ustring, "1:2");

ofstream myout;

// writing gnuplot commands myout.open("command.gp");

myout << "set terminal " << GnuTerm << endl; myout << "set output '" << G.emfname << "'" << endl;

Page 37: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 37 of 52

myout << "set title \"" << G.title << "\" " << endl; myout << "set xlabel \" " << G.xlabel << "\" " << endl; myout << "set ylabel \"frequency\" " << endl; myout << "plot 'angle.dat' using " << G.ustring << " with impulses linetype 1, "; myout << " 'angle.dat' using " << G.ustring << " with points linetype 1" << endl;

//myout << "set style data histograms" << endl; //myout << "set style histogram cluster" << endl; //myout << "set style fill solid 1.0 border lt -1" << endl; //myout << plot for [COL=2:4:2] ’file.dat’ using COL

myout << "pause mouse keypress" << endl;

myout.close();

system("gnuplot command.gp");

}

//-----------------------------------------------------------------------------// make plot data for residue or difference of residue (histogram)//-----------------------------------------------------------------------------// mode = 0 : HRCm (Residue - Count)// mode = 1 : HDCm (Difference - Count)//-----------------------------------------------------------------------------void P7A_make_plot_data_mI(uStat & S, int mode) { mI lbound, ubound;

if (mode) { lbound = S.HDCm.begin(); ubound = S.HDCm.end(); cout << " . [difference residue - frequency] plot using HDCm " << endl; } else { lbound = S.HRCm.begin(); ubound = S.HRCm.end(); cout << " . [residue - frequency] plot using HRCm " << endl; }

ofstream myout;

// write histogram data from delta array myout.open("angle.dat");

map<double, double> C; map<double, double>::iterator i; mI i1; char str[80]; double tmp1, tmp2, tmp3, sum;

sum = 0.0; for (i1=lbound; i1!=ubound; i1++) { tmp1 = (*i1).first; tmp2 = (*i1).second; sum += tmp2;

if (mode) { sprintf(str, "%20.5e", tmp1);

} else {sprintf(str, "%12.1e", tmp1);

Page 38: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 38 of 52

}

if (C[atof(str)] == 0.0) { C[atof(str)] = tmp2; } else { tmp3 = tmp2 + C[atof(str)]; C[atof(str)] = tmp3; } }

cout << "total count sum = " << sum << endl;

for (i=C.begin(); i!=C.end(); i++) { sprintf(str, "%g %g", (*i).first, (*i).second / sum); myout << str << endl; }

myout.close();

}

//-----------------------------------------------------------------------------// make plot data for residue or difference of residue (histogram)//-----------------------------------------------------------------------------// mode = 0 : RAmm (Residue - Angle)// mode = 1 : DAmm (Difference - Angle)//-----------------------------------------------------------------------------void P7B_make_plot_data_mmI(uStat & S, int mode) {

mmI lbound, ubound;

if (mode) { lbound = S.DAmm.begin(); ubound = S.DAmm.end(); cout << " . [difference residue - angle] plot using HDCm " << endl; } else { lbound = S.RAmm.begin(); ubound = S.RAmm.end(); cout << " . [residue - angle] plot using HRCm " << endl; }

ofstream myout;

// write histogram data from delta array myout.open("angle.dat");

mmI i1;

multimap<double, double> C; multimap<double, double>::iterator i; char str[80]; double tmp1, tmp2;

for (i1=lbound; i1!=ubound; i1++) { tmp1 = (*i1).first; tmp2 = (*i1).second;

if (mode) { sprintf(str, "%20.1e", tmp1);

} else {sprintf(str, "%12.1e", tmp1);

}

Page 39: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 39 of 52

C.insert( make_pair(atof(str), tmp2) );// cout << "first = " << str << " second = " << tmp2 << endl; }

for (i=C.begin(); i!=C.end(); i++) { sprintf(str, "%g %g", (*i).first, (*i).second); myout << str << endl; }

myout.close();

}

//-----------------------------------------------------------------------------// Plot uniform scale statistics//-----------------------------------------------------------------------------// nPoint : the number of angle points on the uniform scale// uStat : // Map ARm; // map : angle - residual // Map ADm; // map : angle - difference (of adjacent residuals)// MMap RAmm; // multimap : residual - angle// MMap DAmm; // multimap : difference - angle// Map HRCm; // map : residual - count for a histogram // Map HDCm; // map : difference -count for a histogram// double min_ang, max_ang;// double min_res, max_res, avg_res, std_res;// double min_diff, max_diff, avg_diff, std_diff;//-----------------------------------------------------------------------------void Angles::plot_uscale_statistics (uStat & S, int nPoint){ int i, j;

cout << "* plot_uscale_statistics ... "; if (Leaf) cout << "(LeafAngles Resolution)" << endl; else cout << "(AllAngles Resolution)" << endl;

// mode=0 : RAmm, HRCm - residue // mode=1 : DAmm, HDCm - difference residue int mode; int sampling;

//.......................................... cout << " + Residue - Histogram Plot \n" ; P7A_make_plot_data_mI(S, mode=0); P7A_run_gnuplot(this, sampling=1, nPoint, mode=0); //.......................................... cout << " + Difference Residue - Histogram Plot \n" ; P7A_make_plot_data_mI(S, mode=1); P7A_run_gnuplot(this, sampling=1, nPoint, mode=1); //..........................................

//.......................................... cout << " + Residue - Angles Plot \n" ; P7B_make_plot_data_mmI(S, mode=0); P7B_run_gnuplot(this, sampling=1, nPoint, mode=0); //.......................................... cout << " + Difference Residue - Angles Plot \n" ;

Page 40: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 40 of 52

P7B_make_plot_data_mmI(S, mode=1); P7B_run_gnuplot(this, sampling=1, nPoint, mode=1); //..........................................

return;

}

//-----------------------------------------------------------------------------void old_plot_uscale_statistics ( ){/* int i, j; double resFactor, offFactor; ofstream myout;

int M=4; // no of resFactor's int N=4; // no of offFactor's double SSR[M][N];

for (i=0; i<M; i++) { resFactor = i + 1.0;

for (j=0; j<N; j++) { offFactor = (j+1) / N;

cout << " ======= resFactor= " << i << ", offFactor= " << j ; cout << " =======" << endl;

calc_uscale_statistics(1000); SSR[i][j] = ssr; } }

// writing residue errors myout.open("angle.dat");

for (i=0; i<M; i++) { cout << i+1 << " "; myout << i+1 << " "; for (j=0; j<N; j++) { cout << SSR[i][j] << " "; myout << SSR[i][j] << " "; } cout << endl; myout << endl; }

myout.close();

// writing gnuplot commands myout.open("command.gp"); myout << "set terminal " << GnuTerm << endl; myout << "set autoscale y" << endl; if (Leaf) { myout << "set output 'eg09.leaf.resfac_ssr.emf'" << endl;

Page 41: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 41 of 52

myout << "set title \"resFactor-SSR Plot (Leaf) \" " << endl; } else { myout << "set output 'eg09.all.resfac_ssr.emf'" << endl; myout << "set title \"resFactor-SSR Plot (All) \" " << endl; } myout << "set xlabel \"resFactor\" " << endl; myout << "set ylabel \"SSR (Sum of Squared Residuals)\" " << endl; myout << "plot " ; for (j=0; j<N; j++) { myout << " 'angle.dat' using 1:" << j+2 ; myout << " title 'offFactor=" << (j+1) << "/" << N << "' "; myout << " with linespoints" ; if (j<N-1) myout << ", "; else myout << endl; }

myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

// writing residue errors myout.open("angle.dat");

for (j=0; j<N; j++) { cout << j+1 << " "; myout << j+1 << " "; for (i=0; i<M; i++) { cout << SSR[i][j] << " "; myout << SSR[i][j] << " "; } cout << endl; myout << endl; }

myout.close();

// writing gnuplot commands myout.open("command.gp"); myout << "set terminal " << GnuTerm << endl; myout << "set autoscale y" << endl; myout << "set autoscale y" << endl; if (Leaf) { myout << "set output 'eg10.leaf.offfac_ssr.emf'" << endl; myout << "set title \"offFactor-SSR Plot (Leaf) \" " << endl; } else { myout << "set output 'eg10.all.offfac_ssr.emf'" << endl; myout << "set title \"offFactor-SSR Plot (All) \" " << endl; } myout << "set xlabel \"offFactor\" " << endl; myout << "set ylabel \"SSR (Sum of Squared Residuals)\" " << endl; myout << "plot " ; for (i=0; i<M; i++) { myout << " 'angle.dat' using 1:" << i+2 ; myout << " title 'resFactor=" << (i+1) << "' "; myout << " with linespoints" ; if (i<M-1) myout << ", "; else myout << endl; }

myout << "pause mouse keypress" << endl; myout.close();

Page 42: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 42 of 52

system("gnuplot command.gp");

*/ return;

}

::::::::::::::Angles.8.plot_uscale_residual_angles.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm>

# include "Angles.hpp"# include "Core.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// plot_uscale_residual_angles()// [residual angles in the reg z after cordic iterations]// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.02.20//// Author://// Young Won Lim//// Parameters://// eg08.leaf.u_index_res.x1.[th0.001].emf (index vs residual angles)// eg08.all.u_index_res.x1.[th0.001].emf (index vs residual angles)// // eg08.leaf.u_angle_res.x1.[th0.001].emf (angle vs residual angles)// eg08.all.u_angle_res.x1.[th0.001].emf (angle vs residual angles)//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// modeI=0 Use [the index n ] for Index vs Residual Angles angles Plot// modeI=1 Use [the n-th angle] for Angle vs Residual Angles angles Plot//-----------------------------------------------------------------------------void plot_uscale_residual_angles_gnuplot

Page 43: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 43 of 52

(int modeI, int sampling, int nPoint, Angles *Ang, Core *C){ ofstream myout;

char LorA[] = "Leaf"; (Ang->getLeaf()) ? strcpy(LorA, "Leaf") : strcpy(LorA, "All");

char emfname[80]; if (modeI) strcpy(emfname, "eg08.____.u_angle_res.n%d.x%d.--%f.emf"); else strcpy(emfname, "eg08.____.u_index_res.n%d.x%d.--%f.emf");

(modeI) ? strcpy(emfname, "eg08.") : strcpy(emfname, "eg08."); (Ang->getLeaf()) ? strcat(emfname, "Leaf.") : strcat(emfname, "All."); (modeI) ? strcat(emfname, "u_angle_res.") : strcat(emfname, "u_index_res."); char nStr[80] = ""; sprintf(nStr, "n%d", nPoint); strcat(emfname, nStr);

char factor[80] = ""; sprintf(factor, "x%d", sampling); strcat(emfname, factor);

char thStr[80] =""; if (Ang->getUseTh()) { sprintf(thStr, "th%g", Ang->getThreshold()); if (Ang->getUseTh()) { strcat(emfname, "."); strcat(emfname, thStr); } }

strcat(emfname, ".emf"); char title[80] = "UScale Index vs. Residual Angles"; if (modeI) strcpy(title, "Angles vs. Residual Angles "); (Ang->getLeaf()) ? strcat(title, "(Leaf)") : strcat(title, "(All)"); strcat(title, factor); strcat(title, thStr);

char xlabel[80] = "UScale Increasing Index"; if (modeI) strcpy(xlabel, "UScale Increasing Angle");

char ustring[80] = "1:3"; if (modeI) strcpy(ustring, "2:3");

// writing gnuplot commands myout.open("command.gp");

myout << "set terminal " << GnuTerm << endl; myout << "set output '" << emfname << "'" << endl; myout << "set title \"" << title << "\" " << endl; myout << "set xlabel \" " << xlabel << "\" " << endl; myout << "set ylabel \"Residual Angles in the z reg\" " << endl; myout << "plot 'angle.dat' using " << ustring << " with linespoints " << endl;

myout << "pause mouse keypress" << endl;

myout.close();

system("gnuplot command.gp");

}

//-----------------------------------------------------------------------------

Page 44: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 44 of 52

// incremental angle = (max_angle - min_angle) / nPoint;//-----------------------------------------------------------------------------void plot_uscale_residual_angles_sampling(int sampling, int nPoint, Angles *Ang, Core *C){ ofstream myout;

double x, y, z; double nBreak;

// not member but local variables double se, ssr, mse, rms, min_err, max_err; se = ssr = mse = rms = 0.0; min_err = +1.0e+10; max_err = -1.0e+10;

// writing residue errors myout.open("angle.dat"); double ang = Ang->get_min_angle(); int n = 0;

while (ang < Ang->get_max_angle()) { x = 1.0; y = 0.0; z = ang;

C->setNBreakInit(n); //........................................................... C->cordic(&x, &y, &z); //........................................................... nBreak = C->getNBreak();

se = z * z; ssr += se; if (se > max_err) max_err = se; if (se < min_err) min_err = se;

// cout << "A[" << i << "]= "; // cout << fixed << right << setw(10) << setprecision(7) << A[i];

// cout << " z= " ; // cout << fixed << right << setw(10) << setprecision(7) << z << endl;

if (n%sampling == 0) { myout << fixed << right << setw(10) << n; myout << fixed << right << setw(22) << setprecision(7) << ang; myout << fixed << right << setw(22) << setprecision(7) << z; myout << fixed << right << setw(22) << setprecision(7) << se << endl; }

ang += (Ang->get_max_angle() - Ang->get_min_angle()) / nPoint; n++; }

myout.close();

mse = ssr / n; rms = sqrt(mse);

// max_err = sqrt(max_err);

cout << " No of points = " << n ;

Page 45: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 45 of 52

cout << " (nBreak = " << nBreak << " : " ; cout << 100. * nBreak / n << " % )" << endl;

printf(" SSR: Sum of Squared Residual Angles = ") ; printf("%12.7f (= %g) \n", ssr, ssr); printf(" MSR: Mean Squared Residual Angles = ") ; printf("%12.7f (= %g) \n", mse, mse); printf(" RMS: Root Mean Squared Residual Angles = ") ; printf("%12.7f (= %g) \n", rms, rms); printf(" Min Squared Residual Angle Error = ") ; printf("%12.7f (= %g) \n", min_err, min_err); printf(" Max Squared Residual Angle Error = ") ; printf("%12.7f (= %g) \n", max_err, max_err); // cout << fixed << right << setw(12) << setprecision(7) << ssr << endl; // cout << fixed << right << setw(12) << setprecision(7) << mse << endl; // cout << fixed << right << setw(12) << setprecision(7) << rms << endl; // cout << fixed << right << setw(12) << setprecision(7) << max_err << endl;

}

//-----------------------------------------------------------------------------// Plot residual errors on the uniform scale//-----------------------------------------------------------------------------void Angles::plot_uscale_residual_angles (int nPoint =10000){

int n; int sampling;

cout << "* plot_uscale_residual_angles ... "; if (Leaf) cout << "(LeafAngles Resolution)" << endl; else cout << "(AllAngles Resolution)" << endl;

if (nIter < 10) { sampling = 1; } else if (nIter < 21 ) { cout << "Enter the sampling factor : "; cin >> sampling; } else { cout << "nIter = " << nIter << " is too large to plot! " << endl; return; }

Core C;

char path[32]; int nBreak =0; C.setPath(path); C.setLevel(nIter); C.setThreshold(threshold); C.setNBreak(nBreak); C.setUseTh(useTh); C.setUseThDisp(useThDisp); C.setUseATAN(useATAN);

//.............................................................. // modeI=0 Use [the index n ] for Index vs Residual Angles angles Plot // modeI=1 Use [the n-th angle] for Angle vs Residual Angles angles Plot //..............................................................

Page 46: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 46 of 52

calc_tscale_statistics(); plot_uscale_residual_angles_sampling(sampling, nPoint, this, &C); for (int I=0; I<2; I++) { plot_uscale_residual_angles_gnuplot(I, sampling, nPoint, this, &C); } //..............................................................

}

::::::::::::::Angles.9.plot_quantization.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.01.17//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Plot Non-uniform Quantization of CORDIC //-----------------------------------------------------------------------------void Angles::plot_quantization (){

vector <double> B, D; vector <double> ::iterator first, last; double mean, std; ofstream myout;

cout << "* calc_tscale_statistics... "; if (Leaf) cout << "(LeafAngles)" << " nAngle = " << nAngle << endl;

Page 47: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 47 of 52

else cout << "(AllAngles)" << " nAngle = " << nAngle << endl;

for (int i=0; i < nAngle; ++i) { // cout << "A[" << i << "]=" << setw(12) << setprecision(8) << A[i] << endl; // cout << "B[" << i << "]=" << setw(12) << setprecision(8) << B[i] << endl; }

// B : sorted angles array for (int i=0; i < nAngle; ++i) B.push_back(A[i]);

sort(B.begin(), B.end());

// D : difference angle array for (int i=0; i < nAngle-1; ++i) D.push_back(B[i+1]- B[i]);

sort(D.begin(), D.end());

double udelta = (B[B.size()-1] - B[0]) / nAngle; // computed unifrom delta

// write histogram data from delta array myout.open("angle.dat"); double pb ; for (int i=0; i<nAngle; i++) { myout << fixed << right << setw(12) << setprecision(7) << B[0] + udelta*i ; myout << fixed << right << setw(12) << setprecision(7) << B[0] + udelta*i ; myout << fixed << right << setw(12) << setprecision(7) << B[i] ; myout << " " << endl; } myout.close();

cout << " + Quantization Effect Plot \n" ;

// writing gnuplot commands myout.open("command.gp"); myout << "set terminal " << GnuTerm << endl; if (Leaf) { myout << "set output 'eg13.leaf.quantization.emf'" << endl; myout << "set title \"Quantization Effect of Leaf Angles\" " << endl; } else { myout << "set output 'eg13.all.quantization.emf'" << endl; myout << "set title \"Quantization Effect of All Angles\" " << endl; } myout << "set xlabel \"Delta (Adjacent Angle Difference)\" " << endl; myout << "set ylabel \"Quantized Angles\" " << endl; myout << "set yrange [" << B[0] << ":" << B[B.size()-1] << "]" << endl;

myout << "plot 'angle.dat' using 1:2 with lines, "; myout << " 'angle.dat' using 1:3 with lines" << endl; myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

return;

}

Page 48: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 48 of 52

::::::::::::::Angles.a.compute_angle_arrays.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream># include <vector># include <algorithm>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.01.23//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------// // double Angles::compute_angle (int idx, int level, char *s)// void Angles::compute_angle_arrays ()// //-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Compute an angle value and binary string based on the binary tree // idx - index for leaf nodes [0..2^level -1]// level - the level of the binary angle tree// s[] - binary number string for the number idx//-----------------------------------------------------------------------------double Angles::compute_angle (int idx, int level, char *s){ int i, j; double angle; // i - bit position starting from msb // j = 2^i // (idx & (1 << (level-i-1))) - i-th bit of idx from msb // if each bit is '1', add atan(1/2^i) // if each bit is '0', sub atan(1/2^i) // s[32] contains the binary representation of idx

angle = 0.0; for (i=0; i<level; i++) { j = 1 << i; if (idx & (1 << (level-i-1))) { angle += atan( 1. / j );

Page 49: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 49 of 52

s[i] = '1'; } else { angle -= atan( 1. / j ); s[i] = '0'; } // cout << "i=" << i << " j=" << j << " 1/j=" << 1./j // << " atan(1/j)=" << atan(1./j)*180/3.1416 << endl; } s[i] = '\0';

// cout << level << " " << idx << " " << s // << " ---> " << angle*180/3.1416 << endl;

return angle;}

//-----------------------------------------------------------------------------// Initialize and compute the arrays A[] and Ap[][]//-----------------------------------------------------------------------------void Angles::compute_angle_arrays (){

A = (double *) malloc (nAngle * sizeof (double)); B = (double *) malloc (nAngle * sizeof (double)); Ap = (char **) malloc (nAngle * sizeof (char *)); for (int i=0; i < nAngle; i++) { Ap[i] = (char *) malloc (256 * sizeof (char)); }

char s[256]; int i, j; int k, level, leaves;

if (Leaf) { // Leaf Angles only for (j=0; j<nAngle; ++j) { A[j] = compute_angle(j, nIter, Ap[j]); // cout << "A[" << j << "]=" << setw(12) << setprecision(8) << A[j] << endl; } } else { // All Angles included k=0; for (i=0; i<=nIter; ++i) { level = i; leaves = 1 << level; // cout << "level = " << level << "leaves = " << leaves << endl; for (j=0; j<leaves; ++j) { A[k+j] = compute_angle(j, level, Ap[k+j]); // cout << "A[" << j+k << "] = " << A[j+k] << endl; } k += leaves; } } }

::::::::::::::Angles.b.plot_angle_tree.cpp::::::::::::::# include <iostream># include <iomanip># include <cstdlib># include <cmath># include <fstream>

Page 50: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 50 of 52

# include <vector># include <algorithm>

# include "Angles.hpp"

using namespace std;

//-----------------------------------------------------------------------------// Purpose:// // Class Angles Implementation Files// // Discussion:////// Licensing://// This code is distributed under the GNU LGPL license. //// Modified://// 2013.01.23//// Author://// Young Won Lim//// Parameters:////-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------// Plot binary angle trees for Leaf and All node cases//-----------------------------------------------------------------------------void Angles::plot_angle_tree (){

int level, leaves; int i, j, k; ofstream myout;

if (nIter > 10) { cout << "nIter = " << nIter << " is too large to plot! " << endl; return; }

// cout << "nIter = " << nIter << endl; // cout << "nAngle = " << nAngle << endl;

//--------------------------------------- if (Leaf) { //--------------------------------------- // Binary Angle Tree (Leaf) //--------------------------------------- myout.open("angle.dat");

level = nIter; for (i=0; i<level; ++i) { leaves = 1 << nIter; for (j=0; j<leaves; ++j) { // cout << "A[" << j << "] = " << A[j] << endl; myout << A[j]*180/pi << " " << i << " 0.0 1.0" << endl; } }

Page 51: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 51 of 52

myout.close();

// writing gnuplot commands myout.open("command.gp"); myout << "set terminal " << GnuTerm << endl; myout << "set output 'eg01.bin_ang_tree.emf'" << endl; myout << "set title \"Binary Angle Tree\" " << endl; myout << "set xlabel \"Angles in degree\" " << endl; myout << "set ylabel \"Levels \" " << endl; myout << "set format x \"%.0f\" " << endl; myout << "set format y \"%.0f\" " << endl; myout << "plot 'angle.dat' using 1:2:3:4 "; myout << "with vectors head filled lt 3" << endl; myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

//--------------------------------------- } else { //--------------------------------------- // Cumulative Angle Tree (All) //---------------------------------------

myout.open("angle.dat");

k=0; for (i=0; i<=nIter; ++i) { level = i; leaves = 1 << level; // cout << "level = " << level << "leaves = " << leaves << endl; for (j=0; j<leaves; ++j) { // cout << "A[" << k+j << "] = " << A[k+j] << endl; myout << A[k+j]*180/pi << " " << i << " 0.0 1.0" << endl; } k += leaves; } myout.close();

// writing gnuplot commands myout.open("command.gp"); myout << "set terminal " << GnuTerm << endl; myout << "set output 'eg02.cumul_ang_tree.emf'" << endl; myout << "set title \"Cumulative Binary Angle Tree\" " << endl; myout << "set xlabel \"Angles in degree\" " << endl; myout << "set ylabel \"Levels \" " << endl; myout << "set format x \"%.0f\" " << endl; myout << "set format y \"%.0f\" " << endl; myout << "plot 'angle.dat' using 1:2:3:4 "; myout << "with vectors head filled lt 4" << endl; myout << "pause mouse keypress" << endl; myout.close();

system("gnuplot command.gp");

//--------------------------------------- } //---------------------------------------

return;

Page 52: print.file.Angles Page 1 of 52 · 3/23/2013  · File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 3 of 52 //-----if (flag_basic) {

File: /home/young/MyWork/7.cordic_accuracy/print.file.Angles Page 52 of 52

}