1

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:

enter image description here

Thanks!

8
  • Have you verified that there is data in Pressure? Try printing out the len(Pressure) Commented May 13, 2016 at 12:14
  • Yes I did, it's 28171 Commented May 13, 2016 at 12:15
  • I am assuming, but is the last line you give the one that is giving you the errors? Commented May 13, 2016 at 12:18
  • No, it's the "Pfft = np.fft.fft(Pressure[0])" line Commented May 13, 2016 at 12:19
  • 1
    Your Pressure is a Pandas Series, roughly speaking a numpy ndarray and you compute its DFT by Pfft = np.fft.fft(Pressure) (no indexing!). — I don't know if this problem is or isn't related to the issue that you showed us. Commented May 13, 2016 at 12:21

2 Answers 2

3

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()
Sign up to request clarification or add additional context in comments.

Comments

1

I'm taking a stab at this, I think that the issue is that Pressure[0] is a value and you need to pass an array to np.fft.fft() so try Pfft = np.fft.fft(Pressure)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.