filtering - NaN values in Android filter -


i use following function filter signal. code works order 4, when use higher order, 5, nan values in output. highlly appreciated

void filt(int ord, double a[], double b[], int np,  double x[], arraylist<double> array)     {         int i,j;        // y[0]=b[0]*x[0];         array.add(0, b[0]*x[0]);         (i=1;i<ord+1;i++)         {              array.add(i, 0.0);             (j=0;j<i+1;j++)                array.add(i, array.get(i)+b[j]*x[i-j]);             (j=0;j<i;j++)                 array.add(i, array.get(i)-a[j+1]*array.get(i-j-1));         }         (i=ord+1;i<np;i++)         {            array.add(i, 0.0);                 (j=0;j<ord+1;j++)                 array.add(i, array.get(i)+b[j]*x[i-j]);                  (j=0;j<ord;j++)                 array.add(i, array.get(i)-a[j+1]*array.get(i-j-1));         }      } 

i tried same functionality of matlab, , got nan values. dig in matlab documentation , found following explains nan values:

"for higher order filters (possibly starting low order 8), numerical problems due roundoff errors may occur when forming transfer function using [b,a] syntax." therefor butterworth filter unstable higher orders.

to on problem in matlab, try following:

n = 6; wn = [2.5e6 29e6]/500e6; ftype = 'bandpass';  % transfer function design [b,a] = butter(n,wn,ftype); h1=dfilt.df2(b,a);      % unstable filter.  % zero-pole-gain design [z, p, k] = butter(n,wn,ftype); [sos,g]=zp2sos(z,p,k); h2=dfilt.df2sos(sos,g);  % plot , compare results hfvt=fvtool(h1,h2,'frequencyscale','log'); legend(hfvt,'tf design','zpk design') 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -