I've recently studied Fourier transform and I've applied it on a time series data, since I am still confused between time and frequency domain I doubt the authenticity of my code to calculate Fourier transform. The data used in analysis is in the link.
Following is the code that I've used to compute and visualize the transform:
df_new = pd.read_csv('df_avn.csv', usecols = ['Date', 'Close'], parse_dates = True, index_col = ['Date']) t = np.linspace(0,24*60*60, 55) s = df_new.values sns.set_style("darkgrid") plt.ylabel("Amplitude") plt.xlabel("Time [s]") plt.plot(t, s) plt.show() fft = scipy.fftpack.fft(s) T = t - t # sample rate N = s.size # 1/T = frequency f = np.linspace(0, 1 /(T), N) f = f * 1000 sns.set_style("darkgrid") plt.ylabel("Amplitude") plt.xlabel("Frequency [mHz]") plt.plot(f[:N // 2], np.abs(fft)[:N // 2] * 1 / N) plt.show()
To explain what I've done in the above code, since the data is has of daily frequency for a total of 55 days I've converted days to seconds using
24*60*60 and plotted it against the original series. As shown here
My first concern is that the implementation of Fourier Transform as demonstrated above is it correct? If yes then we can move on to the following next two questions.
I am having trouble in explaining the three peaks in transformed graph. What I think is that these three peaks have highest significance, is it that the correct interpretation? Furthermore how would you explain the frequencies at which these three peaks occur to a layman.
Is it more appropriate to use a data converted in frequency domain for clustering (using e.g. Kmeans) or is it appropriate to use time series data without converting to frequency domain?