Correct determination of adc_gain and baseline in to_wfdb #3
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.
hen exporting waveform data to WFDB format, we want to preserve the resolution of the original source tracks as best we can.
This is important for analysis of the data (avoiding artificial noise created by re-scaling the sample values), converting the results into other formats without degradation, and also has benefits for data compression.
(wfdb-python doesn't currently support saving compressed signals, but I'm working on it. You can convert to compressed WFDB format by using
wfdb.wrsamp
and then usingsnip
to compress the result.)If the original source tracks in the
.vital
file are stored in integer format, it's easy - we can just write out those integer values and set the gain and baseline accordingly.For tracks stored in floating-point formats, I don't know whether the original measurement resolution is known. So far, I've only looked at the file
0001.vital
, which contains two floating-point tracks (BIS/EEG1_WAV
andBIS/EEG2_WAV
). Both of those havetrk.gain = 1.0
although the actual resolution appears to be 0.05 µV. The code given here works for these two examples, but the algorithm is not great.All other issues aside, wfdb-python currently has a bug (MIT-LCP/wfdb-python#418) that is screwing up conversion using
wfdb.wrsamp
withp_signal
. So here I've changed the code to used_signal
instead.This is just a first attempt; comments welcome!