OpenCores
URL https://opencores.org/ocsvn/cordic_atan_iq/cordic_atan_iq/trunk

Subversion Repositories cordic_atan_iq

[/] [cordic_atan_iq/] [AuxFunc.sv] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 Papayaved
`ifndef _AuxPkg_
2
`define _AuxPkg_
3
`include "AuxClasses.sv"
4
 
5
package AuxFuncPkg;
6
        import AuxClassesPkg::*;
7
        export AuxClassesPkg::*;
8
 
9
        function automatic int atan_iq_int(int IS, int QS);
10
                if (IS == 0)
11
                        if (QS > 0)
12
                                return 2**30; // 90
13
                        else if (QS < 0)
14
                                return -(2**30); // -90
15
                        else
16
                                return 0;
17
                else if (QS == 0)
18
                        if (IS < 0)
19
                                return 1<<31; // -180
20
                        else
21
                                return 0;
22
                else if (IS < 0)
23
                        if (QS > 0)
24
                                return int'(($atan(real'(QS)/IS) + PI) * ((2.0**31) / PI));
25
                        else
26
                                return int'(($atan(real'(QS)/IS) - PI) * ((2.0**31) / PI));
27
                else
28
                        return int'($atan(real'(QS)/IS) * ((2.0**31) / PI));
29
        endfunction
30
 
31
        function automatic real int_to_deg(int angle);
32
                return real'(angle) / 2.0**30 * 90.0;
33
        endfunction
34
 
35
        function automatic int delta(int ref_angle, int angle);
36
                return angle - ref_angle;
37
        endfunction
38
 
39
        function automatic real rel_pct(int ref_angle, int angle);
40
                int d = delta(ref_angle, angle);
41
 
42
                if (d < 0) d = -d;
43
 
44
                if (ref_angle == 0)
45
                        if (d == 0)
46
                                return 0;
47
                        else
48
                                return 100;
49
                else
50
                        return real'(d) / real'(ref_angle) * 100.0;
51
        endfunction
52
 
53
        function automatic IQArrayList GenIQ(int POINTS = 8);
54
                IQArrayList v = new;
55
 
56
                // 135...45 deg
57
                for (int i = -POINTS; i < POINTS; i++)
58
                        v.push_back(i * (V_MAX / POINTS), V_MAX);
59
 
60
                // 45...-45 deg
61
                for (int i = POINTS; i > -POINTS; i--)
62
                        v.push_back(V_MAX, i * (V_MAX / POINTS));
63
 
64
                // -45...-135 deg
65
                for (int i = POINTS; i > -POINTS; i--)
66
                        v.push_back(i * (V_MAX / POINTS), V_MIN);
67
 
68
                // -135...135 deg
69
                for (int i = -POINTS; i < POINTS; i++)
70
                        v.push_back(V_MIN, i * (V_MAX / POINTS));
71
 
72
                return v;
73
        endfunction
74
 
75
        function automatic int unsigned iabs(int value);
76
                if (value < 0) value = -value;
77
                return value;
78
        endfunction
79
 
80
        function automatic int unsigned imag(int I, int Q);
81
                real res = int'( $sqrt(real'(I) * real'(I) + real'(Q) * real'(Q)) );
82
                int unsigned res_uint = longint'(res);
83
//              $display("I %d Q %d Mag %g (%d)\n", I, Q, res, res_uint);
84
                return res_uint;
85
        endfunction
86
 
87
endpackage :AuxFuncPkg
88
 
89
`endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.