title: Hamming Window and Threshold Calculation of PPG Signal
body: <p>Currently, I am analyzing the software of an infrared and red sensor to calculate oxygen saturation and heart rate. The general formula I use for calculating SpO2 and HR is:</p>
  
  <p><a href="https://i.stack.imgur.com/r1KtX.png" rel="nofollow noreferrer">Used Formula</a></p>
  
  <p>Now I am failing on the following lines:</p>
  
  <p>In the .h file:</p>
  
  <pre><code>#define FS 100
  #define BUFFER_SIZE  (FS* 5) 
  #define HR_FIFO_SIZE 7
  #define MA4_SIZE  4 // DO NOT CHANGE
  #define HAMMING_SIZE  5// DO NOT CHANGE
  static  int32_t an_dx[ BUFFER_SIZE-MA4_SIZE]; // delta
  static  int32_t an_x[ BUFFER_SIZE]; //ir
  static  int32_t an_y[ BUFFER_SIZE]; //red
  </code></pre>
  
  <p>C++ File: </p>
  
  <pre><code>uint32_t un_ir_mean,un_only_once ;
  int32_t k, i,s;
  
  const uint16_t auw_hamm[31]={ 41,    276,    512,    276,     41 }
  //Hamm=  long16(512* hamming(5)');
  // an_dx[] array with soomthed adc values
  ...
  ...
  // hamming window (Buffer = 500, Hamming Size = 5, MA4 Size = 4)
      // flip wave form so that we can detect valley with peak detector
      for ( i=0 ; i&lt;BUFFER_SIZE-HAMMING_SIZE-MA4_SIZE-2 ; i++)
      {
          s= 0;
          for( k=i; k&lt;i+ HAMMING_SIZE ; k++)
          {
              s -= an_dx[k] *auw_hamm[k-i] ;
          }
          an_dx[i]= s/ (int32_t)1146; // divide by sum of auw_hamm
      }
  </code></pre>
  
  <p>How is the signal flipped here? 
  Where do the numbers from the Hamming Array come from? 
  I have worked in the theory of the Hamming window, but still do not understand the function performed. I hope you guys can help me out.</p>
  
  <p>Best regards
  Emin</p>