-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab1_2.py
67 lines (60 loc) · 1.26 KB
/
lab1_2.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
66
67
import random
import math
import matplotlib.pyplot as plt
n = 10
omegaMax = 1200
N = 64
k = 128
tau = 64
Yrxx = []
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 Expectancy(g):
Mxx = 0
for t in range(k):
Mxx += (1 / k) * g[t]
return Mxx
def AutoCorr(g):
res = []
Rxxx = 0
Mx = Expectancy(g)
for T in range(tau):
for t in range(tau):
Rxxx = Rxxx + ((g[t] - Mx)* (g[t + T] - Mx))
res.append(Rxxx / (tau - 1))
Yrxx.append(T)
Rxxx = 0
return res
def MutualCorr(g, h):
res = []
Rxy = 0
Mx = Expectancy(g)
My = Expectancy(h)
for T in range(tau):
for t in range(tau):
Rxy = Rxy + ((g[t] - Mx) * (h[t + T] - My)) / (tau - 1)
res.append(Rxy)
Rxy = 0
return res
if __name__ == "__main__":
x = []
y = []
Plot(x)
Plot(y)
Rxx = AutoCorr(x)
plt.plot(Yrxx, Rxx)
plt.show()
Rxy = MutualCorr(x, y)
plt.plot(Yrxx, Rxy)
plt.show()