I am using the fread() function to continuously receive datagrams, and the fprintf() function to write the data to a text file when a datagram is received:
UDP = udp(ip, port);UDP.InputBufferSize = 1024;UDP.DatagramTerminateMode = 'ON';fopen(UDP);while 1 ADCdata = fread(UDP, 1, 'uint16'); fprintf(ADCdataFile, '%d\n', ADCdata);end
We would like the data rate to be as high as possible for our application. Right now, when transmitting at a rate of 4Mbps or so, the data is read in and saved with no problem. However, at 15–20Mbps, MATLAB is not able to keep up with the data, and much of the data is lost (i.e. not read/saved).
Is there a data rate limitation to the UDP fread() functionality that is known?
Is there a way to increase the rate at which UDP data is read in and saved to a file? Perhaps the above code is not optimal, or there may be a better function than fprintf()?
Best Answer