-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab2_1.py
48 lines (42 loc) · 946 Bytes
/
lab2_1.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
import matplotlib.pyplot as plt
import random
import math
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
def Fourier(g):
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
if __name__ == "__main__":
x = []
Plot(x)
Fp = Fourier(x)
plt.stem(Fp)
plt.show()