RIStream¶
RIStream is a C++ class included with libri that adds additional signal processing functionality on top of the basic data collection methods provided by libri: ri_get_raw_data()
and ri_start_continuous_transfer()
.
RIStream provides the following features to ease data collection:
Conversion to floating point numbers (either float or double)
calibration of raw ADC values to physical units
Low-pass filtering of incoming data
Downsampling of incoming data to reduce sample rates
Decimation of incoming data (combination of low-pass filtering and downsampling) to reduce sample rates while avoiding aliasing of high-frequency noise.
These various signal processing options can be toggled on or off by setting the various properties of the RIStream object. By default, a new RIStream will only perform calibration to uW of the collected data.
Using RIStream¶
Unlike the rest of libri which is written in C, RIStream is written in C++. To enable RIStream, the ri_stream.hpp header must be included:
#include "ri_stream.hpp"
After opening an ri_device* object as done with libri, we can create an RIStream object with the functions ri_open_stream<float> or ri_open_stream<double>.
ri_device *device = ri_open_device();
RIStream<float> *stream = ri_create_stream<float>(device);
// the stream is now ready for use
Note
An RIStream object cannot be created by manually calling the C++ constructor since RIStream and it’s parent, RIGenericStream are abstract classes. A new RIStream has to be allocated using the ri_create_stream functions.
Once a new stream has been created, the various signal processing operations it performs on incoming data can be configured. See ristream_properties for a description of the various properties that can be configured.
To collect data, the acquire function of the stream can be used:
float data[1000000];
stream->acquire(data, 1000000);
Finally, after you are finished using the stream, it should be cleaned up with ri_close_stream:
ri_close_stream(stream);