Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MATLAB serial port interface maximum speed

954 views
Skip to first unread message

Frank Bormann

unread,
Sep 24, 2006, 1:54:26 AM9/24/06
to
Hi!

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

AD

unread,
Sep 28, 2006, 6:34:08 PM9/28/06
to


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.

Frank Bormann

unread,
Oct 9, 2006, 4:38:45 AM10/9/06
to
AD wrote:

> 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.

Paul Brinkman

unread,
Nov 9, 2006, 4:26:45 AM11/9/06
to
What is (in theory) the maximum data transfer rate and/or maximum
frequency using a USB port and Matlab?
At the moment I'm trying to make a connection between a measurement
device (acquires data at a frequency of 200Hz)and Matlab

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

Sebastian Hölz

unread,
Nov 9, 2006, 9:03:39 AM11/9/06
to
@ 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

Paul Brinkman

unread,
Nov 9, 2006, 4:18:56 PM11/9/06
to
Does someone has experience with Labview? Is it true that the maximum
transfer rate and/or maximum frequency that can be achieved in
Labview are higher than in Matlab?

Dhinakaran Chinappen

unread,
Nov 16, 2006, 4:59:31 PM11/16/06
to
Hello there,
I was really glad to see that somebody posted something about the
upper limit of the Serial Port Object Speed.

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.

Frank Bormann

unread,
Feb 4, 2007, 12:10:07 PM2/4/07
to
Paul Brinkman wrote:
> What is (in theory) the maximum data transfer rate and/or maximum
> frequency using a USB port and Matlab?

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

camaybar

unread,
Feb 8, 2007, 3:53:03 AM2/8/07
to
I am guessing that this FT2232 is an IC in the DAC system that you
have connected to the USB of your PCB.

Frank Bormann

unread,
Feb 8, 2007, 5:27:28 AM2/8/07
to
camaybar wrote:
> I am guessing that this FT2232 is an IC in the DAC system that you
> have connected to the USB of your PCB.

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.

Marcus

unread,
Jul 18, 2009, 12:10:03 PM7/18/09
to
Frank Bormann <news.1....@xoxy.net> wrote in message <Proxh.121434$5l2....@fe02.news.easynews.com>...
Its long ago, but maybe you still read it and can give me some hints how to achieve this. I cant achieve transfer rates close to 2Mbits/s. Neither with callbacks nor with loops... Thanks
0 new messages