Applying Fourier Transform on Time Series data and avoiding aliasing

8k Views Asked by At

I am willing to apply Fourier transform on a time series data to convert data into frequency domain. I am not sure if the method I've used to apply Fourier Transform is correct or not? Following is the link to data that I've used.

After reading the data file I've plotted original data using

t = np.linspace(0,55*24*60*60, 55)
s = df.values
sns.set_style("darkgrid")
plt.ylabel("Amplitude")
plt.xlabel("Time [s]")
plt.plot(t, s)
plt.show()

Since the data is on a daily frequency I've converted it into seconds using 24*60*60 and for a period of 55 days using 55*24*60*60

The graph looks as follows: Original Time Series

Next I've implemeted Fourier Transform using following piece of code and obtained the image as follows:

#Applying Fourier Transform
fft = fftpack.fft(s)

#Time taken by one complete cycle of wave (seconds)
T = t[1] - t[0] 

#Calculating sampling frequency
F = 1/T

N = s.size

#Avoid aliasing by multiplying sampling frequency by 1/2 
f = np.linspace(0, 0.5*F, N)

#Convert frequency to mHz
f = f * 1000

#Plotting frequency domain against amplitude
sns.set_style("darkgrid")
plt.ylabel("Amplitude")
plt.xlabel("Frequency [mHz]")
plt.plot(f[:N // 2], np.abs(fft)[:N // 2])  
plt.show()

Transformed

I've following questions:

I am not sure if my above methodology is correct to implement Fourier Transform.

I am not sure if the method I am using to avoid aliasing is correct.

If, what I've done is correct than how to interpret the three peaks in Frequency domain plot.

Finally, how would I invert transform using only frequencies that are significant.

1

There are 1 best solutions below

0
On

While I'd refrain from answering your first two questions (it looks okay to me but I'd love an expert's input), I can weigh in on the latter two:

If, what I've done is correct than how to interpret the three peaks in Frequency domain plot.

Well, that means you've got three main components to your signal at frequencies roughly 0.00025 mHz (not the best choice of units here, possibly!), 0.00125 mHz and 0.00275 mHz.

Finally, how would I invert transform using only frequencies that are significant.

You could just zero out every frequency below a cutoff you decide (say, absolute value of 3 - that should cover your peaks here). Then you can do:

below_cutoff = np.abs(fft) < 3
fft[below_cutoff] = 0
cleaner_signal = fftpack.ifft(fft)

And that should do it, really!