UDP reading data speed

33 ビュー (過去 30 日間)
Tom Inge Nesheim
Tom Inge Nesheim 2019 年 4 月 16 日
コメント済み: LUCA MONARI 2020 年 10 月 21 日
Hi
I have a UDP source that transmits UDP packages with payload of 84 bytes and a rate of 20kHz. I have tried the UDP function in Matlab, fread(). This works, and I can get 3000 packages of data into Matlab and do signal analysis of the data stream. The data are consistent, and the data analysis are correct. The problem is that fread() use too much time. To read 3000 packages uses more than 4 seconds. To test the speed I have removed all other code and only testing the fread, by using this code:
For ii = 1:3000
fread (obj1,42,’unit16’);
end
This still uses more than 4 seconds.
Is there something that can help speeding up the fread command?

回答 (4 件)

LUCA MONARI
LUCA MONARI 2019 年 7 月 1 日
Hello Tom
Did you find any solution to your problem? I'm facing the same issue
Thank you
  2 件のコメント
Tom Inge Nesheim
Tom Inge Nesheim 2019 年 7 月 5 日
Hi Luca
I did not manage to solve this in Matlab. For my test task I had someone made a routine in C that do the task. For the time being I’m just transfer data through a file, this is still much faster than doing it in Matlab.
LUCA MONARI
LUCA MONARI 2019 年 7 月 5 日
Hi, Tom
thanks for your reply.
We manage to solve the problem basically in the same way. I had a colleague to write a script in python for receiving and saving UDP data and use Matlab to call the script and then move the file.

サインインしてコメントする。


Aiswarya Subramanian
Aiswarya Subramanian 2019 年 7 月 5 日
Hello,
Can you check the following link and see the changes they have suggested? I hope this helps :)

Andrew Neaville
Andrew Neaville 2019 年 11 月 21 日
I've had good luck increasing speed by setting
UDP.DatagramTerminateMode = 'off';
Then reading out the whole buffer, which contains many packets, at a time. I then just parse the packets. If your packets are constant size, then this should be very easy.
bytesAvailable = UDP.BytesAvailable;
fread (UDP,bytesAvailable/2,'unit16');

Bhargavi Ragidi
Bhargavi Ragidi 2020 年 10 月 21 日
編集済み: Bhargavi Ragidi 2020 年 10 月 21 日
Hi We are sending 1 packet of 730 bytes at 1ms through a specified port and we are receiving in Matlab through UDP port communication. When reading the packet using fread command to read that 1 packet of 730 bytes it is taking around 25ms
Generally the fread speed performance is slow or can we achieve same date rate as of sender??? Could any one explain..
  1 件のコメント
LUCA MONARI
LUCA MONARI 2020 年 10 月 21 日
Hi there
There are no way to increase the fread speed.
The only way I've found to significally increase the reading speed is the following:
  • write a script in Python to fetch the data ad save the data to a file
  • from Matlab call the Python script through the windows command prompt (command "system" in Matlab)
  • read the data from the file created by the Python script
In my case, I was able to read 7 packets of 24 bytes each every 1 ms (7 kHz, 168 bytes every ms).
Hope this helps

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by