forked from exo7math/deepmath-exo7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrelation_1d.py
More file actions
87 lines (62 loc) · 1.71 KB
/
Copy pathcorrelation_1d.py
File metadata and controls
87 lines (62 loc) · 1.71 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import numpy as np
import matplotlib.pyplot as plt
def correlation(f,g):
gg = g[::-1]
h = np.convolve(f,gg,'same')
return h
##########################################
# Exemple de correlation
f = np.array([1,0,3,5,1])
g = np.array([1,2,3])
h = correlation(f,g)
print("=== Exemple ===")
print('f =',f)
print('g =',g)
print('h =',h)
##########################################
# Génération d'un signal émis par radar
# Cela peut être n'importe quoi
Nout = 100
Xout = np.linspace(-3.14,3.14,Nout)
Yout = np.sinc(Xout) -0.5
plt.plot(Yout,color='red')
plt.tight_layout()
# plt.savefig('correlation1d-1.png')
plt.show()
##########################################
# Génération d'un signal bruité reçus par le radar
# Cela peut être n'importe quoi
a, b, Nin = 0, 1000, 1000
Xin = np.linspace(a, b, Nin)
# Yrandom = 1*np.sin(0.1*Xin) + 1*np.random.random(Nin)
Yrandom = 0.5*np.random.normal(0,1,Nin)
plt.figure(figsize=(10,3))
plt.plot(Yrandom)
plt.tight_layout()
# plt.savefig('correlation1d-2.png')
plt.show()
delay = 350
Yin = Yrandom + np.pad(Yout,(delay,Nin-Nout-delay))
plt.figure(figsize=(10,3))
plt.plot(Yin,color='blue')
plt.tight_layout()
# plt.savefig('correlation1d-3.png')
plt.show()
# Visualisation
def affichage_correlation(f,g):
h = correlation(f,g)
ax = plt.subplot(2,1,1)
ax.set_title("Entrée f")
plt.plot(f,color='blue')
# ax = plt.subplot(3,1,2)
# ax.set_title("fonction g")
# plt.plot(g,color='orange')
ax = plt.subplot(2,1,2)
ax.set_title("Sortie h = correlation(f,g)")
plt.plot(h,color='red')
plt.subplots_adjust(top=0.9, bottom=0.1, left=0.1, right=0.95, hspace=1.0,wspace=0.5)
plt.tight_layout()
# plt.savefig('correlation1d-4.png')
plt.show()
return
affichage_correlation(Yin,Yout)