fix(vital_signs): use circular variance for wrapped phase values#605
Closed
yahyasaqban-lab wants to merge 1 commit into
Closed
fix(vital_signs): use circular variance for wrapped phase values#605yahyasaqban-lab wants to merge 1 commit into
yahyasaqban-lab wants to merge 1 commit into
Conversation
Phase values from atan2(i_val, q_val) are wrapped to (-pi, pi]. Linear variance treats values near +pi and -pi as ~2pi apart when they are physically ~0.003 rad apart, producing variance of ~pi^2 instead of ~1e-6. Replace with circular variance (1 - R, mean resultant length) which correctly handles wrapped circular data. This fixes the +/-15 bpm jitter in heart-rate detection and the jumpy vitals reported in issues ruvnet#485, ruvnet#519. Fixes ruvnet#593
Owner
|
Closing as a duplicate of #595, which was filed by the original reporter (@akhilesharora) of #593 on 2026-05-16 — three minutes after the bug report. #595 ships the same circular-variance formula plus 4 dedicated tests (including a regression test that explicitly asserts the old linear formula's pi² output on the wraparound input, so any future regression will fail the suite). #595 was merged in 60d1f… just now. Thanks for the contribution. For next time, please check existing open PRs before opening a fix and open feature branches from your fork rather than |
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
Phase values from
atan2(i\_val, q\_val)are wrapped to (-\pi, \pi]). Linear variance treats values near (+\pi) and (-\pi) as (\sim 2\pi) apart when they are physically (\sim 0.003) rad apart, producing variance of (\sim \pi^2) instead of (\sim 10^{-6}).Replace with circular variance (1 - R̄, where R̄ is the mean resultant length), which correctly handles wrapped circular data.
Repro
Impact
Fixes the (\pm 15) bpm jitter in heart-rate detection and jumpy vitals reported in issues #485 and #519.
Fixes #593