/* Adds a new value to the wma_f_t instances.  */
void wma_f_add(wma_f_t *wma, float x)
/* Adds a new value to the wma_f_t instances.  */
void wma_f_add(wma_f_t *wma, float x)
{
  float *pSource = wma->buffer + wma->k % wma->size;
  *pSource = x;
  wma->k++;
  if (wma->k < wma->size)
    return;
  double total = 0;
  uint16_t current_pos = wma->k % wma->size;
  for (uint16_t i = 0; i < wma->size; i++)
  {
    total += wma->buffer[(i + current_pos) % wma->size] * wma->weight[i];
  }
  wma->avg = (float)(total / wma->sum_weight);
}