Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Nan and Inf with butterworth filter

Asked by Simranjit Singh on 11 May 2014
Latest activity Commented on by Star Strider on 12 May 2014
  • I want to create a butterworth filter of order 10 to extract the waves having frequency between 8-30Hz.
  • The signal which I want to filter has been sampled at 512Hz.
  • This is how I am using creating and using my filter.
[b,a] = butter(10, [8/256 30/256], 'bandpass')
filt=filter(b,a,series1);

But I get inf and NaN values. So I wanted to know am I using it correctly? Any tips and pointers will help Thanks in adavance

0 Comments

Simranjit Singh

Products

No products are associated with this question.

2 Answers

Answer by Star Strider on 11 May 2014

First, see if a lower-order filter works. Use the freqz function to analyse it before you use it on your data.

Second, see what the results of these commands are:

ser1nan = length(find(isnan(series1)))
ser1inf = length(find(isinf(series1)))

If they’re not both zero, you have to figure out what you want to do with the NaN and Inf values.

2 Comments

Simranjit Singh on 12 May 2014

Hi Strider,

Thanks for the info. I tried with the following(order 6):

[b,a] = butter(6, [8/256 30/256], 'bandpass')
filt=filter(b,a,series1);
The freqz function gives the right cut off power.There are no Nan and Inf in my inputs. 
I am also attaching my ip and op file for extra info.

Thanks! Your help is much appreciated.

Star Strider on 12 May 2014

Please upload your input data as a single-column text file. The file ‘ip.txt’ is your input as a multi-line row vector copied from the Command Window.

Star Strider
Answer by Honglei Chen on 12 May 2014

If your signal does not contain nan or inf, then likely this is due to the numerical stability of transfer function designed by butter algorithm. You can try the following code to design a Butterworth filter in SOS form, which improves the the numerical robustness and see if it addresses your issue.

myFilter = design(fdesign.bandpass('N,F3dB1,F3dB2',6,8,30,500),'butter');
y = filter(hd,series1);

HTH

1 Comment

Star Strider on 12 May 2014

I’d forgotten about the advantages of the SOS form. Thanks!

Honglei Chen

Contact us