Class WfdbSegmentReader

java.lang.Object
com.framed.communicator.driver.protocol.mimic.WfdbSegmentReader

public final class WfdbSegmentReader extends Object
Decodes the raw ADC samples of a single WFDB segment from its .dat file.

WFDB stores samples frame-interleaved: for n signals the on-disk sample sequence is sig0[0], sig1[0], …, sig(n-1)[0], sig0[1], …. The flat sample index of signal s in frame f is therefore k = f*n + s. This reader supports the three formats occurring in the MIMIC-III Waveform Database:

  • 80 — 8-bit offset binary; one byte per sample, adc = byte - 128.
  • 16 — 16-bit little-endian two's complement; two bytes per sample.
  • 212 — two 12-bit two's-complement samples packed into three bytes.

The whole segment file is held in memory; segments in this database are individually small enough (tens of MB at most) for this to be acceptable and it keeps random frame access simple. All signals of a segment are expected to share one .dat file and one format, as MIMIC-III segments do.

  • Method Details

    • open

      public static WfdbSegmentReader open(Path datPath, List<WfdbSignal> signals, long numFramesHint) throws IOException
      Opens the .dat file for a segment described by signals.
      Parameters:
      datPath - the segment's signal file
      signals - the segment header's signal specifications (all sharing datPath)
      numFramesHint - the samples-per-signal count from the segment header; when <= 0 the frame count is derived from the file length
      Returns:
      a reader positioned over the decoded samples
      Throws:
      IOException - if the file cannot be read
      UnsupportedOperationException - if the signals use a format this reader cannot decode
      IllegalArgumentException - if the signals mix formats or files
    • numFrames

      public long numFrames()
      Returns:
      the number of decodable frames (samples per signal) in this segment
    • numSignals

      public int numSignals()
      Returns:
      the number of signals per frame
    • adc

      public int adc(int signalIndex, long frame)
      Decodes the raw ADC value of signal signalIndex in frame frame.
      Parameters:
      signalIndex - zero-based signal (column) index
      frame - zero-based frame index, 0 <= frame < numFrames()
      Returns:
      the sign-corrected raw ADC sample value