MATLAB Fouriertransform with nunequidistant values

1 view (last 30 days)
Hello there,
I am currently working on a frequencyanalysis. For this, I have a signal with a non-static signaling frequency. In other words, I have one vector 'y' with measurement (pixel with maximum intensity) and one vector 'time' with times inbetween measurements. Each value in the measurements vector corresponds to one measurements.
The sampling frequency is about 5 Hz, which is why I wrote this fft()-code:
load('y');
load('times')
Fs = 5;
Ts = 1/Fs;
nfft = length(y);
dt = 0:Ts:Ts*nfft-Ts;
ff = fft(y);
ff(1) = [];
nfft = length(ff);
ffabs = abs(ff(1:floor(nfft/2)+1));
freq = (1:length(ffabs))*Fs/length(y);
subplot(2,1,1);
plot(dt,y);
subplot(2,1,2)
plot(freq,ffabs);
This does the basic fouriertransform but does not incorperate the actual times for each measurement. The Vector times is built up of the times in secondy after the beginning of the measurement ([0.886769 1.125059 1.301065 1.497016 1.69091 1.885543 2.061231 ...]).
Does anyone have an idea how to incorperate these times into the code. Help is verymuch appreciated!!
Cheers

Answers (3)

dpb
dpb on 1 Jul 2018
The simplest route is to interpolate to a fixed sample rate and apply the FFT to that series.
Alternatively there's a submission at FEX of the NUFFT FEX 25135

Star Strider
Star Strider on 1 Jul 2018
I would use the Signal Processing Toolbox resample (link) function to interpolate it to a regularly-sampled time base. There is an option to use a time vector created by the linspace function. Then use fft to take the Fourier transform. (If I remember correctly, there are File Exchange contributions that can deal with non-uniformly sampled data. Using reshape is likely easier.) The resample function uses an anti-aliasing filter to avoid the resampling problems encountered using interp1 alone, so use resample if you are going to be doing further signal processing on your data.

Vilnis Liepins
Vilnis Liepins on 2 Jul 2018
Edited: Vilnis Liepins on 2 Jul 2018
You can apply File Exchange program 'nedft' available on https://se.mathworks.com/matlabcentral/fileexchange/11020-extended-dft.
load('y');
load('times')
Fs = 5;
Ts = 1/Fs;
nfft = length(y);
fr=[-ceil((nfft-1)/2):floor((nfft-1)/2)]/(nfft*Ts); % Uniform set of frequencies in [-1/2Ts,1/2Ts[
ff=fftshift(nedft(y,times,fr)); Calculate DFT on fr and fftshift

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!