2016-05-13 65 views
1

數據分析我有一個data它看起來像這樣:的Python:使用FFT

YYYY-MO-DD HH-MI-SS_SSS, ATMOSPHERIC PRESSURE (hPa) mean, ATMOSPHERIC PRESSURE (hPa) std 
2016-04-20 00:00:00,1006.0515000000001,0.029159119281803602 
2016-04-20 00:01:00,1006.039666666667,0.03565211699642609 
2016-04-20 00:02:00,1006.0148333333334,0.036891580347842706 
2016-04-20 00:03:00,1006.0058333333335,0.03351152934243721 
2016-04-20 00:04:00,1005.9714999999999,0.03155973620213212 
2016-04-20 00:05:00,1005.955666666667,0.027207094455343653 
............. 

我感興趣的壓力意味着其採樣的每一分鐘。 我的目標是在數據中查找週期性頻率。

我已經試過如下:

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
from scipy.fftpack import fft 
    df3 = pd.read_csv('Pressure - Dates by Minute.csv', sep=",", skiprows=0) 
    Pressure = df3['ATMOSPHERIC PRESSURE (hPa) mean'] 
    frate = 1/60 
    Pfft = np.fft.fft(Pressure[0]) 
    freqs = fft.fftfreq(len(Pfft), 1/frate) 

但我發現了「元組索引超出範圍」錯誤

如何分析FFT和暗算的匹配頻率的任何想法原始數據?

的原始數據是這樣的:

enter image description here

謝謝!

+0

您是否驗證過數據在'壓力'中?嘗試打印出'len(壓力)' –

+0

是的,我做了,我假設它是28171 – ValientProcess

+0

,但是你給最後一行給出了錯誤嗎? –

回答

2

您只檢索Pressure的第一個元素,但您應該對所有樣品進行傅立葉分析。如果您有

Pfft = np.fft.fft(Pressure) 

更換

Pfft = np.fft.fft(Pressure[0]) 

它的工作原理:

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 

df3 = pd.read_csv('Pressure - Dates by Minute.csv', sep=",", skiprows=0) 
Pressure = df3['ATMOSPHERIC PRESSURE (hPa) mean'] 
frate = 1./60 
Pfft = np.fft.fft(Pressure) 
Pfft[0] = 0 # Set huge DC component to zero, equates to Pressure = Pressure - numpy.mean(Pressure) 

freqs = np.fft.fftfreq(len(Pfft), 1./frate) 
plt.plot(freqs, Pfft) 
plt.show() 
1

我正在刺傷在此,我認爲這個問題是Pressure[0]是一個值,你需要傳遞數組到np.fft.fft()所以請嘗試Pfft = np.fft.fft(Pressure)