Why is NaN shown after fft is keyed in the command window?

2 views (last 30 days)
I am trying to calculate the Fast Fourier Transform (fft) using matlab.
CSV file was successfully read. However, NaN appeared after I keyed 'p = abs(fft(signaldata,N))/N);' into the command window.
Furthermore, I have issues when plotting the graph.
plot(fv,p)
where fv = 1x513, and p = 1024x2.
The following error was prompted.
"Error using plot
Vectors must be the same lengths."
I understand that the matrix of the two variables are imbalance.
Can anyone advice what should I do to solve the problems above? Thanks in advance!

Accepted Answer

dpb
dpb on 13 Nov 2015
Probably there's a missing value in the .csv file that was imported as NaN. What does
all(isfinite(signaldata(:)))
return? If it's not '1' (True) then the above supposition is correct and those NaN values are what are propogated thru the the result. Find out how many and where they are...
sum(isnan(signaldata(:)))
[r,c]=find(isnan(signaldata))
Presuming it's only an end effect or somesuch, remove these rows--
signaldata(r,:)=[];
See
doc fft
for an example of how to do the PSD and the frequency vector from the double-sided fft result returned by Matlab to solve your length issues. After the above you may want to pad or fix the input data stream first.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!