Accessing clients in MATLAB

Although there is no MATLAB client for Radiens, the Python client may be accessed via MATLAB using some built-in functionality.

  1. First download and install Python if not already installed. Check that you have (or are installing) the correct Python version for your version of MATLAB here. For trouble shooting see these docs.

  2. Next you need to tell matlab where your python executable is (if you are using an environment, direct pypath to that binary). The following lines must be run once upon every matlab launch.

Because of the asyncronous nature of Python env creation in via MATLAB, we recommended that you run these lines outside of your main script to avoid errors.
pypath = '/path/to/python/executable';
pyenv("Version", pypath);
  1. The following command only needs to be run once per unique pypath. That is, you’ll only have to install radiens again if you change the python executable matlab uses.

system([pypath ' -m pip install radiens'])
  1. Once the above has executed successfully, you can access the clients. The following are the same use cases we saw previously, but this time in MATLAB.

Streaming live signals

% import radiens python package and connect client
radiens = py.importlib.import_module('radiens');
allego = radiens.AllegoClient();

% duration of each signal chunk during streaming
loop_dur = allego.get_stream_loop_dur_ms()

% channel_metadata describes all the channel metadata
chan_meta = allego.get_channel_metadata()

% set time to primary cache head (live signals)
allego.set_time_to_cache_head()  

% wait for cache to build up before starting aquisition loop
pause(loop_dur)

% aquisition loop   
while true    
    % returns a py.tuple
    sigs_tuple = allego.get_signals();

    % we can cast py.tuple as a cell array in matlab
    sigs_cell_array = cell(sigs_tuple);

    % first cell is py.numpy.ndarray which can be cast as single or double
    sigs = single(sigs_cell_array{1}); 

    % second cell is py.list, which can also be cast as above
    time_range = single(sigs_cell_array{2}); 


    % do something


    pause(loop_dur)    
end

Note that the type conversions add noticable latency, and the effective loop duration may be considerably larger than loop_dur.