I am trying to perform an FFT of a non-uniformly sample signal. My input comes from Simulink and PLECS which uses variable-time solver.

So far, I have used resample function from Matlab to resample the values to a uniform sample rate and perform the FFT but with this set of values I cannot get it to work no matter what. I guess it's due to the nature of the signal which has a lot of jumps but I am not sure.

In this particular case I'd like to identify the component at 300Hz but for general purpose it can be any component. The code I tried is below if anyone wants to give it a try and help me. For comparison I also have the results from PLECS scope which indicates the 300Hz components

Link to raw data

Link to PLECS FFT data

clear all;
close all;
tab = csvread('data1.csv',1,0);
tout = tab(:,1);
in = tab(:,2);
fSamp = 1e6;
% Resampling
a(1) = (in(end)-in(1)) / (tout(end)-tout(1));
a(2) = in(1);
% detrend the signal
indetrend = in - polyval(a,tout);
[ydetrend,ty] = resample(indetrend,tout,fSamp,'linear');

out = ydetrend + polyval(a,ty);
fr_des = 300;
amp = abs(fft(out))/length(out);
phs = unwrap(angle(fft(out)));
Fv = linspace(0, 1, fix(length(out)/2)+1)*fSamp/2;           % Frequency Vector
Iv = 1:length(Fv);                                      % Index Vector                                          % Desired Frequency
ampv = amp(Iv);                                         % Trim To Length Of ‘Fv’
phsv = phs(Iv);                                         % Trim To Length Of ‘Fv’
ap = [ampv(:) phsv(:)];                                 % Amplitude & Phase Matrix
ap_des = interp1(Fv(:), ap, fr_des, 'linear');
FFT = ap_des(1)*exp(1i*ap_des(2));
  • $\begingroup$ You have to be sure about the nature of the signal in order to successfully apply nonuniform to uniform conversion. Is it bandlimited enough? if not, the conversion from nonuniform samples to uniform ones may fail. So as a first step, you should ensure that nonuniform to uniform conversion works as expected. $\endgroup$
    – Fat32
    Commented Aug 20, 2018 at 10:23
  • $\begingroup$ You have jitter at the 5th or 6th decimal place, you should be fine for a 300Hz component even without interpolation. Can you please post a plot of the spectra that you get, that you think is not correct? $\endgroup$
    – A_A
    Commented Aug 20, 2018 at 10:50
  • $\begingroup$ @Fat32 What do you mean by "bandlimited enough"? $\endgroup$
    – MarkoP
    Commented Aug 21, 2018 at 15:09
  • $\begingroup$ @A_A So you say that I can proceed with FFT even if the sampling is not fixed since the time step difference is very small? $\endgroup$
    – MarkoP
    Commented Aug 21, 2018 at 15:10
  • $\begingroup$ @MarkoP bandlimited enough means bandlimited to half the sampling rate that's what is enough. As just bandlimited does not suffice... $\endgroup$
    – Fat32
    Commented Aug 21, 2018 at 15:18

1 Answer 1


I am trying to perform an FFT of a non-uniformly sample signal. My input comes from Simulink and PLECS which uses variable-time solver.

Assuming that the first column in the data provided is your time variable ($t$) in units of seconds, the variable-time solver introduces a very small jitter.

(All code in Octave)

x = csvread("somefile.csv");
time_variable = x(3:end); %Skipping the first few samples as the solver settles.
plot(diff(time_variable)); %Ideally, this should return a flat plot at the sampling period, but that is not what we have here.

This results in:

enter image description here

Where you are sampling with at least a sampling period of something like $Ts \approx 1.68e-07$ extending to $Ts \approx 7.65e-07$.

The period of a 300Hz sinusoid that you are interested in is something like $0.00333 \ldots$ and the worst case scenario given above introduces an uncertainty of $\approx 0.022 \%$. That is per-cent.

Now, I am not sure which waveforms you are trying to obtain the spectrum of, but the second one is the one with the most discontinuities (the control signal?) and its spectrum looks like:

Fs = 1/7.6587e-07;
NFFT = 512;
FreqVec = Fs.*(0:(NFFT-1))./(NFFT-1);
xlabel("Frequency (Hz)");ylabel("Amplitude");grid on;

enter image description here

Where as you can see, I have used the Sampling Frequency ($Fs$) of the worst case scenario, again, assuming that the first column contains the time variable in seconds.

Hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.