Python 中的傅立叶变换 [英] Fourier Transform in Python
本文介绍了Python 中的傅立叶变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用 Python 进行信号处理的新手.我想找出如何将加速度计的幅度值转换为频域.我的示例代码如下:
I am a newbie in Signal Processing using Python. I want to find out how to transform magnitude value of accelerometer to frequency domain. My example code is following below:
在[44]中:
x = np.arange(30)
plt.plot(x, np.sin(x))
plt.xlabel('Number of Sample')
plt.ylabel('Magnitude Value')
plt.show()
在这里我想将数据绘制到域频率.所需的输出可能是这样的:
In here I want to plot the data to domain frequency. The desired output may be like this:
推荐答案
numpy
and scipy
have a fourier transform module (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.
这篇关于Python 中的傅立叶变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文