am32-firmware / AM32

GNU General Public License v3.0
312 stars 111 forks source link

Averaging loop only iterates over 30 elements, but divides by 32. #97

Open zenith-parsec opened 1 month ago

zenith-parsec commented 1 month ago

The average_signal_pulse is calculated incorrectly in the detectInput() function. The number of elements added by the loop is 30, but sum of those 30 elements is divided by 32.

The loop is here: https://github.com/am32-firmware/AM32/blob/97f0d669afe27354c0c2f3e00483140c56228c15/Src/signal.c#L241

and the division is here: https://github.com/am32-firmware/AM32/blob/97f0d669afe27354c0c2f3e00483140c56228c15/Src/signal.c#L250

The fix is to change either the range being sampled (did you mean to say

for(int j = 0; j < 32; j++) {

instead?) or change the value it is dividing by (to 30).