Skip to content

Instantly share code, notes, and snippets.

@delasign
Created March 30, 2024 14:44
Show Gist options
  • Save delasign/e58e0671cab31ab2bf6089b0d9c8ce1e to your computer and use it in GitHub Desktop.
Save delasign/e58e0671cab31ab2bf6089b0d9c8ce1e to your computer and use it in GitHub Desktop.
Sample High Pass Filter in Arduino
float alpha = 0.1; // Filter constant, lower value means more filtering
float prevValue = 0.0; // Previous filtered value
float filteredValue;
void setup() {
Serial.begin(9600);
}
void loop() {
float rawValue = analogRead(A0); // Read the raw analog input
// Apply the high-pass filter
filteredValue = rawValue - (prevValue * alpha);
prevValue = rawValue;
// Print the filtered value
Serial.println(filteredValue);
delay(10); // Delay to control the sampling rate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment