title: Digital filter algorithm
body: <p>I just found a fir algorithm on wikipedia</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Digital_filter" rel="nofollow">http://en.wikipedia.org/wiki/Digital_filter</a></p>
  
  <pre><code>// if the size of NB_COEF = 2^n use a bit mask instead of the modulo (%)
  // %=NB_COEF =&gt; &amp;=(NB_COEF-1)
  // pipe is a circular buffer
  
  #define NB_COEF 16  // numbers of coefficients of the filter
  double x_buffer[NB_COEF]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  double coef[NB_COEF]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int ptr_x_buffer=0;
  
  double FiltreFIR(double x)
  // x: Signal d'entrée
  // y: Signal de sortie
  {
    int n, y=0;
    x_buffer[ptr_x_buffer++] = x;
    ptr_x_buffer %= NB_COEF;
  
    for( n = (NB_COEF-1) ; n &gt;= 0 ; n-- )
    {
      y += coef[n] * x_buffer[ptr_x_buffer++];
      ptr_x_buffer %= NB_COEF;
    }
    return(y);
  }
  </code></pre>
  
  <p>-Can anybody tell me why do we need constantly to do this expression </p>
  
  <pre><code>ptr_x_buffer%= NB_COEFF.
  </code></pre>
  
  <p>Because for me it would mean the variable ptr_x_buffer always take the value 0 ?!
  And it seems to me far from logic?!</p>
  
  <p>And also can somebody explain to me the first comment about bit masking and modulo.</p>
  
  <p>thank you in advance
  :)</p>