Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Mean Calculation in Getpeak #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 5_EyeBlinkDetection/5_EyeBlinkDetection.ino
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ bool Getpeak(float new_sample) {
}

// Calculate mean
//Instead of recalculating the mean from scratch every time, you can use a sliding mean formula for efficiency:
// Update mean dynamically (sliding window mean)
//mean = mean + (new_sample - data_buffer[data_index]) / DATA_LENGTH;
float sum = 0.0, mean, standard_deviation = 0.0;
for (int i = 0; i < DATA_LENGTH; ++i){
sum += data_buffer[(data_index + i) % DATA_LENGTH];
Expand Down