fixed mean diff and enhanced moving average #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
The mean diff values array are not initialized, so it can get garbage values from memory and make the balance intensities crazy. It is fixed by memsetting at the constructor.
The moving average was enhanced by first checking if the last pulse ocurred long ago (example: the finger was removed and then put back again in the sensor) to reset the moving average array. Then, it is checked if the values of the BPM are out of bounds (50 <= BPM <= 220), so they can be ignored and not added to the moving average. Finally, the moving average sum was enhanced to avoid unnecessary calculations.