Skip to content

Commit 6bb2df6

Browse files
authored
Create CORDIC-Algorithm
0 parents  commit 6bb2df6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

CORDIC-Algorithm

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import numpy as np
2+
a = [-1,1] #direction variable
3+
sd = float(input("Input degree:"))
4+
while(sd>360):
5+
sd = sd - 360
6+
m_rotation = np.matrix([[1,-1],[1,1]])
7+
#while(True):
8+
if(sd>0):
9+
sd = sd - np.arctan(2**(0))*180/np.pi
10+
elif(sd<0):
11+
sd = sd + np.arctan(2**(0))*180/np.pi
12+
#elif(sd == 0):
13+
i = 1
14+
#for i in range(12):
15+
while(True):
16+
print(i)
17+
#i = 1
18+
if(sd > -0.005 and sd < 0.005):
19+
break
20+
elif(sd == 0):
21+
break
22+
elif(sd>0):
23+
sd = sd - np.arctan(2**(-i))*180/np.pi
24+
m_rotasi = m_rotasi*np.matrix([[1,(-2**(-i))*a[1]],[(2**(-i))*a[1],1]])
25+
elif(sd<0):
26+
sd = sd + np.arctan(2**(-i))*180/np.pi
27+
m_rotasi = m_rotasi*np.matrix([[1,(-2**(-i))*a[0]],[(2**(-i))*a[0],1]])
28+
i = i + 1
29+
print(m_rotasi)
30+
print(sd)
31+
#calculate K constant
32+
K = 1
33+
for k in range(i):
34+
d = np.arctan(2**(-k))
35+
K = K * np.cos(d)
36+
#print(K)
37+
x,y = K*m_rotasi*np.matrix([[1],[0]])
38+
print("cos value =", x[0])
39+
print("sine value =", y[0])

0 commit comments

Comments
 (0)