1

I have a dataset containing the daily sum of news articles for specific topics since 1995 (for this example, I'm trying to analyze the topic "Soccer, Football"). I am trying to use the fast fourier transform (fft) but am not sure how to interpret the results. How am I supposed to convert the frequency to a daily scale?

from scipy.fftpack import fft
N = 8335 # lenth of times series (days)
# Nyquist Sampling Criteria
T = 1/8335 # inverse of the sampling rate
x = np.linspace(0.0, 1.0/(2.0*T), int(N/2))

# FFT algorithm
yr = fft(array) # "raw" FFT with both + and - frequencies
y = 2/N * np.abs(yr[0:np.int(N/2)]) # positive freqs only

# Plotting the results
plt.plot(x, y)
plt.figsize=(25,10)
plt.ylim(0,.08)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Vibration (g)')
plt.title('Soccer,Football');

The results: See here 3 spikes in the power spectrum but in audio frequency terms

How can I convert the three frequencies to understand the lengths of the cycles in days?

Dror M
  • 63
  • 8
  • Tried @Prieur Julien's solution - I'm not quite sure what is the output this gave me. I have an array with n values (in this case one per each day), with the values rising up to 4.999, only to fall to -4.999 and then rise again to end at 0... what is the significance of these values? – Dror M Sep 18 '19 at 14:31
  • Since the signal is of length 8335 days, its period for the DFT is 8335 days. Hence the frequency of bin 1 is 1 per 8335 days, or 1/8335 day^-1. The second bin is 2/8335 and so on. For instance, the week period (1/7 days^-1) is near the bin 8335/7=1190, the month period is near the bin 8335/30=278. Hence the small first, the second peak and third peak conrespond to monthly, weekly, and twice-a-week periods. You may try to apply a [window function](https://en.wikipedia.org/wiki/Window_function) to limit the effects of considering the signal as a periodic signal of period 8335 days. – francis Sep 19 '19 at 19:28
  • Perfect! Thanks :) – Dror M Sep 21 '19 at 12:35
  • Take a look at this and see if it helps, https://stackoverflow.com/questions/52690632/analyzing-seasonality-of-google-trend-time-series-using-fft/52691914 – DrM Sep 23 '19 at 14:39
  • Thanks! @DrM Helpful – Dror M Sep 24 '19 at 22:42
  • Great, don't forget to vote! Thank you – DrM Sep 25 '19 at 17:38

0 Answers0