I have a problem with the results obtained from running sets of codes of numpy FFT functions in my python 3.7.
The problem is that the frequency vs amplitude and frequency vs Power spectrum density plots are not correct - judging from the shape and look of my raw data:
As can be seen from the raw data plot, I would expect the freq. vs amplitude and freq. vs PSD plots should not be looking like what i have now:
FYI, The length of my raw data is 4096 which was taken for 5.7 hours. So, that means one data point is taken in ~ 5 seconds.
How to fix my code to obtain the right results of my FFT analysis?
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fft, fftfreq, ifft, rfft
file = "C:\work\Data_2019-01-03_16-19-49.txt"
df = pd.read_csv(file,skiprows = (0,2), delimiter='\t')
data1_name = "CH9CC05"
data1 = df[data1_name].values
n = data1.size
y= data1
fft_vals = fft(y,n)
freqs = fftfreq(n)
mask = freqs>=0
fft_theo = 1/n* np.abs(fft_vals)
psd = 1/n*(np.abs(fft_vals)**2)
plt.figure(1)
plt.plot(y, label= data1_name)
plt.title(data1_name+" Raw Data")
plt.figure(2)
plt.plot(freqs[mask], fft_theo[mask], 'r')
plt.title(data1_name+" Freq vs Amplitude")
plt.show()
plt.figure(3)
plt.plot(freqs[mask], psd[mask], 'r')
plt.title(data1_name+" Freq vs PSD")
plt.show()`