I want to calculate the fft of a given signal using python. The x axis is time (seconds) and the y axis is a voltage. The signal has some kind of periodicity and looks like this:
Following this post, I get this figure:
Is this the correct fft?. The csv file is here. And the code:
import numpy as np
import matplotlib.pyplot as plt
from pandas import read_csv
from scipy.fft import fft
plt.rcParams['figure.dpi'] = 1000
# load the dataset #1
dataframe = read_csv('data/1.csv', usecols=[1])
plt.plot(dataframe)
plt.show()
################ FFT Con scipy
#number of sample points
N = 100
#sampling period
T = 1
#create x-axis for time length of signal
x = np.linspace(0, N*T, N)
#create array that corresponds to values in signal
y = dataframe
y = y - np.mean(y)
#perform FFT on signal
yf = fft(y)
#create new x-axis: frequency from signal
xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
#plot results
plt.plot(xf, abs(yf[0:N//2]), label = 'signal')
plt.grid()
plt.xlabel('Frequency')
plt.ylabel('Spectral Amplitude')
plt.legend(loc=1)
plt.savefig('fft.jpg')
plt.show()