# transform time series different length and sampling rate with frequency domain

i want to transform my time series (each same scale) to frequency domain. There are 2 things to conside:

1. some time series are longer then the other
2. i have different measuring intervals which means e.g. one time series measures sometimes 2 times an hour, another one measures 3 times an our and so on.

i have 20 time series and the sampling rate vary for each time series. i want to do hierarchical clustering with these 20 time series (ID). Here is an example how my data looks like:

ID  DAY  MONTH HOUR  VALUE
1    1     6   00:30   5
1    1     6   00:58   5.1
1    1     6   1:23    4.2
........................
2    1     6   00:02   2
2    1     6   00:28   1.8
............................
20   1     6   23:55    1.4


can i use frequency transformation and which transformation is useful (fourier transformation). I am new to this topic and i saw someone already asking a similar question, but the situation is not the same (for example i have different sampling rate)

• Can you list out the lengths and rates that you have (as it may simplify what you need to do). The frequency domain will extend out to the sampling rate (uniquely to half the sampling rate if your data is real), so the higher rate data will extend further; is your goal to have the same frequency index for all data (such that the results can be superimposed on the same plot, with some of those plots extending further as I mentioned)? Commented Apr 7 at 11:37
• my goal is to do a cluster analysis with these time series and i want to transform my series to frequency domain before i do that: I have measurement which in average 2 times per hour. i have 20 time series and some of them are measureing longer (1 day longer) or in aveage more or less then 2 times a hour Commented Apr 7 at 11:43
• so if i understand it correctly that i can use frequency domain and its not a problem that my data have different length and different measure intervals? Commented Apr 7 at 11:45
• so in any one series, is it sampled consistently or does the sampling rate vary? (Please edit your original question with these details so others don't have to read through the comments). Also add the specific processing you will need to do with the data, an example would be helpful as clustering analysis is a little broad. Commented Apr 7 at 11:54
• sorry and thank u for u response, i added more information. the sampling rate vary and i want to do hierarchical clustering to analyse similar time series. I want to transform the time series to the frequency domain, extract a feature (for example mean) and the use this value to do hierarchical clustering. Does this make sense? Commented Apr 7 at 14:09

Consider using the Lomb-Scargle Periodogram which is useful for spectral analysis of unevenly spaced data in the time domain. Jacob VanderPlas provides an intuitive overview of the algorithm in his publication in the Astrophysical Journal, May 11 2018 "Understanding the Lomb-Scargle Periodogram".

The algorithm is implemented in MATLAB as plomb and in Python's scipy.signal as lombscargle

Another Jacob, Jacob Svensson, has provided a python implementation to have an equivalent interface to MATLAB's plomb, also copied here:

import numpy as np
from scipy.signal import lombscargle

def lomb(t, y):
"""
Compute the Lomb-Scargle periodogram

Inputs
t : sample times
y : measurement values

Outputs
f   : frequency vector
pxx : power spectral density (PSD) estimate

Inputs are assumed to be vectors of type numpy.ndarray.
"""
n = t.size
ofac = 4  # Oversampling factor
hifac = 1
T = t[-1] - t[0]
Ts = T / (n - 1)
nout = np.round(0.5 * ofac * hifac * n)
f = np.arange(1, nout+1) / (n * Ts * ofac)
f_ang = f * 2 * np.pi
pxx = lombscargle(t, y, f_ang, precenter=True)
pxx = pxx * 2 / n
return f, pxx

• thank u very much!! Commented Apr 9 at 17:58
• @user71812 glad it helped! If this is sufficient toward what you were looking for, please mark as correct so we can close this out Commented Apr 9 at 22:16