Filter returning NaN in a loop

3 views (last 30 days)
Fatemeh
Fatemeh on 29 Dec 2014
Edited: Geoff Hayes on 29 Dec 2014
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
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.
Fatemeh
Fatemeh on 29 Dec 2014
Edited: Geoff Hayes on 29 Dec 2014
right, this is the code:
fAcquire = 1002.39;
w0 = 60/(fAcquire/2);
[b2 a2] = butter(4,[1 70]/(fAcquire/2),'bandpass');
[b1 a1]=iirnotch(w0,w0/35); % Q = 35
for indexI = 3:6
fdata_notch1 = filtfilt(b1,a1,data_unfilt);
fdata = filtfilt(b2,a2,fdata_notch);
pause(2);
countNAN = sum(isnan(fdata));
if (countNAN)
display(indexI, 'I have a problem');
break;
end
end
the data is a simple binary file that does not have any NaNs, I checked that. And if that helps I'm currently running my code in another machine that has MATLAB 2014a and it's working just fine.
Thanks guys.

Sign in to comment.

Answers (1)

Star Strider
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
Fatemeh
Fatemeh on 29 Dec 2014
no that's just a typo here...I typed my code instead of copying it :)
fdata_notch1 = filtfilt(b1,a1,data_unfilt); fdata = filtfilt(b2,a2,fdata_notch1);
Sorry!
Star Strider
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’?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!