Filter returning NaN in a loop
3 views (last 30 days)
Show older comments
Hi, I am using filtfilt function (in MATLAB 2014b) inside a for loop. Basically what my loop does is that every time it loads a signal and applies the filtfilt function to it. Now problem is after the first file is done and the loop moves to the second file the result of the filtfilt function is all NaN and I don't know why.
NOTE: I checked the input file to the filtfilt, it does NOT have NaN in it. Also, I tried changing the filter, and used a simple filter command, still the same problem exists. I just updated my MATLAB from 2014a to 2014b, before the update everything worked just fine, so I don't know, but maybe it's a problem with the new version???
PLEASE people! Any answer is appreciated...
Thanks.
3 Comments
Jan
on 29 Dec 2014
@Fatemeh: Currently there is only a very tiny chance, that the forum can guess the reason of the observed behavior. Either the input data or your code causes the NaNs, but we cannot see neither the code nor the data.
Answers (1)
Star Strider
on 29 Dec 2014
This may be your problem:
fdata_notch1 = filtfilt(b1,a1,data_unfilt);
fdata = filtfilt(b2,a2,fdata_notch);
In cascading your filters, you have to give the output of your first filter, ‘fdata_notch1’ here, to your second filter. I have no idea what may be in ‘fdata_notch’, but it’snot your signal!
Change the second line to:
fdata = filtfilt(b2,a2,fdata_notch1);
and see if that eliminates the NaN values
2 Comments
Star Strider
on 29 Dec 2014
OK.
I don’t have the DSP System Toolbox, so I can’t reproduce your ‘b1’ and ‘a1’. Attaching a .mat file with the coefficients would help.
Does ‘fdata_notch1’ have NaN values or only ‘fdata’?
See Also
Categories
Find more on Filter Analysis 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!