MATLAB Answers

0

How to find FFT of a non-uniformly sampled data?

Asked by Vasav Ayush on 9 Nov 2017
Latest activity Commented on by Joseph Fox-Rabinovitz on 30 Apr 2019
I have a vibration data in time domain and want to convert it to frequency domain.However my data is not uniformly sampled, so I am having trouble applying fast fourier transform to it. I have attached my excel data file.Can you guys please help

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Star Strider
on 9 Nov 2017
 Accepted Answer

Your data are very close to being uniformly sampled. The mean difference in sampling times (sampling interval) is 976.5623e-006, and the standard deviation is 496.2100e-009. You can interpolate them with the Signal Processing Toolbox resample function to be entirely uniformly sampled, then do the Fourier transform:
[D,S,R] = xlsread('vibration.xls');
t = D(:,1);
v = D(:,2);
tstats = [mean(diff(t)) std(diff(t))] % Information Only
tr = linspace(min(t), max(t), length(t)); % Uniformly-Sampled Time Vector
vr = resample(v, tr); % Resampled Signal Vector
L = length(tr); % Signal Length
Ts = mean(diff(tr)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTvr = fft(vr)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(1)
plot(Fv, abs(FTvr(Iv))*2)
grid
You can use the File Exchange contribution NUFFT, NFFT, USFFT (link) if you want, but you probably don’t need it here.

  4 Comments

Show 1 older comment
My pleasure.
The fft function calculates the two-sided Fourier transform, and the energy of the signal is divided evenly between the two halves. Here we are looking at the one-sided Fourier transform, so in order to represent the amplitudes correctly, it is necessary to multiply the amplitudes by 2.
// just a comment to those wondering the same:
The resampling step as written above is not necessary since both time vectors have the same size. Plotting vr and v shows the same data.
Perhaps an interpolation
y = resample(v, t, 1/mean(diff(t)) );
is more appropriate?
Cheers,
Rather than
tr = linspace(...
vr = resample(v, tr);
you probably want to use
[vr, tr] = resample(v, t);

Sign in to comment.