Ideally you should put that code right after the call to the read(...)
function. Note that BITalino streams the data in real time and therefore read(...)
should be called within a loop (e.g. while
Another important detail is the number of samples requested each time read(...)
is called. Request too few (e.g. 1) and it will be highly resource-intensive; request too many (e.g. 10000) and read(...)
will be blocked for a long period.
Of course it will depend on the requirements of your algorithm, but from our experience requesting between 100 and 200 samples provides a good compromise between real time feel and performance in the access to the device.
Also, bear in mind that your processing code should have time to complete between calls to read(...)
. Imagine that your code takes 150ms to complete (e.g.); if you request 100 samples (e.g.) at 1000 Hz sampling rate, this will introduce a delay in the data arrival and eventually loss of samples.
Finally, if you're looking into plotting your data in real time, more likely than not you will have to use the drawnow
callback together with the call to the plot(...)
function, otherwise Matlab won't refresh the current plot as expected.
Hope you find this information useful for the goals you are pursuing. Do feel free to contact us for any further question you may have.
The BITalino Team