I am a novice in MATLAB, trying to implement a high-speed data
acquisition application. Actually, the data source is connected to the
PC through an USB port, using a Virtual Serial Port driver so MATLAB
can access the data source device through its serial interface. I was
wondering if anyone had any experience in what the maximum achievable
data transfer speed is in this kind of setup.
I'm using this code to read the data, with sp being the serial port
object:
bytecount = 0;
tic
while bytecount < 524588
if sp.BytesAvailable
[ dummy, count ] = fread(sp, sp.BytesAvailable, 'uint8');
bytecount = bytecount + count;
end
end
toc
I'm getting maximum speeds of 300-500 kbit/s, which unfortunately is a
bit less than I was hoping for. I was wondering, if anyone knows a
simple way to accomplish higher data transfer rates, besides more
obvious solutions of course, like accessing the USB driver DLL
directly. Setting different baudrates (the USB drivers ignores those
anyway) or input buffer sizes makes no difference. In a C program I can
get up to 1.9 MBit/s using the same hardware/driver setup, thus the
bottleneck must be MATLAB.
TIA
Frank
How about using BytesAvailableFcn and BytesAvailableFcnCount properties
of serial object, rather than a while loop?
You can have BytesAvailableFcnCount set to some number, and once the
specified number of bytes are available the BytesAvailableFcn will be
executed. Putting fread in BytesAvailableFcn will get the data into
MATLAB.
Also try changing the BaudRate, higher baudrate will give you better
performance.
> How about using BytesAvailableFcn and BytesAvailableFcnCount properties
> of serial object, rather than a while loop?
Tried that, unfortunately, using Callback functions was even slower. In
the meantime however, I've found a solution. It seems running the while
loop continously consumes so much processing power, that the reading
process of the MATLAB serial object is being slowed down to a crawl. I
managed to get reasonable data rates close of those I experience when
programming the same function in C just by putting a pause command in
the while loop like this:
bytecount = 0;
tic
while bytecount < 524588
if sp.BytesAvailable
[ dummy, count ] = fread(sp, sp.BytesAvailable, 'uint8');
bytecount = bytecount + count;
else
pause(0.01);
end
end
toc
Thanks anyway for your suggestion.
After reading these messages I'm not completely convinced that I will
manage it, because of the fact that Matlab can't collect the data
fast enough.
Paul
If you run Matlab on a 15-year old calculator, you may have problems acquiring data at 200Hz, with newer models you should not have a problem ...
Sebastian
So, i'm trying to gather data from a device which is controlled by a
DOS program. The data is supposed to be transmitted at 60hz, but i
only get 34Hz at best and when i plot the times between the data
sets, it's all over the place, with times ranging from 0.015s
(impossible!) an 0.054s (grrr).
So, a collegue of mine ran a C program and gathered data at full
speed from that DOS program, so the DOS program is no prob.
I'm hitting a ceiling. Here's the loop in my code to gather 200 sets
of data, each piece of data is 9bytes.
C = zeros(200,:);
for i = 1:200
fwrite (Eye,'1');
[A] = fread (Eye,9);
C (:,i)= A;
end
Increasing the baud rate doesn't increase the speed.
I've tried various small techniques to verify my time measurements,
and they all return more or less the same kind of receiving
frequencies.
I really hope somebody can help me out there!!
Thx a lot,
DK.
I'm sorry, that I haven't been to this newsgroup earlier. Just in case,
anybody is still interested, I've successfully managed to transfer data
from a measurement device into MATLAB's serial port object at transfer
rates of up to 2 MBit/s, using a FT2232 USB controller and its virtual
comport driver. It is very important however, to not keep MATLAB too
busy with other stuff while waiting for / reading data from the serial
port object, because apparently the asynchronous data read process has
quite a low priority compared to the main MATLAB program execution process.
Frank
The FT2232 is an IC I have on my PCB to establish communication between
a microcontroller on my PCB and MATLAB using USB. The FT2232 is the USB
endpoint on my PCB.