Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-bit integer wraparound with analog input recordings #40

Open
Cody-G opened this issue Jul 2, 2017 · 0 comments
Open

16-bit integer wraparound with analog input recordings #40

Cody-G opened this issue Jul 2, 2017 · 0 comments
Labels

Comments

@Cody-G
Copy link
Contributor

Cody-G commented Jul 2, 2017

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
@Cody-G Cody-G added the bug label Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant