Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFT: Match samples to frequency

let us assume,

  • I have a vector t with the times in seconds of my samples. (These samples are not equally distributed on the time domain.

  • Also I have a vector data containing the samplevalues at the time t.

  • t and data have the same length.

If I plot the graph some sort of periodical signal is obtained.

now I could perform: abs(fft(data)) to get my spectrum, which is then plotted over the amount of data points on the x-axis.

How can I obtain my spectrum regarding the times in vector t and plot it? I want to see which frequencies in 1/s or which period in s my signal contains.

Thanks for your help.

like image 602
Vladimir S. Avatar asked Jan 19 '26 12:01

Vladimir S.


1 Answers

[Not the OP's intention]: FFT will give you the spectrum (global) for any number of input data points. You cannot have a specific data point (in time) associated with parts (or the full) spectrum.

What you can do instead is use spectrogram and obtain the Short-Time Fourier Transform (STFT). This will give you a NxM discrete grid of time-frequency FT values (N: FT frequency bins, M: signal time-windows).

By localizing the (overlapping) STFT windows on your data samples of interest you will get N frequency magnitude values, thus the distribution of short-term spectrum estimates as the signal changes in time.

See also the possibly relevant answer here: https://stackoverflow.com/a/12085728/651951

EDIT/UPDATE:

For unevenly spaced data you need to consider the Non-Uniform DFT (and Non-uniform FFT implementations). See the relevant question/answer here https://scicomp.stackexchange.com/q/593

The primary approaches for NFFT or NUFFT, are based on creating a uniform grid through local convolutions/interpolation, running FFT on this and undoing the convolutional effect of the interpolation filter.

You can read more:

  • A. Dutt and V. Rokhlin, Fast Fourier transforms for nonequispaced data, SIAM J. Sci. Comput., 14, 1993.
  • L. Greengard and J.-Y. Lee, Accelerating the Nonuniform Fast Fourier Transform, SIAM Review, 46 (3), 2004.
  • Pippig, M. und Potts, D., Particle Simulation Based on Nonequispaced Fast Fourier Transforms, in: Fast Methods for Long-Range Interactions in Complex Systems, 2011.

For an implementation (with an interface to MATLAB) try NFFT and possibly its parallelized version PNFFT. You may find a nice walk-through on how to set-up and use here.

like image 166
gevang Avatar answered Jan 21 '26 08:01

gevang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!