home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_05 / 9n05053a < prev    next >
Text File  |  1991-03-22  |  692b  |  35 lines

  1. #include <math.h>
  2.  
  3. /* apply a filter */
  4.  
  5. double filter( double s[], double y[],double A[]
  6.     double a[],int n, int N)
  7.     {
  8.     double sum=0.; int k;
  9.     for(k=0;k<n;k++) sum += a[k]*s[n-k];
  10.     for(k=1;k<N;k++) sum += A[k]*y[N-k];
  11.     return (y[n]=sum);
  12.     }
  13.  
  14. /* Set coefficients for two typical low-pass
  15.    windowing filters */
  16.  
  17. /* window size 2n-1 */
  18.  
  19. hamming(double a[],int n)
  20.     {
  21.     int k,m=(n<<1)-1;double c;
  22.     c=3.14159265358979323/n;
  23.     for(k=0;k<m;k++) a[k]=.54+.46*cos( c*k );
  24.     }
  25.  
  26. /* the Hanning window is another possible
  27.    winder choice*/
  28.  
  29. hanning(double a[],int n)
  30.     {
  31.     int k,m=(n<<1)-1;double c;
  32.     c=3.14159265358979323/n;
  33.     for(k=0;k<m;k++) a[k]=.5+.5*cos( c*k );
  34.     }
  35.