1

I'm working on an application where I receive a large amount of data via the USB from 4 sensors and displaying them in Matlab.

The streaming works perfectly , however, I need to do some processing on the data as it's streaming. I use segments of the incoming data and process them then plot the processed data. The incoming data is taken segment by segment and processed.

My problem is that, if I'm processing 5 seconds' worth of data in every segment. When the processing and plotting is implemented, the streaming stops, therefore when it's time for the next batch to process, I have to wait for the streaming of the next 5 seconds segment. Even if I delay the beginning of the processing to let's say after 20 seconds, the streaming will always stop when the processing starts and I will always have a small pause to read new data. How can I keep the streaming or the data reception from the serial port going even when I'm processing the data?

Thanks

Isra
  • 155
  • 1
  • 12

1 Answers1

1

You should use a worker thread to perform your processing. This can be done in matlab using the parfeval command as follows:

parpool % start a parallel pool (may take some time)

...

nOutputs = 1; % number of outputs
in1 = 1; % first input argument
in2 = 2; % second input argument
f = parfeval(@your_function, nOutputs, in1, in2); % execute your function with two input arguments as example

...

% check regularly if the function is executed
if strcmp(f.State, 'finished') == 1
  output = fetchOutputs(f);
  ... % do something with the output
  delete(f); % empty resources
end

As an alternative, you can use the batch command.

m7913d
  • 10,244
  • 7
  • 28
  • 56