Coder Social home page Coder Social logo

Comments (2)

AlexandraTrifan avatar AlexandraTrifan commented on August 22, 2024 1

Hello,

Please keep in mind that the branch you are using, with the modified Python bindings is still under development/review, so some things might slightly change until it is merged to master.

The getSamplesRawInterleaved(10000) will return 4*nb_samples elements in the Python list. In order to get samples faster, we don't copy all the samples into a list, we just return bytes. One sample on one channel for AnalogIn is represented on 2 bytes. That's why you have 40000 instead of 20000. The samples are indeed interleaved, so you will see one sample from CHANNEL_1, then one sample from CHANNEL_2. The difference is that a sample corresponds to 2 elements in the list.
Let's take an example:
Run:

samples = getSamplesRawInterleaved(10) 
samples.tolist()

will return something like this
[243, 255, 2, 0, 246, 255, 2, 0, 244, 255, 2, 0, 246, 255, 2, 0, 244, 255, 2, 0, 244, 255, 1, 0, 243, 255, 0, 0, 245, 255, 3, 0, 245, 255, 2, 0, 245, 255, 2, 0]
and samples.tobytes()
will return
b'\xf3\xff\x02\x00\xf6\xff\x02\x00\xf4\xff\x02\x00\xf6\xff\x02\x00\xf4\xff\x02\x00\xf4\xff\x01\x00\xf3\xff\x00\x00\xf5\xff\x03\x00\xf5\xff\x02\x00\xf5\xff\x02\x00'
[243, 255] correspond to the first sample on CHANNEL_1
[2, 0] correspond to the first sample on CHANNEL_2

In order to convert all the samples you can use the following chunk of Python code:

import struct
#..enable channels, acquire samples
samples = samples.tobytes()
count = int(len(samples)/2)
value_list = struct.unpack('h'*count, samples)   #'h' is the format for short

value_list will be similar to the following: (-13, 2, -10, 2, -12, 2, -10, 2, -12, 2, -12, 1, -13, 0, -11, 3, -11, 2, -11, 2)

Next thing is to convert it into Volts. In Python, for AnalogIn() you have 2 exposed methods: convertRawToVolts(channel, raw) and convertVoltsToRaw(channel, voltage).

Running convertRawToVolts(0, value_list[0]) (in the case we described above) should get you the Volts value that you need.

Regarding your questions about the formula parameters: filterCompensation changes if you modify the sample rate, some of the coefficients change if you recalibrate the board, and one might change if you modify the RANGE of the AnalogIn.

For the multiprocessing part: You can open up a context in the second process (without doing any calibration, or modifying any attributes in it) and just use it to run convertRawToVolts on the samples transfered from the first process.
The first process could run m2kOpen() (connect through USB), then calibrate the board, enable channels, set sample rates and run getSamples, then send those samples to the second process.
The second process could run m2kOpen("ip:192.168.2.1"), get a handler for the AnalogIn and just convert all the samples using convertRawToVolts(channel, raw). (The second process will know what values to use for the conversion coefficients).

We will add these explanations regarding new Python exposed methods to the documentation as soon as possible.
Did I manage to answer your questions? Please let me know if something is not clear.

Thank you,
-Alexandra

from libm2k.

AlexandraTrifan avatar AlexandraTrifan commented on August 22, 2024

These instructions were added to the libm2k Doxygen Documentation. ( https://analogdevicesinc.github.io/libm2k/#faq )
I think we can close this.

from libm2k.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.