# compensation for irregular timestep for FFT

I want to run a clustering algorithm (svm, knn) on the ferquency spectrum data of a temperature sensor that published at irregular times. Here is the temperature data to take the FFT: I got the mean frequency for this temperature data as well as every temp sensor in the dataframe the average is every 18mins, longest distance between 2 points is 3hrs:

# group by short id
groups = df.groupby('id')
time_diff = groups.apply(lambda df: df.published_at.diff().mean())


Isolated the graphed temp data in a series:

signal = df.loc[df['_id'] == 'A1']['temperature']


Stored size of signal and mean sampling frequency as variables:

# sampling frequency:
Fs = time_diff[:1]
Fs
Out: 00:18:54.085526

# size
S = signal.size
Then took the fft and calculated dBs

X = np.fft.fft(signal)
X_db = 20*np.log10(2*np.abs(X)/S)
And plotted the results:

plt.plot(X)
plt.show() plt.plot(X_db)
plt.show() These graphs intuitively do not look like they correspond to the original data. The objective with the fft is to then classify the data using SVM, however, I am not sure which variant fft is appropriate, nor if using the mean time frequency is either.

• Just an idea. – jojek Jan 25 '18 at 21:28

## 2 Answers

You might want to look at the non uniform DFT

https://en.wikipedia.org/wiki/Non-uniform_discrete_Fourier_transform

Google (nonuniform fft) and many useful references will be returned

and also

https://scicomp.stackexchange.com/questions/593/how-do-i-take-the-fft-of-unevenly-spaced-data

One option, in addition to the Non-uniform DFT that has been mentioned, is simply interpolating the data on a regularly-spaced grid by using a timestep approximately the same size as the smallest timestep, and then taking the DFT on the interpolated data.