Frequency analysis with unevenly distributed data in python

I have a signal generated by a simulation program. Since the solver in this program has a variable time step, I have a signal with unevenly distributed data. I have two lists, a list with signal values โ€‹โ€‹and another list with the time at which each value occurred. The data may be something like this

npts = 500 t=logspace(0,1,npts) f1 = 0.5 f2 = 0.6 sig=(1+sin(2*pi*f1*t))+(1+sin(2*pi*f2*t)) 

I would like to be able to perform frequency analysis of this signal using python. I can't seem to use the fft function in numpy because it requires evenly distributed data. Are there any standard functions that could help me find the frequencies contained in this signal?

+4
source share
2 answers

The most common algorithm for solving such problems is called Least Squares Spectral Analysis. It looks like it will be in a future release of the scipy.signals package . Maybe there is a current version, but I canโ€™t find it ... Also, there is some code from Astropython that I wonโ€™t copy it entirely, but it essentially creates a lomb class, which you can use the following code to get some values. What you need to do is the following:

 import numpy import lomb x = numpy.arange(10) y = numpy.sin(x) fx,fy, nout, jmax, prob = lomb.fasper(x,y, 6., 6.) 
+6
source

Very simple, just find the formula for the Fourier transform and implement it as a discrete sum over your data values:

given a set of values f(x) for some set of x , then for each frequency k ,

 F(k) = sum_x ( exp( +/-i * k *x ) ) 

select k between 0 and 2*pi / min separation in x .

and you can use 2 * pi / max(x) as the increment size

For the test case, use something for which you know the correct answer, cf, one cos( k' * x ) for some k' or gauss.

+2
source

Source: https://habr.com/ru/post/1400594/


All Articles