MATLAB Answers

Dealing with NaN values in FFT

50 views (last 30 days)
Hi, I'm working with a large data set of voxel information from MRI scans of multiple subjects, and as part of the analysis I use FFT. Prior to this, the data already goes through some modifications, removing specific values deemed too low (insignificant data) and replacing it with NaN values. After checking the results I realized there is an issue with FFT and NaN values. Is there some solution or workaround that someone perhaps knows that might help resolve this issue?


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 25 Jul 2020
If you have R2016b or later, the fillmissing function is an option.


Show 1 older comment
Star Strider
Star Strider on 26 Jul 2020
Noiithing similar to nanmean is appropriate for the fft function, since it destroys the required regularity of the sampling points and data (with regularly-sampled data and constant sampling frequency).
It may be possible to eliminate the NaN values and still get the Fourier transform using the nufft function (R2020a and later). I have no experience with it (I have not yet used it) so my ability to help you with it is limited. It would be necessary to eliminate the corresponding points from both the signal vector and time (or other independent variable) vector.
Another option is to eliminate the NaN values and then use the resample function to resample them to a new time vector, then use fft. (This effectively interpolates, so that may not be an option for you.)
noam edelshtein
noam edelshtein on 27 Jul 2020
Thats what I thought, but hoped to maybe be wrong. I'll look into the nufft function, it may help.
Thank you for the help, in this thread and many other answers you've given in other threads that have helped me!
Star Strider
Star Strider on 27 Jul 2020
As always, my pleasure (here, and for the others as well)!

Sign in to comment.

More Answers (1)

Sugar Daddy
Sugar Daddy on 25 Jul 2020
what if you remove NaNs from dataset
X = [1 2 3 NaN 3 2 1];
X(isnan(X)) = []
X =
1 2 3 3 2 1

  1 Comment

noam edelshtein
noam edelshtein on 25 Jul 2020
That would cause a change in dimensions of the matrix, and there is more analysis to come after this stage, so I would need to know precisely where the nan values were to reinsert them in the right places following the fft analysis.
I considered replacing with 0 but I think that will cause some form of change in the results of the analysis.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!