11-09-2014, 04:01 PM
(This post was last modified: 11-10-2014, 12:39 AM by GISED_Link.)
Heeey ! I'm implement CORDIC right now in the server XD. The algoithm :
This algo return the cos(=x) value AND the sin(=y) value ! The next algo do it, too.
And my version, to get a result between 0 and 255.
Sorry for french XD
(si = if, alors = then, sinon = else, pour = for, prend_la_valeur = ':=' OR '=', afficher = print() ). I've made this with Algobox.
And where I am now :
And I have to make the state machine, too.
The precision (of my algo) is ± "1°" (when you take the inverse function). (for ±, do alt + 0177 ^^).
I've join CORDIC255, this is an example of the algorithm. Cordic2 is the file where I've found the first algorithm.
Code:
Cordic2(z)
Func{
Local angle,x,y,temp,s,i
{.7854,.46365,.24498,.12435,.06242,.03124,.01562,.00781,.00391,.00195,9.8–
ª4,4.9–ª4,2.4–ª4,1.2–ª4,6.–ª5}»angle
0.60725»x
0»y
For i,0,14
when(z=0,1,signe(z))»s
x-s*y/2^i»temp
y+s*x/2^i»y
temp»x
z-s*angle[i+1]»z
EndFor
Return {x,y}
EndFunc
And my version, to get a result between 0 and 255.
Code:
CORDIC255
1 VARIABLES
2 x EST_DU_TYPE NOMBRE
3 y EST_DU_TYPE NOMBRE
4 temp EST_DU_TYPE NOMBRE
5 s EST_DU_TYPE NOMBRE // this is the sign to change the - in +. so s = 1 or -1.
6 i EST_DU_TYPE NOMBRE
7 angle EST_DU_TYPE LISTE
8 z EST_DU_TYPE NOMBRE (z = input angle, in °)
9 DEBUT_ALGORITHME
10 LIRE z // z = angle
11 z PREND_LA_VALEUR z*2 //to increase the accuracy
12 angle[0] PREND_LA_VALEUR 90
13 angle[1] PREND_LA_VALEUR 53
14 angle[2] PREND_LA_VALEUR 28
15 angle[3] PREND_LA_VALEUR 14
16 angle[4] PREND_LA_VALEUR 7
17 angle[5] PREND_LA_VALEUR 3
18 angle[6] PREND_LA_VALEUR 2
19 angle[7] PREND_LA_VALEUR 1
20 //*end const*
21 x PREND_LA_VALEUR 155
22 y PREND_LA_VALEUR 0
23 //for
24 POUR i ALLANT_DE 0 A 7
25 DEBUT_POUR
26 SI (z==0) ALORS
27 DEBUT_SI
28 s PREND_LA_VALEUR 1
29 FIN_SI
30 SINON
31 DEBUT_SINON
32 s PREND_LA_VALEUR z/abs(z)
33 FIN_SINON
34 temp PREND_LA_VALEUR x - s*(round(y/pow(2,i)))
35 y PREND_LA_VALEUR y + s*(round(x/pow(2,i)))
36 x PREND_LA_VALEUR temp
37 z PREND_LA_VALEUR z - s*(angle[i])
38 FIN_POUR
39 AFFICHER "x cos = "
40 AFFICHER x
41 AFFICHER "y sin = "
42 AFFICHER y
43 FIN_ALGORITHME
(si = if, alors = then, sinon = else, pour = for, prend_la_valeur = ':=' OR '=', afficher = print() ). I've made this with Algobox.
And where I am now :
And I have to make the state machine, too.
The precision (of my algo) is ± "1°" (when you take the inverse function). (for ±, do alt + 0177 ^^).
I've join CORDIC255, this is an example of the algorithm. Cordic2 is the file where I've found the first algorithm.