From 2f4449d81e407d8ee2d2c4d9cf64ad5e2028e4f7 Mon Sep 17 00:00:00 2001 From: Dimitry Pianykh Date: Sat, 16 Nov 2024 22:39:19 -0500 Subject: [PATCH 1/3] #173: casual lowpass filter --- simple_ema.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 simple_ema.c diff --git a/simple_ema.c b/simple_ema.c new file mode 100644 index 0000000..f6221f0 --- /dev/null +++ b/simple_ema.c @@ -0,0 +1,13 @@ +#include + +// Exponential Moving Average Lowpass Filter +void ema_filter(float current_value, float *previous_ema, float alpha) { + *previous_ema = (alpha * current_value) + ((1 - alpha) * (*previous_ema)); +} + +int main() { + float alpha = 0.1f; // smoothing strength + float ema = 0.0f; // initial value can be 0 + // Something like : ema_filter(curent_unfiltered_value, &ema, alpha) + return 0; +} From 5e4840d96450bd8c46b6749e9b8b247e6fbf9e68 Mon Sep 17 00:00:00 2001 From: DimitryP6 Date: Tue, 19 Nov 2024 11:32:31 -0500 Subject: [PATCH 2/3] #173: finalized file location --- .pre-commit-config.yaml | 18 +++++++++--------- middleware/simple_ema.c | 8 ++++++++ simple_ema.c | 13 ------------- 3 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 middleware/simple_ema.c delete mode 100644 simple_ema.c diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 570ca9b..157f2fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ -repos: - - repo: local - hooks: - - id: clang_restage - name: Restage formatted files - entry: clang_restage - language: system - pass_filenames: false - always_run: true +repos: + - repo: local + hooks: + - id: clang_restage + name: Restage formatted files + entry: clang_restage + language: system + pass_filenames: false + always_run: true stages: [pre-commit] \ No newline at end of file diff --git a/middleware/simple_ema.c b/middleware/simple_ema.c new file mode 100644 index 0000000..c1912a0 --- /dev/null +++ b/middleware/simple_ema.c @@ -0,0 +1,8 @@ +#include + +// Exponential Moving Average Lowpass Filter +void ema_filter(float current_value, float *previous_ema, float alpha) +{ + *previous_ema = + (alpha * current_value) + ((1 - alpha) * (*previous_ema)); +} diff --git a/simple_ema.c b/simple_ema.c deleted file mode 100644 index f6221f0..0000000 --- a/simple_ema.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -// Exponential Moving Average Lowpass Filter -void ema_filter(float current_value, float *previous_ema, float alpha) { - *previous_ema = (alpha * current_value) + ((1 - alpha) * (*previous_ema)); -} - -int main() { - float alpha = 0.1f; // smoothing strength - float ema = 0.0f; // initial value can be 0 - // Something like : ema_filter(curent_unfiltered_value, &ema, alpha) - return 0; -} From 6811331e5e1356367c5bde5f482fcb7bf9904bfa Mon Sep 17 00:00:00 2001 From: DimitryP6 Date: Sun, 1 Dec 2024 18:54:53 -0500 Subject: [PATCH 3/3] #173: Added a simple_ema.h file --- middleware/simple_ema.c | 2 +- middleware/simple_ema.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 middleware/simple_ema.h diff --git a/middleware/simple_ema.c b/middleware/simple_ema.c index c1912a0..567b107 100644 --- a/middleware/simple_ema.c +++ b/middleware/simple_ema.c @@ -1,6 +1,6 @@ #include +#include "simple_ema.h" -// Exponential Moving Average Lowpass Filter void ema_filter(float current_value, float *previous_ema, float alpha) { *previous_ema = diff --git a/middleware/simple_ema.h b/middleware/simple_ema.h new file mode 100644 index 0000000..901e787 --- /dev/null +++ b/middleware/simple_ema.h @@ -0,0 +1,7 @@ +#ifndef SIMPLE_EMA +#define SIMPLE_EMA + +// Exponential Moving Average Lowpass Filter +ema_filter(float current_value, float *previous_ema, float alpha); + +#endif /* SIMPLE_EMA */ \ No newline at end of file