Repository navigation
Keep invalid samples invalid in smooth_frames - #608
Merged
Merged
Conversation
tompollard
reviewed
Oct 31, 2026
tompollard
left a comment
Member
There was a problem hiding this comment.
Thanks, this looks great!
I compared it against rdsamp from the WFDB C library (frame-averaged output) on the multi-frequency sample records that have invalid samples:
wave_4:rdsampgives 3659 invalid frames. With this PR the Python reader gives the same 3659, at the same positions. Onmainit gave 7.041s02: one invalid frame in both, at the same position. Onmainthere were none.
All other multi-frequency records in sample-data read exactly as before.
TheNetherWatcher
force-pushed
the
smooth-frames-invalid
branch
2 times, most recently
from
October 31, 2026 18:41
2f2a81f to
dfd0a25
Compare
smooth_frames averaged the invalid sample value with the other samples in a frame, which gave a large valid-looking value instead of an invalid one (NaN in physical units). As in the WFDB library's meansamp(), a frame that contains an invalid sample now gives the invalid value.
TheNetherWatcher
force-pushed
the
smooth-frames-invalid
branch
from
October 31, 2026 18:49
dfd0a25 to
af4958e
Compare
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.
When a signal has more than one sample per frame,
smooth_framesaverages each frame in digital units. It doesn't check for the invalid sample value, so an invalid sample is averaged with the others and gives a large value that looks valid:The WFDB library returns an invalid value for any frame that contains an invalid sample (
meansamp()inlib/signal.c), so this does the same: after averaging a chunk of frames in digital units, frames with an invalid sample are set to the invalid value for the channel's format. That then becomes NaN when converted to physical units. Physical smoothing (sigtype="physical") already gave NaN, since NaN propagates through the sum.This doesn't change the rounding of valid frames, which is #335.
Tests: a fmt 16 record with two samples per frame and one invalid sample reads back as
[3, -32768, 7](digital) and[0.015, nan, 0.035](physical). This fails onmain.pytest -m "not network"passes (97 tests), and the docs build passes.