简体   繁体   中英

Python: Data analysis using FFT

I have a data which looks like this:

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
.............

I'm interested in the Pressure mean which is sampled every minute. My goal is to look for periodic frequencies inside the data.

I've tried the following:

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)

But i'm getting "tuple index out of range" errors

Any ideas on how to analyze the fft and plot the matching frequencies against the raw data?

The raw data looks like this:

在此输入图像描述

Thanks!

You are retrieving only the first element of Pressure but you should do the fourier analysis on all samples. If you replace

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

with

Pfft = np.fft.fft(Pressure)

it works:

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()

我正在考虑这个,我认为问题是Pressure[0]是一个值,你需要将一个数组传递给np.fft.fft()所以试试Pfft = np.fft.fft(Pressure)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM