MATLAB: After using “FFT” getting NAN. Why

fftnan

clc
close all
clear all
%%
data = xlsread('freq15.xlsx','Group Name #2');
v= data(:,1);
plot (v);
title('Voltage signal with noise')
xlabel('Samples')
ylabel('Amplitudes')
%%
%plot magnitude specturm of a signal
clc
format long
X_mag=abs((fft(v)))
figure(1)
plot(X_mag)
xlabel('DFT Bins')
ylabel('Magnitude')
%%
Above is a code using FFT in MATLAB. The outcome of the code is NAN+NANi. How to get rid of NAN or what is the reason of this outcome?

Best Answer

... what is the reason of this outcome?
You probably either have a NaN in your data, or an empty cell. Both will appear as NaN in the xlsread output.
If that is the situation, your best option is to interpolate using the fillmissing (link) function (R2016b and later releases). The reason is that Fourier transforms require regularly-sampled time-domain signals for them to provide reliable output. Omitting the NaN value disrupts this regularity and results in an inaccurate fft result. Interpolating the NaN values will not provide as accurate a result has having the original value, however it is the only reliable alternative.