-
Notifications
You must be signed in to change notification settings - Fork 0
/
additional_task.py
65 lines (59 loc) · 1.51 KB
/
additional_task.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import matplotlib.pyplot as plt
import random
import math
from timeit import default_timer as timer
from datetime import timedelta
n = 10
omegaMax = 1200
N = 64
k = 128
tau = 64
def Plot(g):
A = []
fi = []
for i in range(n):
A.append(random.random())
fii = random.random() * omegaMax
fi.append(fii)
for i in range(k):
res = 0
for j in range(n):
res += A[j] * math.sin((omegaMax / (j + 1)) * i + fi[j])
g.append(res)
yy = i
start = timer()
def FourierList(g, containerType="list"):
Fp = []
W = []
Re = []
Im = []
for i in range(N):
Re.append(math.sin(i * 2 * math.pi / 4))
Im.append(math.cos(i * 2 * math.pi / 4))
W.append(math.sqrt((Re[i] * Re[i]) + (Im[i] * Im[i])))
for k in range(N - 1):
Wpk = 0
for p in range(N - 1):
Wpk = Wpk + W[(p * k) % N]
Fp.append(g[k] * Wpk)
return Fp
end = timer()
startF = timer()
def FourierArray(g, containerType="array"):
Fp = []
W = []
Re = []
Im = []
for i in range(N):
Re.append(math.sin(i * 2 * math.pi / 4))
Im.append(math.cos(i * 2 * math.pi / 4))
W.append(math.sqrt((Re[i] * Re[i]) + (Im[i] * Im[i])))
for k in range(N - 1):
Wpk = 0
for p in range(N - 1):
Wpk = Wpk + W[(p * k) % N]
Fp.append(g[k] * Wpk)
return Fp
endF = timer()
print("DFT time for list:", timedelta(end - start))
print("DFT time for array:", timedelta(endF - startF))