Store stream data in Matlab | LabJack
 

Store stream data in Matlab

3 posts / 0 new
Last post
Adrulolo
adrilopez2005's picture
Store stream data in Matlab

Hi, I'm a new user and I'm using your u3simpleastream,m example to interact with Matlab, but I don't understand how to get the stream data.

The application I need should basically do:

  • set a stream time, a sampling frequency and number of channels.
  • start the stream and run it for the set time
  • and return a vector with the data per channel

Thanks for the help :)

LabJack Support
LabJack Support's picture
In the example, take a look

In the example, take a look at the loop commented with "% Read the stream data" as it demonstrates getting the stream data with LJ_ioGET_STREAM_DATA.

Before the stream read loop is the configuration and start code.

For running for a set time, you can do that in the stream read loop. You can calculate that time the code has ran and stop when needed (tic, toc), or you can stop it after a certain amount of scan are read. For example on the latter, if you want 5 seconds of data and your scan rate is 2000 scans/second, read 10000 scans total (10000*#Channels total samples) in the stream read loop. Time*ScanRate.

Note that returned stream data is interleaved. For example, if streaming AIN0 and AIN1 (channels 0 and 1), the returned stream data is:

adblData(1)  % Scan 0, AIN0
adblData(2)  % Scan 0, AIN1
adblData(3)  % Scan 1, AIN0
adblData(4)  % Scan 1, AIN1
adblData(5)  % Scan 2, AIN0
adblData(6)  % Scan 2, AIN1
and so on ...

For general documentation on stream mode using the UD driver, look here:

https://labjack.com/support/datasheets/u3/high-level-driver/example-pseu...

LabJack Support
LabJack Support's picture
To add, the example shows the

To add, the example shows the stream reads with LJ_chALL_CHANNEL, which is all channels interleaved. To read channels 0 and 1 separately in the read loop would be (note that change the disp code accordingly as this only shows getting the data):

        % Init arrays to store data.
        adblData0 = NET.createArray('System.Double', numScans);  % Channel 0 array
        adblData1 = NET.createArray('System.Double', numScans);  % Channel 1 array

        % Read numScans channel 0 scans (stored in adblData0)
        numScansRequested0 = numScans;
        [ljerror, numScansRequested0] = ljudObj.eGetPtr(ljhandle, LJ_ioGET_STREAM_DATA, 0, numScansRequested0, adblData0);

        % Read numScans channel 1 scans (stored in adblData1)
        numScansRequested1 = numScans;
        [ljerror, numScansRequested1] = ljudObj.eGetPtr(ljhandle, LJ_ioGET_STREAM_DATA, 1, numScansRequested1, adblData1);