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
# encoding: utf-8
import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack, signal
f_Sampling = 1e4
f_Signal = f_Sampling/2
observation_period = 1/f_Signal*10
n_Sample = f_Sampling*observation_period
u_RMS = 2
def get_fft(signal_):
fft = fftpack.fft(signal_)
return abs(fft)*2/n_Sample
time_line = np.linspace(0.0, observation_period, int(n_Sample))
sq_signal = u_RMS * signal.square(2*np.pi*f_Signal*time_line)
freq_line = [x*f_Signal for x in range(int(n_Sample))]
print("СКЗ сигнала по отсчетам: {}".format(np.sqrt(sum([x**2/len(sq_signal) for x in sq_signal]))))
print("СКЗ сигнала по спектру: {}".format(np.sqrt(sum([x**2 for x in get_fft(sq_signal)]))/2))
plt.subplot(211)
plt.plot(time_line, sq_signal)
plt.subplot(212)
plt.stem(freq_line, get_fft(sq_signal))
plt.show()