/* Adds a new value to the wma_u16_t instances.  */
void wma_u16_add(wma_u16_t *wma, uint16_t x)
/* Adds a new value to the wma_u16_t instances.  */
void wma_u16_add(wma_u16_t *wma, uint16_t x)
{
  uint16_t *pSource = wma->buffer + wma->k % wma->size;
  *pSource = x;
  wma->k++;
  if (wma->k < wma->size)
    return;
  uint32_t 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 = (uint16_t)(total / wma->sum_weight);
}