-
Notifications
You must be signed in to change notification settings - Fork 20.1k
Update EMAFilter.java #6368
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
base: master
Are you sure you want to change the base?
Update EMAFilter.java #6368
Conversation
refactor: simplify EMAFilter implementation - Reduce verbose comments to essential formula - Shorten variable names (emaValue -> ema, audioSignal -> signal) - Condense constructor validation and initialization - Maintain identical functionality and behavior
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6368 +/- ##
============================================
- Coverage 74.63% 74.63% -0.01%
+ Complexity 5452 5450 -2
============================================
Files 682 682
Lines 19017 19013 -4
Branches 3674 3674
============================================
- Hits 14193 14190 -3
+ Misses 4265 4263 -2
- Partials 559 560 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The build failed. Need to fix the build to start review. But what is the point of this PR? As this repository is mostly for studying algorithms, the older version is actually better for educational purposes, even though the newer version is slightly more concise. Here’s why:
Better Documentation for Learners:
This helps students understand the algorithm’s purpose before diving into the code. More Readable Error Message:
Explicit Initialization of emaValue in Constructor:
But we can combine these approaches and refactor the code as follows:
|
Simplify EMAFilter Implementation
Summary
Refactored the EMAFilter class to reduce code verbosity while maintaining identical functionality and behavior.
Changes
emaValue
→ema
,audioSignal
→signal
)Testing
Impact
The EMA filter continues to apply the same exponential moving average formula:
EMA[i] = alpha * signal[i] + (1-alpha) * EMA[i-1]