title: Real time low pass filter in C
body: <p>I'm trying to implement an embedded design.
  I receive u32 data from my board and want to add a LPF to the signal. Since I'm not very familiar with C code, I'm stuck right now. I followed a tutorial to get the basics about fixed point FIR, which works with static data.</p>
  
  <p>Right now I take a sample from the input device and process the sample separately. There are some casts from u32 to int32_t, but I'm not really sure what's going on there.</p>
  
  <p>Anyone who can point me in the right direction?</p>
  
  <pre><code>#define FILTER_LEN_LP 44
  int16_t coeffsLPF[ FILTER_LEN_LP ] =
  {
      87, 76, 106, 143, 185, 234, 289, 349,
      414, 483, 555, 628, 701, 773, 842, 907,
      966, 1017, 1060, 1093, 1115, 1126, 1126,
      1115, 1093, 1060, 1017, 966, 907, 842, 773,
      701, 628, 555, 483, 414, 349, 289, 234, 185,
      143, 106, 76, 87
  };
  
  void low_pass_filter(){
      u32 in_left;
  
      int k = 0;
      int filter_length = FILTER_LEN_LP;
      u32 acc; // accumulator for MACs
      u32 *coeffp; // pointer to coefficients
  
      u32 out_left;
  
      while (!XUartPs_IsReceiveData(UART_BASEADDR)) {
  
          in_left = Xil_In32(I2S_DATA_RX_L_REG);
  
          xil_printf("%d\n\r", in_left);
  
          out_left = 1 &lt;&lt; 29;
          for ( k = 0; k &lt; filter_length; k++ )
          {
              out_left += (int32_t)*coeffp++ * in_left;
          }
  
          // saturate the result
          if ( out_left &gt; 0x3fffffff )
          {
             out_left = 0x3fffffff;
          } else if ( out_left &lt; -0x40000000 ){
             out_left = -0x40000000;
          }
  
         xil_printf("%d\n\r", out_left);
  
          //in_right = Xil_In32(I2S_DATA_RX_R_REG);
  
          Xil_Out32(I2S_DATA_TX_L_REG, out_left);
  
  
          //Xil_Out32(I2S_DATA_TX_R_REG, in_right);
  
      }
      // break
      if(XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET) == 'q') menu();
      else low_pass_filter();
  }
  </code></pre>