Network streaming

The activity of segmented cells can be streamed over the network for online processing or for use in closed-loop experiments. Two configuration variables define the host name and port the data will be streamed to.

sbconfig.stream_host = 'localhost';     % stream to this host name
sbconfig.stream_port = 30000;           % and port...

In this particular example we will be streaming data to the same machine, but you can change stream_host to the name of any other machine on your network or a static IP address.

After segmenting cells, the only thing you need to do to stream the data is to click the “Network stream” checkbox in the real-time processing panel. In the example below, there are two ROIs defined that will get streamed to destination defined by the (stream_host,stream_port) variables.

To receive the data on the client side, you can simply open an udp port:

u = udp('localhost','LocalPort',30000);
fopen(u)

Every time you call fread() you will get a single packet of data:

>> fread(u,80,'int16')

ans =
           9
           2
        -341
       -1492
           0

The first number in the packet is the frame number (in this case, the packet represents data from frame #9). The second entry corresponds to the the number of segmented cells (in this case we have two ROIs). The next two values correspond to the signal from each ROI normalized as explained below. The last entry in the packet is a stimulus marker, that is one during the presentation of a stimulus and zero otherwise.

At each point in time, the data for each channel are z-scored and normalized so that 1 SD corresponds to a count of 1000. Thus, the two values in the packet above represent z-scores of -0.34 and -1.49. At each point in time, the mean and standard deviation used for z-scoring are based on all the data collected up to that point. So, it may take a few seconds of data collection to obtain a stable estimate of these values.