|
|

楼主 |
发表于 2019-9-5 16:53:00
|
显示全部楼层
import matplotlib.pyplot as plt
import numpy as np
import seaborn
Fs =120; # sampling rate采样率
Ts = 1.0/Fs; # sampling interval 采样区间
t = np.arange(0,1,Ts) # time vector,这里Ts也是步长
ff1 = 10; # frequency of the signal 采样频率
ff2 = 50
y = 10*np.sin(2*np.pi*ff1*t)+10*np.sin(2*np.pi*ff2*t)
n = len(y) # length of the signal 信号长度
k = np.arange(n)
T = n/Fs
frq = k/T # two sides frequency range 两侧频率范围
frq1 = frq[range(int(n/2))] # one side frequency range单侧频率范围
YY = np.fft.fft(y)
Y = np.fft.fft(y)/n # fft computing and normalization 快速傅立叶变换计算与归一化
Y1 = Y[range(int(n/2))]
fig, ax = plt.subplots(4, 1)
ax[0].plot(t,y)
ax[0].set_xlabel('Time')
ax[0].set_ylabel('Amplitude')
ax[1].plot(frq,abs(YY),'r') # plotting the spectrum 绘制光谱
ax[1].set_xlabel('Freq (Hz)')
ax[1].set_ylabel('|Y(freq)|')
ax[2].plot(frq,abs(Y),'G') # plotting the spectrum
ax[2].set_xlabel('Freq (Hz)')
ax[2].set_ylabel('|Y(freq)|')
ax[3].plot(frq1,abs(Y1),'B') # plotting the spectrum
ax[3].set_xlabel('Freq (Hz)')
ax[3].set_ylabel('|Y(freq)|')
plt.show()
其实我更想问这一段红色的 大佬求讲解。。。
|
|