Skip to content

Conversation

@anthony9975
Copy link
Contributor

@anthony9975 anthony9975 commented Jan 23, 2026

ADC

Problem and Scope

A classic sliding window function needs to track a certain number of previous ADC frame values for various different signals. This uses unnecessary memory, so we can fix this by using an exponential moving average. This directly smooths the ADC output based on an exponential output and the current frame.

Description

We implemented
ADC_UpdateAnalogValues_EMA(volatile uint16_t *new_values, int num_signals, double alpha, uint16_t *weighted_output)
following https://en.wikipedia.org/wiki/Exponential_smoothing#Basic_(simple)_exponential_smoothing.
It returns the exponential moving average instead of a sliding window function to reduce memory usage (due to the window of previous ADC values).

Gotchas and Limitations

If the data are correlated in some way (i.e. a linear function), a simple exponential smoothing function will always lag behind and never reach the true value of the signal.
A solution would be to use Holt double exponential smoothing, which attempts to estimate the trend. This operation is still much faster than the sliding window function since we are again only looking at previous and new values and does not require more memory.

Testing

  • HOOTL testing
  • HITL testing
  • Human tested

Testing Details

We tested this on a G4 board and played around with the weights.

Larger Impact

A working ADC with a customizable smoothing function and weight is essential for all other signals to be smoothed.

Additional Context and Ticket

#170

ManasijaBhargavan and others added 30 commits November 4, 2025 09:57
Signed-off-by: Daniel Hansen <105574022+dchansen06@users.noreply.github.com>
@dchansen06 dchansen06 linked an issue Jan 23, 2026 that may be closed by this pull request
@dchansen06 dchansen06 added Enhancement New feature or request 2 PRIORITY Important and a priority, but less than URGENT Sensors Something involved with or related to sensors Peripheral Related to or involving a peripheral including abstractions labels Jan 23, 2026
@dchansen06 dchansen06 marked this pull request as ready for review January 23, 2026 10:17
@dchansen06 dchansen06 self-requested a review as a code owner January 23, 2026 10:17
@dchansen06 dchansen06 marked this pull request as draft January 23, 2026 10:17
@dchansen06
Copy link
Contributor

Please fix conflicts prior to marking as ready for review

@anthony9975 anthony9975 marked this pull request as ready for review January 27, 2026 04:25
Copy link
Contributor

@dchansen06 dchansen06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make your changes to the ECU in a separate branch off of StateMachineImplementation, please keep the ADC changes here; thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file changed? (And can you unchange it please)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot comment out everything else in a PR into main

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this as it will be old by the time anyone has to use it

@dchansen06 dchansen06 marked this pull request as draft January 27, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 PRIORITY Important and a priority, but less than URGENT Enhancement New feature or request Peripheral Related to or involving a peripheral including abstractions Sensors Something involved with or related to sensors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ADC Smoothing

7 participants