3
votes

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.

2
This is better suited for dsp.stackexchange.com. But I don't think the Fourier transform is well suited to this problem, at least in its basic form it assumes the samples are evenly distributed in time.mtrw

2 Answers

4
votes

[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:

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.

2
votes

You can resample or interpolate your sample points to get another set of sample points that are equally spaced in t. The chosen spacing or sample rate of the second set of equally spaced sample points will allow you to infer frequencies to the result of an FFT of that second set.

The results may be noisy or include aliasing unless the initial data set is bandlimited to a sufficiently low frequency to allow interpolation. If bandlimited, then you might try something like cubic splines as an interpolation method.

Although it may look like one can get a high FFT bin frequency resolution by resampling to a larger number of data points, the actual useful resolution accuracy will be more related to the original number of samples.