Listing 4

#include <math.h>

/* apply a filter */

double filter( double s[], double y[],double A[]
    double a[],int n, int N)
   {
   double sum=0.; int k;
   for(k=0;k<n;k++) sum += a[k]*s[n-k];
   for(k=1;k<N;k++) sum += A[k]*y[N-k];
   return (y[n] =sum);
   }

/* Set coefficients for two typical low-pass
   windowing filters */

/* window size 2n-1 */

hamming(double a[],int n)
   {
   int k,m=(n<<1)-1;double c;
   c=3.14159265358979323/n;
   for(k=0;k<m;k++) a[k]=.54+.46*cos( c*k );
   }

/* the Hanning window is another possible
   winder choice*/

hanning(double a[],int n)
   {
   int k,m=(n<<1)-1;double c;
   c=3.14159265358979323/n;
   for(k:0;k<m;k++) a[k]=.5+.5*cos( c*k );
   }