análisis de frecuencia con datos espaciados de manera desigual en Python

I have a signal generated by a simulation program. Because the solver in this program has a variable time step, I have a signal with unevenly spaced data. I have two lists, a list with the signal values, and another list with the times at which each value occurred. The data could be something like this

npts = 500
f1 = 0.5 
f2 = 0.6

I would like to be able to perform a frequency analysis on this signal using python. It seems I cannot use the fft function in numpy, because this requires evenly spaced data. Are there any standard functions which could help me find the frequencies contained in this signal?

preguntado el 09 de marzo de 12 a las 15:03

3 Respuestas

The most common algorithm to solve such things is called a Least-Squares Spectral analysis of frequencies. It looks like this will be in a future release of the scipy.signals package. Maybe there is a current version, but I can't seem to find it... In addition, there is some code available from Astropython, which I will not copy in it's entirety, but it essentially creates a lomb class which you can use the following code to get some values out.. 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.)

respondido 09 mar '12, 15:03

There do seem to be a couple of indenting problems in the lomb class, but otherwise it works just as I'd hoped! - Katt

Link to gist with fixed indentation: - user2398029

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

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

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

escoge tu k's ranging from 0 a 2*pi / min separation in x.

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

For a test case, use something for which you known the correct answer, c.f., a single cos( k' * x ) para algunos k', or a Gaussian.

contestado el 05 de mayo de 15 a las 18:05

Please consider answering with an example output, as it will help a lot of users how will find this question. - Huá dé ní 華得尼

This is just a schematic of the function. The F(k) will be complex values at whatever set of k's that you choose. - DrM

One more comment, this method treats the input set of independent variables as a set of delta functions, much the same as implied in a FFT. - DrM

An easy way out is to interpolate to evenly-spaced time intervals

Respondido el 06 de Septiembre de 18 a las 15:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.