URL
https://opencores.org/ocsvn/cordic_atan_iq/cordic_atan_iq/trunk
Subversion Repositories cordic_atan_iq
[/] [cordic_atan_iq/] [AuxFunc.sv] - Rev 8
Compare with Previous | Blame | View Log
`ifndef _AuxPkg_`define _AuxPkg_`include "AuxClasses.sv"package AuxFuncPkg;import AuxClassesPkg::*;export AuxClassesPkg::*;function automatic int atan_iq_int(int IS, int QS);if (IS == 0)if (QS > 0)return 2**30; // 90else if (QS < 0)return -(2**30); // -90elsereturn 0;else if (QS == 0)if (IS < 0)return 1<<31; // -180elsereturn 0;else if (IS < 0)if (QS > 0)return int'(($atan(real'(QS)/IS) + PI) * ((2.0**31) / PI));elsereturn int'(($atan(real'(QS)/IS) - PI) * ((2.0**31) / PI));elsereturn int'($atan(real'(QS)/IS) * ((2.0**31) / PI));endfunctionfunction automatic real int_to_deg(int angle);return real'(angle) / 2.0**30 * 90.0;endfunctionfunction automatic int delta(int ref_angle, int angle);return angle - ref_angle;endfunctionfunction automatic real rel_pct(int ref_angle, int angle);int d = delta(ref_angle, angle);if (d < 0) d = -d;if (ref_angle == 0)if (d == 0)return 0;elsereturn 100;elsereturn real'(d) / real'(ref_angle) * 100.0;endfunctionfunction automatic IQArrayList GenIQ(int POINTS = 8);IQArrayList v = new;// 135...45 degfor (int i = -POINTS; i < POINTS; i++)v.push_back(i * (V_MAX / POINTS), V_MAX);// 45...-45 degfor (int i = POINTS; i > -POINTS; i--)v.push_back(V_MAX, i * (V_MAX / POINTS));// -45...-135 degfor (int i = POINTS; i > -POINTS; i--)v.push_back(i * (V_MAX / POINTS), V_MIN);// -135...135 degfor (int i = -POINTS; i < POINTS; i++)v.push_back(V_MIN, i * (V_MAX / POINTS));return v;endfunctionfunction automatic int unsigned iabs(int value);if (value < 0) value = -value;return value;endfunctionfunction automatic int unsigned imag(int I, int Q);real res = int'( $sqrt(real'(I) * real'(I) + real'(Q) * real'(Q)) );int unsigned res_uint = longint'(res);// $display("I %d Q %d Mag %g (%d)\n", I, Q, res, res_uint);return res_uint;endfunctionendpackage :AuxFuncPkg`endif
