Incorrect UDP data reception in Matlab

雨燕双飞 提交于 2019-12-25 03:19:26

问题


My FPGA is continuously sending UDP packets on network using 10/100/1000 Mbps ethernet and i have written a MATLAB code to capture the data. FPGA kit is connected to a 1 gbps switch and then to PC.

The problem is that after a certain number of packets (around 1080000 Bytes) are received in Matlab, the next packets that are received are corrupted although the FPGA is sending correct data which i have verified by running Matlab with Wireshark.

1) Does it have something to do with the fact that the transmission rate from FPGA is high (5.18 Mbps in Wireshark) & the reception rate in Matlab is low?

2) Is it because of some internal memory issue. No more packets are received after around 1080000 Bytes worth of UDP data is received (problem shown in figure)? I tried changing the buffer_size & buffer_read_count but to no avail.

3) Is it because of the Matlab's internal buffer getting FULL? Will flushinput() command be of any help in this case if indeed the buffer is getting FULL?

I am pasting the Matlab code below.

clc
clearall
closeall

packet_size = 18;                %Size of 1 Packet
buffer_size = 1000*packet_size; % Buffer to store 1000 packets each of Packet_Size
buffer_read_count  = 100;         %How many times the buffer must be read 

do_post_processing = 1;

u=udp('192.168.0.100','RemotePort',4660,'Localport',4661);

set(u,'DatagramTerminateMode','off');   
set(u, 'InputBufferSize', 3*buffer_size);
set(u,'Timeout', 10); 

fopen(u);

x=tic;

ii=1;
kk = 1;

while(1)
      if(u.BytesAvailable>= buffer_size) 
            [a, count] = fread(u, buffer_size);

            data(:, kk) = a;

            data_buffer_read = reshape(a, packet_size, buffer_size/packet_size);

            data_start(:,kk) = (data_buffer_read(18,1:10)).';   

            data_end(:,kk)   = (data_buffer_read(18,end-10:end)).';   

            kk = kk + 1;

      end

      if(kk == buffer_read_count + 1)
          break;
      end

end

fclose(u);

%delete(u);

t=toc(x);

bw = (buffer_size*buffer_read_count*8)/t;

fprintf('Achieved data rate: %e bps\n', bw);

% post processing

data_reshape = reshape (data, packet_size, buffer_size*buffer_read_count/packet_size);

if(do_post_processing==1)
     plot(data_reshape.');
     title('UDP Data v/s Total Packets at 10 Mbps Ethernet Link');
     xlabel('Total Number of Packets'); 
     ylabel('Packet Data');
end

A thread i posted previously provides a link to this problem.

Slow speed of UDP reception in Matlab

Please provide any guidance about this issue.

Thank you.

Regards,

来源:https://stackoverflow.com/questions/25645367/incorrect-udp-data-reception-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!