@wudawufanfan
2017-01-02T04:12:27.000000Z
字数 752
阅读 615
未分类
在此输入正文
import matplotlib.pyplot as pltimport plotly.plotly as pyimport numpy as np# Learn about API authentication here: https://plot.ly/python/getting-started# Find your api_key here: https://plot.ly/settings/apiFs = 150.0; # sampling rateTs = 1.0/Fs; # sampling intervalt = np.arange(0,1,Ts) # time vectorff = 5; # frequency of the signaly = np.sin(2*np.pi*ff*t)n = len(y) # length of the signalk = np.arange(n)T = n/Fsfrq = k/T # two sides frequency rangefrq = frq[range(n/2)] # one side frequency rangeY = np.fft.fft(y)/n # fft computing and normalizationY = Y[range(n/2)]fig, ax = plt.subplots(2, 1)ax[0].plot(t,y)ax[0].set_xlabel('Time')ax[0].set_ylabel('Amplitude')ax[1].plot(frq,abs(Y),'r') # plotting the spectrumax[1].set_xlabel('Freq (Hz)')ax[1].set_ylabel('|Y(freq)|')plot_url = py.plot_mpl(fig, filename='mpl-basic-fft')