[关闭]
@wudawufanfan 2017-01-02T04:12:27.000000Z 字数 752 阅读 562

在此处输入标题

未分类


在此输入正文

  1. import matplotlib.pyplot as plt
  2. import plotly.plotly as py
  3. import numpy as np
  4. # Learn about API authentication here: https://plot.ly/python/getting-started
  5. # Find your api_key here: https://plot.ly/settings/api
  6. Fs = 150.0; # sampling rate
  7. Ts = 1.0/Fs; # sampling interval
  8. t = np.arange(0,1,Ts) # time vector
  9. ff = 5; # frequency of the signal
  10. y = np.sin(2*np.pi*ff*t)
  11. n = len(y) # length of the signal
  12. k = np.arange(n)
  13. T = n/Fs
  14. frq = k/T # two sides frequency range
  15. frq = frq[range(n/2)] # one side frequency range
  16. Y = np.fft.fft(y)/n # fft computing and normalization
  17. Y = Y[range(n/2)]
  18. fig, ax = plt.subplots(2, 1)
  19. ax[0].plot(t,y)
  20. ax[0].set_xlabel('Time')
  21. ax[0].set_ylabel('Amplitude')
  22. ax[1].plot(frq,abs(Y),'r') # plotting the spectrum
  23. ax[1].set_xlabel('Freq (Hz)')
  24. ax[1].set_ylabel('|Y(freq)|')
  25. plot_url = py.plot_mpl(fig, filename='mpl-basic-fft')
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注