import numpy as np
from scipy.fftpack import fft,ifft
from matplotlib.pylab import plt
# Fs = 1000 #采样频率
# T = 1/Fs #采样周期,只相邻两数据点的时间间隔
# L = 1500 #信号长度
Fs = 5000000000 #采样频率
T = 1/Fs #采样周期,只相邻两数据点的时间间隔
L = 10000#信号长度
nnn = 500000
t = np.arange(L)*T #间隔 T * 个数
npp = np.pi
X = np.sin(2*np.pi *nnn*t)
# X = S + np.random.rand(L)
plt.plot(t[:nnn], X[:nnn])
plt.xlabel("Time(s)")
plt.ylabel("Amplitude")
plt.title("Signol with random noise")
plt.show()
Y = fft(X)
p2 = np.abs(Y) # 双侧频谱
p1 = p2[:int(L/2)]
f = np.arange(int(L/2))*Fs/L;
# plt.plot(f,2*p1/L)
plt.plot(f, p1)
plt.title('Single-Sided Amplitude Spectrum of X(t)')
plt.xlabel('f (Hz)')
plt.ylabel('|P1(f)|')
plt.show()
正弦波及FFT变换py程序
最新推荐文章于 2024-06-29 14:50:08 发布