python - Python 中的傅里叶变换

标签 python matplotlib

我是使用 Python 进行信号处理的新手。我想找出如何将加速度计的幅度值转换为频域。我的示例代码如下:

在[44]中:

  x = np.arange(30)
  plt.plot(x, np.sin(x))
  plt.xlabel('Number of Sample')
  plt.ylabel('Magnitude Value')
  plt.show()

Graph of the sample values

在这里我想将数据绘制到域频率。所需的输出可能是这样的: Graph of the intended output

最佳答案

numpyscipy 有一个傅立叶变换模块 ( http://docs.scipy.org/doc/numpy/reference/routines.fft.html )。

x = np.linspace(0,5,100)
y = np.sin(2*np.pi*x)

## fourier transform
f = np.fft.fft(y)
## sample frequencies
freq = np.fft.fftfreq(len(y), d=x[1]-x[0])
plt.plot(freq, abs(f)**2) ## will show a peak at a frequency of 1 as it should.

enter image description here

关于python - Python 中的傅里叶变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30209779/

相关文章:

python - 如何使用 Rally API 获取测试用例名称

python - seaborn 中的白盒图? (覆盖层不透明)

python-3.x - matplotlib 错误 : No module named matplotlib even though it is installed

python - 如何在 python 中绘制二进制数据序列

python - print.__doc__ vs getattr(__builtin__ ,"print").__doc__

python - 从命令式编程到函数式编程的转换 [Python 到标准 ML]

Worker中的Python有不同的版本: environment variables are set correctly

Python pygodaddy 连接超时

python - 如何在 matplotlib 和 pandas 中绘制按两列分组的数据框

python - 绘制条形图-colors python