C++ API#

When I run make in the */maxlab_lib/ folder I get compilation errors. How can I solve this?

The examples are meant to work out of the box. If you get compilation erros it is most probably a toolchain issue. Please make sure that you have installed at least GCC 11 and make sure that when you run g++ --version it actually runs version 11 or newer.

Changing the gain value in MLL does not appear to change the range of data?

The gain value changes the value of the LSB (the multiplication factor to get from bits to volts/microvolts). The range of the bits does not change, as it always is 10bits (2^10, i.e. 0-1023). But what one bit corresponds to, does change (via the LSB).

../../_images/gain_lsb_resolution.png
In what units is the amplitude?

There are two member variables that can hold the amplitude:

That data is in ‘bits’. These bits can be between 0 and 1023. To convert from bits to volts or microvolts, one needs to multiply the bits value with the LSB. The LSB depends on the gain used and is

Gain

LSB [µV]

1

3222.66

7

460.38

112

28.77

512

6.29

1024

3.15

2048

1.57

We notice that we do not get consecutive frame numbers. Is our PC too slow?

Likely the system is not too slow. It does not need a very powerful system to keep up with the data. But it might depend on what you’re doing with the data in-between two data reads/two frames. If you want to do more complicated computations, it is advisable to use two or more threads (one thread to receive the data, one thread to process the data). But yes, in rare cases, a faster computer might help as well.

How do the amplitudes in the raw data need to be interpreted?

The member maxlab::RawFrameData::amplitudes is of type float* and is arranged as follows:

  • One call to maxlab::DataStreamerRaw_receiveNextFrame() yields one sample of data, i.e. one vector of float values where each value represents one sample from one of the 1024 channels

  • Individual elements (channels) of that sample can be accessed:

RawFrameData rawFrame;
float *dataRaw = rawFrame.amplitudes;
float channel0 = dataRaw[0];
float channel1 = dataRaw[1];
// etc.
What is the relationship between frame-number and the real time?

The frame numbers start at 0, when you turn on the device (hub). Then, they should be monotonically increasing with each frame. I.e. since the data is coming with 20kHz, there will be 20’000 frame numbers per second, and each frame number will be the preceding number +1. However, the data might arrive from the system with some jitter. So the individual frames cannot be used as precise time source.

How can I access electrode positions and channel mappings in C++ code?

Electrode positions and channel mappings can be accessed by manually parsing a .cfg file or by using the Python class mx.Config and passing data from the Python script to the C++ script.

See also: What information is contained in the .cfg files of the array?

What are the differences between the FIR and IIR filters?

The FIR filter is a finite impulse response filter while the IIR filter is an infinite impulse response filter.

Both filters are used to process raw voltage traces prior to spike detection. The resulting spike data are not directly comparable: the different filter characteristics can lead to differences in spike waveforms and measured amplitudes.

The FIR filter is the default filter used in Scope.

The two filters have different latencies, with the IIR filter being significantly faster, making it more suitable for closed-loop applications where low latency is important.

Can I generate new stimulation sequences while a closed-loop experiment is running?

The C++ API is only able to send commands to the system if they have been predefined within a mx.Sequence object through a Python setup script.

One option for creating stimulation patterns is to pre-define a large number of mx.Sequence objects before starting the experiment, using a regular naming scheme to determine each sequence’s token. Then, when the experiment is being run, one of these Sequences can be delivered through the C++ code by calling maxlab::sendSequence() while passing in a selected token from the tokens of the generated Sequences.

This method allows for the creation of complex stimulation patterns that can be delivered with precise timing, but requires the overhead cost of generating and storing all of the Sequences (the number and length of sequences is only constrained by the memory of the computer running mxwserver).

Another way to generate stimulation patterns on the fly is to create short, “building block” mx.Sequence objects in Python and and then send them sequentially, in various permutations, through the C++ API in order to build longer stimulation patterns. The downside of this approach is less precise stimulation timing: the initial_delay parameter of the Sequence object affects the timing of the sequence’s delivery, and reducing this parameter may introduce variability due to the time it takes for a the commands within a sequence to be downloaded to the system.