0

I'm trying to calculate the Fourier transform of non periodical data in python, with non periodical I mean this. Usually we use have periodical data:

x=[0,1,2,3,4,5,6,7] 
y=[1,0,2,0,1,0,1,0]

And the Fourier transform and the frequency domain can be obtained easily,

from scipy.fft import fft, fftfreq, fftshift

f=fftfreq(len(x), dx)

fy=fft(y)

And with that we can easily calculate the Fourier transform using scipy fft, but in the case our data is not exactly periodical, for example,

x=[0,1,1.5,1.7,3,4,5...]
y=[...]

Anyone have some idea of how can be possible to obtain the Fourier transform using python if it's possible, or the mathematics principles that are used.

Euler
  • 121
  • 6
  • I found this is a good question for several phenomena that could need pattern recognition analysis. For instance in trading, the sequence of trades and their volumes the time of which obviously is not pre-determined. – fede72bari Aug 25 '22 at 09:11

2 Answers2

3

For such data, you can use least-squares spectral analysis. SciPy includes the function scipy.signal.lombscargle that computes the Lomb-Scargle periodogram. The docstring has an example; see Discrete fourier transformation from a list of x-y points for another example.

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
1

You can't do an FFT of an unevenly sampled signal. That invalidates the assumptions of the math the FFT is based upon.

You'll have to resample the signal so you have evenly spaced samples.

Read this for more information: https://dsp.stackexchange.com/questions/8488/what-is-an-algorithm-to-re-sample-from-a-variable-rate-to-a-fixed-rate

ZVY545
  • 384
  • 1
  • 13