MATLAB: How to receive data through serial port with a frequency of 1000Hz (Matlab R2011)

arduinoMATLABserialport

I am interfacing an arduino with Matlab 2011 through a serial port. But currently I receive only 1 data per 2 second in the matlab even when I change baudrate in the arduino from 9600 – 250000.This is really slow as my application requires 1000 data per second to do the processes.
Data I send from the arduino is 5 ADC values that range from 0 – 1023 and I am using fscanf in matlab to receive these data.
Can any one suggest ideas to solve this issue.

Best Answer

Send a newline from the arduino after each sample (or group of samples)
Alternately, send in binary from the arduino and set up a BytesAvailableFcn with BytesAvailableFcnCount that reflects the number of bytes of samples you want to process for each interrupt, and set the serial BytesAvailableFcnMode to 'byte'; you would use fread() to read the bytes and (if appropriate) sscanf() or str2double() to convert them to numeric.
Alternately, send each sample as a fixed number of characters, and set up a BytesAvailableFcn with BytesAvailableFcnCount that reflects the number of bytes of samples you want to process for each interrupt, and set the serial BytesAvailableFcnMode to 'byte'; you would use fread() to read the bytes and (if appropriate) sscanf() or str2double() to convert them to numeric.
What you are likely doing now is just sending each sample without termination, and possibly without any delimiter between samples either. fscanf() does not terminate until the buffer fills up or it sees a terminator or until it times out.
Related Question