After using "FFT" getting NAN. Why?

조회 수: 58 (최근 30일)
Danish Ahmad
Danish Ahmad 2019년 4월 11일
댓글: Star Strider 2020년 9월 2일
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?
  댓글 수: 2
Jan
Jan 2019년 4월 11일
Please use the buttons to format the code. It is a good idea to post a question in the best readable format.
Omit the brute clearing header "clc; close all; clear all". This is a waste of time and cargo-cult-programming. If you want to keep your workspace clean, use functions.
Without knowing, what the contents of v is, there is no chance to understand, why abs((fft(v))) is NaN. So please show us, what your input data are.
Danish Ahmad
Danish Ahmad 2019년 4월 14일
Thank you for your response.
Regards

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 4월 11일
... 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.
  댓글 수: 12
Diego Soto Chávez
Diego Soto Chávez 2020년 9월 2일
Hi Star Strider
know you another option like "fillmissing" but for previosly versiones of matlab? Thanks!!
Star Strider
Star Strider 2020년 9월 2일
Something like this woulld likely work:
t = 1:8
y = rand(size(t))
y([3 5]) = NaN
ti = t;
ti(isnan(y)) = []
y(isnan(y)) = []
ynew = interp1(ti, y, t)
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by