Closed
Conversation
fe217ca to
1204cb6
Compare
jcelerier
reviewed
Dec 12, 2025
Puara/PPAmplitude.hpp
Outdated
| { | ||
| halp::data_port< | ||
| "Peak-to-peak amplitude", | ||
| "Peak-to--peak amplitude in raw units, computed as (peak_max_raw - peak_min_raw).\n" |
jcelerier
approved these changes
Dec 12, 2025
### Summary Adds a peak-detection and amplitude-analysis utility for real-time signals. The object uses a normalized `Detection signal` to track four event types — rising trigger crossing (`PEAK_RISING`), falling trigger crossing (`PEAK_FALLING`), local maxima (`PEAK_MAX`), and local minima (`PEAK_MIN`) — based on configurable trigger, reload, and fallback parameters. Amplitude is measured from a separate `Raw signal`, with two available modes: `PeakLocked` or `CycleExtrema`. Adapted from Sofian Audry’s [Plaquette implementation](https://plaquette.org/PeakDetector.html), with additional raw-amplitude tracking. ### Functionality Inputs are: - Detection signal (`float`, ideally normalized and scaled 0 to 1) - Raw signal (`float`, original signal used for amplitude measurement) Parameters are: - Trigger threshold (`float` between 0 and 1. Level used for rising and falling trigger crossings) - Reload threshold (`float` between 0 and 1. Level used to reset / re-arm the detector) - Fallback tolerance (`float` between 0 and 1. Drop percentage between trigger and apex required to confirm maxima and minima) - Amplitude mode (`enum`) — `PeakLocked` or `CycleExtrema` - P2P update (`enum`) — updates peak-to-peak on max, min, or both Outputs are: - Peak max (`boolean`. True when a local maximum is confirmed on the detection signal) - Peak min (`boolean`. True when a local minimum is confirmed on the detection signal) - Peak rising (`boolean`. True when the detection signal crosses upward through the trigger threshold) - Peak falling (`boolean`. True when the detection signal crosses downward through the trigger threshold) - Peak-to-peak (`float`. Held raw peak-to-peak amplitude) - Max above threshold (`float`. Held raw amplitude above the rising trigger baseline) - Min below threshold (`float`. Held raw amplitude below the falling trigger baseline) Modes explained PeakLocked: - Uses raw values paired with confirmed detect peaks - Suitable when amplitude should follow the peaks confirmed by the detection signal CycleExtrema: - Uses raw extrema over two half-cycles: rising to falling for the upper excursion, and falling to next rising for the lower excursion - Suitable when amplitude should follow the full raw waveform shape between trigger crossings ### Implementation notes Uses a custom `PeakDetector` class stored in `3rdparty/extras` (to be reused in Respiration and EDA processes). Raw baselines are interpolated at trigger crossings so amplitude is measured relative to the estimated raw value at the threshold crossing, not only at the nearest sample.
Contributor
Author
|
Superseded by updated amplitude implementation with PeakLocked / CycleExtrema modes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Computes peak-to-peak amplitude in raw units using external peak events.
The module takes a raw signal plus two boolean gates (peak-min and peak-max, typically from a
PeakDetectorobject) and measures amplitude as:You can choose whether to emit the amplitude on each detected max or each detected min, and optionally enforce “strict” cycles that require a full min→max→min (or max→min→max) sequence before a new amplitude is produced.
Functionality
Inputs are:
Parameters are:
Outputs are:
last_peak_max_raw - last_peak_min_raw.The value is updated only at the chosen peak event (according to Mode) and otherwise held constant between events.
Implementation notes
peak_min_gateandpeak_max_gatesignals.