Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MATLAB serial port interface maximum speed

Subject: MATLAB serial port interface maximum speed

From: Frank Bormann

Date: 23 Sep, 2006 22:54:26

Message: 1 of 10

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

Subject: MATLAB serial port interface maximum speed

From: AD

Date: 28 Sep, 2006 15:34:08

Message: 2 of 10

Frank Bormann wrote:
> 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


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.

Subject: (solution) MATLAB serial port interface maximum speed

From: Frank Bormann

Date: 9 Oct, 2006 01:38:45

Message: 3 of 10

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.

Subject: (solution) MATLAB serial port interface maximum speed

From: Paul Brinkman

Date: 9 Nov, 2006 04:26:45

Message: 4 of 10

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

Frank Bormann wrote:
>
>
> 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.
>
>

Subject: (solution) MATLAB serial port interface maximum speed

From: Paul Brinkman

Date: 9 Nov, 2006 16:18:56

Message: 5 of 10

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?

Paul Brinkman wrote:
>
>
> 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
>
> Frank Bormann wrote:
>>
>>
>> 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.
>>
>>

Subject: (solution) MATLAB serial port interface maximum speed

From: Dhinakaran Chinappen

Date: 16 Nov, 2006 16:59:31

Message: 6 of 10

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.

Paul Brinkman wrote:
>
>
> 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?
>
> Paul Brinkman wrote:
>>
>>
>> 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
>>
>> Frank Bormann wrote:
>>>
>>>
>>> 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.
>>>
>>>

Subject: (solution) MATLAB serial port interface maximum speed

From: Frank Bormann

Date: 4 Feb, 2007 17:10:07

Message: 7 of 10

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

Subject: (solution) MATLAB serial port interface maximu

From: camaybar

Date: 8 Feb, 2007 03:53:03

Message: 8 of 10

I am guessing that this FT2232 is an IC in the DAC system that you
have connected to the USB of your PCB.

Subject: (solution) MATLAB serial port interface maximu

From: Frank Bormann

Date: 8 Feb, 2007 10:27:28

Message: 9 of 10

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.

Subject: (solution) MATLAB serial port interface maximum speed

From: Marcus

Date: 18 Jul, 2009 16:10:03

Message: 10 of 10

Frank Bormann <news.1.fbormann@xoxy.net> wrote in message <Proxh.121434$5l2.81157@fe02.news.easynews.com>...
> 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
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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us