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
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); % FFT 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));