用Python进行傅立叶变换 [英] Fourier transform with python

查看:85
本文介绍了用Python进行傅立叶变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数据。它显然具有一定的周期性。我想通过使用傅立叶变换来找出频率,然后将其绘制出来。

I have a set of data. It is obviously have some periodic nature. I want to find out what frequency it has by using the fourier transformation and plot it out.

这里是我的镜头,但看起来不太好。

Here is a shot of mine, but it seems not so good.

这是相应的代码,我不知道为什么它会失败:

This is the corresponding code, I don't konw why it fails:

import numpy
from pylab import *
from scipy.fftpack import fft,fftfreq
import matplotlib.pyplot as plt
dataset = numpy.genfromtxt(fname='data.txt',skip_header=1)
t = dataset[:,0]
signal = dataset[:,1]
npts=len(t)

FFT = abs(fft(signal))
freqs = fftfreq(npts, t[1]-t[0])
subplot(211)
plot(t[:npts], signal[:npts])
subplot(212)
plot(freqs,20*log10(FFT),',')
xlim(-10,10)
show()

我的问题是:由于原始数据非常定期查看,我希望看到在频域中峰值非常尖锐;如何使峰看起来更好?

推荐答案

这是数据分析的问题。

It's a problem of data analysis.


  • FFT与复数一起使用,因此频谱在实际数据输入上是对称的:限制 xlim(0,max (频率))

  • 采样周期不好:在保持相同输入点总数的同时增加周期将导致最佳质量频谱

编辑。
with:

EDIT. with :

 dataset = numpy.genfromtxt(fname='data.txt',skip_header=1)[::30];
 t,signal = dataset.T
 (...)
 plot(freqs,FFT)
 xlim(0,1)
 ylim(0,30)    

频谱是

要获得最佳质量的频谱,只需长时间获取信号即可长时间(对于美丽的峰),采样频率为1 Hz,这将为您提供[0,0.5 Hz]频率刻度(请参阅Nyquist判据)。

For best quality spectrum , just reacquire the signal for a long long time (for beautiful peaks), with sampling frequency of 1 Hz, which will give you a [0, 0.5 Hz] frequency scale (See Nyquist criterium).

这篇关于用Python进行傅立叶变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆