FFT with variable sampling frequency

Hello members of the Julia community,

Is it possible to use the FFTW package (or any other Julia package) to perform an FFT on non-uniformly-sampled data? It seems that the functions provided in this package all assume uniform sampling.

I have a 1-dimensional time-series (about 8k units long) and an accompanying vector of time values, and I’d like to extract peaks in the frequency.

FastTransforms.jl has a NUFFT

I believe there’s a few other packages, I found a NUFFT.jl

2 Likes

You want other packages (that are built on top of FFTW in most cases) for this. There are several to choose from: FastTransforms, NFFT, FINUFFT, …

3 Likes

Okay, thanks! Looks like I should just hop over to https://juliaobserver.com/packages/.

Note that you want an inverse NFFT here. You can approximate that using an adjoint NFFT but you need to use an additional density compensation (quadrature weights)

1 Like

And feel free to ask questions on NFFT.jl. It should be pretty solid right now and has different ways to adjust the performance of the transform.

2 Likes

Hi @tknopp, the readme for NFFT.jl does not seem to help here. Could you link me to a MWE in order to get a frequency spectrum from my time series?

My signal typically looks like this, and if I restrict to the last ~60 time units, I expect to get a pretty sharp peak in the frequency domain.
image

The Δt varies with time like this (hence the need for a nonuniform FFT)
image

Yes the NFFT description will not really question is more a signal processing one and the NFFT will likely only be one building block in getting the correct frequency.

One first question before we can go into detail: Are you aiming for a single frequency or is it that you are looking also at frequency changes over time?

If this is about a single frequency then I see some issues with your signal since it is changing the amplitude over time. So probably you should start doing an NFFT just over that phase where the amplitude remains constant.

A further thing that you will need is a windowing function since your sampling rate will not necessary match to the frequency you are looking for.

If you take these things into account and look at the signal from point 50-120 it seems that the deltaT is pretty small and thus I would start with an FFT to look if you get something in the correct region. Once you have that, you can switch to the NFFT.

I am actually just aiming for a single frequency, corresponding to the constant-amplitude sinusoidal signal after t>≈ 60. I don’t care about the frequency in the early part of the signal, or how it changes with time.

I am sure this is just signal processing 101, but I was under the impression that my Δt being variable will mess things up, for example if I were to average the sampling frequency over the last ~half of the interval. This is why I was looking into non-uniform FFTs. It seems like this won’t be such a big deal, though, and that I should just try to use a regular FFT with, say, an average sampling frequency?

using the NFFT is absolutely the right thing to do here but I wanted to give you some hints on the many other pitfalls one can make here.

What I got is that you are aiming for a single frequency but are you 100% sure that the underlying data really only contains a single frequency? When I look at that data, I would start with a short time Fourier transform (which includes the windowing) and then look at the frequency over time. In a second step you can then exchange the internal FFT by the NFFT. But its important to keep the windowing.

Ok, I will try to window as well – the thing is, though, that even if there are indeed other frequency signals I only care about the obvious one!

Hi, I’ve just found this discussion and I have an almost identical problem. Which packages and functions did you use at the end? Thank you in advance!

1 Like