encoding utf-8 import numpy as np import matplotlib pyplot as plt from

 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
# encoding: utf-8
import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack
n_Sample = 100
f_Signal = 50
f_sampling = f_Signal*n_Sample
u_RMS = 50
def show_signal(x, y, title, is_it_t, upper_lim):
plt.plot(x, y) if is_it_t else plt.stem(x, y)
plt.title(title), plt.xlabel('t, c') if is_it_t else plt.xlabel('f, Гц')
plt.ylabel('U, В'), plt.grid(), plt.xlim(0, upper_lim)
plt.axhline(color='black') if is_it_t else None
plt.show()
data = [[np.linspace(0.0, 1/f_Signal, n_Sample)]]
data[0] += \
[
u_RMS*np.sqrt(2)*np.sin(f_Signal * 2.0*np.pi*data[0][0]) + np.random.randint(20, size=n_Sample)\
+ u_RMS*np.sqrt(2)*np.sin(70 * 2.0*np.pi*data[0][0]) + u_RMS*np.sqrt(2)*np.sin(120 * 2.0*np.pi*data[0][0]),
'Сигнал', True, 1/f_Signal
]
data += [
[
[x*f_Signal for x in range(n_Sample)], 2/n_Sample * abs(fftpack.fft(data[0][1])),
'Спектр сигнала', False, f_sampling//2
]
]
data += [
[
data[0][0], [x-y for (x, y) in zip(data[0][1],fftpack.ifft(fftpack.fft(data[0][1])).real)],
'Ошибка', True, 1/f_Signal
]
]
for args in data:
show_signal(*args)