sfrwmaker / hakko_t12_stm32

The soldering iron controller built on stm32 micro controller
150 stars 63 forks source link

question about “exponential moving average” #2

Closed chenli2015 closed 5 years ago

chenli2015 commented 5 years ago

Hi, sfrwmaker, Thanks for your great work! Recently, I read your code. I could not understand the “exponential moving average” part. The following formula is the one get from: http://www.alglib.net/time-series/moving-average-filter.php EMA(t) = α·X(t) + (1-α)·EMA(t-1)

but the code from your project is diffrent: int32_t empAverage(uint32_t emp_data, uint8_t emp_k, int32_t v) { uint8_t round_v = emp_k >> 1; emp_data += v - (emp_data + round_v) / emp_k; return (emp_data + round_v) / emp_k; }

Is this a mistake?

sfrwmaker commented 5 years ago

In the project the recursive variant of the formula is used.

chenli2015 commented 5 years ago

Thanks for your response! I get the formula from wikipedia.