I have passed my time series data,which is essentially measurements from a sensor about pressure, through a Fourier transformation, similar to what is described in . The file used can be found here: The code related is this :
import pandas as pd import numpy as np file='test.xlsx' df=pd.read_excel(file,header=0) #df=pd.read_csv(file,header=0) df.head() df.tail() # drop ID df=df[['JSON_TIMESTAMP','ADH_DEL_CURTAIN_DELIVERY~ADH_DEL_AVERAGE_ADH_WEIGHT_FB','ADH_DEL_CURTAIN_DELIVERY~ADH_DEL_ADH_COATWEIGHT_SP']] # extract year month df["year"] = df["JSON_TIMESTAMP"].str[:4] df["month"] = df["JSON_TIMESTAMP"].str[5:7] df["day"] = df["JSON_TIMESTAMP"].str[8:10] df= df.sort_values( ['year', 'month','day'], ascending = [True, True,True]) df['JSON_TIMESTAMP'] = df['JSON_TIMESTAMP'].astype('datetime64[ns]') df.sort_values(by='JSON_TIMESTAMP', ascending=True) df1=df.copy() df1 = df1.set_index('JSON_TIMESTAMP') df1 = df1[["ADH_DEL_CURTAIN_DELIVERY~ADH_DEL_AVERAGE_ADH_WEIGHT_FB"]] import matplotlib.pyplot as plt #plt.figure(figsize=(15,7)) plt.rcParams["figure.figsize"] = (25,8) df1.plot() #df.plot(style='k. ') plt.show() df1.hist(bins=20) from scipy.fft import rfft,rfftfreq ## # convert into x and y x = list(range(len(df1.index))) y = df1['ADH_DEL_CURTAIN_DELIVERY~ADH_DEL_AVERAGE_ADH_WEIGHT_FB'] # apply fast fourier transform and take absolute values f=abs(np.fft.fft(df1)) # get the list of frequencies num=np.size(x) freq = [i / num for i in list(range(num))] # get the list of spectrums spectrum=f.real*f.real+f.imag*f.imag nspectrum=spectrum/spectrum[0] # plot nspectrum per frequency, with a semilog scale on nspectrum plt.semilogy(freq,nspectrum) nspectrum type(freq) freq= np.array(freq) freq type(nspectrum) nspectrum = nspectrum.flatten() # improve the plot by adding periods in number of days rather than frequency import pandas as pd results = pd.DataFrame({'freq': freq, 'nspectrum': nspectrum}) results['period'] = results['freq'] / (1/365) plt.semilogy(results['period'], results['nspectrum']) # improve the plot by convertint the data into grouped per day to avoid peaks results['period_round'] = results['period'].round() grouped_day = results.groupby('period_round')['nspectrum'].sum() plt.semilogy(grouped_day.index, grouped_day) #plt.xticks([1, 13, 26, 39, 52]) My end result is this : Result of Fourier Trasformation for Data
My question is, what does this eventually show for our data, and intuitively what does the spike at the last section mean?What can I do with such result? Thanks in advance all!
3Related questions 0 Strange FFT output python 3 output of a fft expressed as a fourier series in terms of sine/cosine 1 numpy Fourier transformation produces unexpected results Related questions 0 Strange FFT output python 3 output of a fft expressed as a fourier series in terms of sine/cosine 1 numpy Fourier transformation produces unexpected results 3 Understanding FFT output in python 5 Python: Designing a time-series filter after Fourier analysis 2 Unexpected Fourier Transform result in Python Numpy 1 Fourier Transformation in Python 3 Fourier transformation (fft) for Time Series, but both ends of cleaned data move towards each other 6 Fourier Transform Time Series in Python 0 Signal processing with Fourier transform Load 7 more related questions Show fewer related questions
Reset to default