Home > Enterprise >  Python : How I can draw FFT graph with Pandas DataFrame which is made by time and values
Python : How I can draw FFT graph with Pandas DataFrame which is made by time and values

Time:07-22

I am trying to make FFT graph which is derived from Pandas DataFrame.

It is my source code I tried with.

import numpy as np  
import matplotlib.pyplot as plt 
import pandas as pd
from scipy.fft import fftfreq 
plt.style.use("seaborn")

data = pd.read_csv("/Users/kyungyunlee/Desktop/ IRP reference/Data/PIXEL_DATA/1_piece.csv")

N = len(t)
t = data["time"].loc[data["time"] > 5].loc[data["time"] < 10]
s = data["y_value"].loc[data["time"] > 5].loc[data["time"] < 10]
print(len(s))

fft = np.fft.fft(s)
fftfreq = np.fft.fftfreq(len(s))

plt.subplot(1, 2, 1)
plt.xlabel("Frquency Domain")
plt.ylabel("Amplitude")
plt.plot(fftfreq, fft)
plt.subplot(1, 2, 2)
plt.plot(t, s)
plt.show()

And the picture below is the result of the source code. As you can see from the graph, the left graph is FFT and the right graph is the time and amplitude graph. In this situation, I can't understand why my FFT graph is like that. The graph is weird but I can't find what the problem is.

enter image description here

And if you plot the power spectrum (np.abs(fft)), you get: enter image description here

  • Related