8000 16-bit integer wraparound with analog input recordings · Issue #40 · HolyLab/Imagine · GitHub
[go: up one dir, main page]

Skip to content
  • 16-bit integer wraparound with analog input recordings #40

    Open

    Description

    @Cody-G

    I've noticed that when we're reading voltage values at the very limits of the device (in this case at 10.0V) the 16-bit int values that get written to the .ai file wrap around and become negative. Here's an example:

    piezo_dip

    This did not occur in older versions of Imagine because we read the raw a/d converter values, which cannot go beyond the 16-bit int range. However in recent versions we switched to using the analog read function in the NIDAQmx API (see #31). This higher level function returns a floating point value that has been rescaled according to device-specific calibration, so it should be more accurate (reference). However it seems that this rescaled value is not precisely within the voltage range specified for the hardware. It's very close, but not quite. The calibrated values seem to go up to 10.00091V. This causes a problem when we rescale the double value to signed short in this line:

    https://github.com/HolyLab/Imagine/blob/waveform/Imagine/ai_thread.cpp#L105

    If I am correct, I think we can fix it by truncating the value to be within the -10.0...10.0V range. Something like this should work:

    voltage_scaled = readBuf[i]
    voltage_inbounds = min(10.0, voltage_scaled)
    voltage_inbounds = max(-10.0, voltage_inbounds)
    data.push_back(static_cast<signed short>(std::round(voltage_inbounds / 10.0 * 32767))); // existing line
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Type

      No type

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

      • 0