Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying Fourier Transform on Time Series data and avoiding aliasing

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.

like image 478
Furqan Hashim Avatar asked Nov 05 '18 17:11

Furqan Hashim


People also ask

Why do we use Fourier transform in time series?

The Fourier Transform is a great tool for extracting the different seasonality patterns from a single time series variable. The Fourier Transform allows you to do exactly this: describing a time series as a frequency rather than as a function of time.

What is meant by a Fourier transform of a time varying signal?

A Fourier transform (FT) is a mathematical transform that decomposes functions depending on space or time into functions depending on spatial frequency or temporal frequency. That process is also called analysis.

What is Fourier time series?

Fourier analysis is the process of obtaining the spectrum of frequencies H(f) comprising a time-series h(t) and it is realized by the Fourier Transform (FT). Fourier analysis converts a time series from its original domain to a representation in the frequency domain and vice versa.

What is aliasing in DFT?

When frequencies higher than 1/1∆t are present in a signal that undergoes DFT, aliasing occurs. Typically this leads to folding back of high frequency components to lower frequencies.

How can Fourier transform be used to organize data?

Time series and signals are natural ways to organize data. The Fourier Transform extracts frequency information embedded in data. There are countless use cases for this approach in fields such as: audio engineering, physics, and data science.

What is a fast Fourier transform in Python?

You'll also see how to execute a Fast Fourier Transform using NumPy on a famous time series data set. The official definition of the Fourier Transform states that it is a method that allows you to decompose functions depending on space or time into functions depending on frequency.

What is the continuous-time Fourier transform (DTFT)?

Below is the continuous-time Fourier transform of . The DTFT is a collection of copies of the continuous-time Fourier transform, spaced apart by the sampling frequency, and with the frequency axis scaled so that the sampling frequency becomes . Here's the DTFT of .

Is it possible to do practical Fourier analysis?

As such, calculations of the Fourier transform are readily available to those that would like to make use of them. Unfortunately, the education around how to do practical Fourier analysis has become something of a dark art, which is often picked up in an ad hoc manner in postgraduate studies.


Video Answer


1 Answers

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!

like image 135
Dominik Stańczak Avatar answered Oct 14 '22 02:10

Dominik Stańczak