Bluetooth EMG Project help, higher sampling frequency

I am student in University and my group and I are trying to construct a bluetooth EMG device. We built a circuit to condition the signal, then sent the data through Arduino BT to a computer. At the computer the data was saved in Matlab and manipulated to plot an EMG Signal. We built our own Matlab code because the arduino-matlab interface on the mathworks website was too slow.

Our problem with this process was that our sampling rate was only 200 hz. This is because we had to put in a delay of 5 ms in the arduino code because the serial connection kept terminating at lower delays. For a true EMG device, the sampling frequency must be at least 500 hz. I could not figure out if the termination of the serial connection was due to the arduino board or matlab acquiring the data.

I was looking at different options to increase this frequency such as

1.) sd card storage and then transmission.
2.) Using a bigger board with more EEPROM memory
3.) Different program than Matlab

Any help you could provide would be amazing.

Thank you

We built our own Matlab code

Can you share this? - sometimes its asked for at the forum!

Share the Arduino code you have sofar, probably there are some tips and tricks to improve performance.

Thank you for responding.

Here is the Matlab code. It's pretty rudimentary but it worked. Fgets was faster at reading the data then fscaf.

y=zeros(6000,1);
for ii=1:6000
v=fgets(s1);
s=str2num(v);
y(ii)=s;
end
volt = .0049.*y;
plot(volt);
ylabel('Volts');
xlabel('Sample');

Here is the Arduino Code. It was pretty rudimentary too.

int sensorPin=2;
int sensorValue=0;
void setup() {

Serial.begin(115200);
}

void loop() {
sensorValue=analogRead(sensorPin);
Serial.println(sensorValue);
delay(5);

The analogRead() returns an int which is turned into a string by the arduino before being send and a return is added.
e.g 567 (2 bytes) ==> "567\n" (4 bytes) so you loose factor 2 in communicating.

Try this:

#define SENSORPIN 2  // can't be changed :)

void setup() 
{
  Serial.begin(115200);
}

void loop() 
{
  int sensorValue = analogRead(sensorPin);
  Serial.write((uint8_t) (sensorValue >> 8));    // some bit masking to get the highbyte
  Serial.write((uint8_t) (sensorValue & 0xFF));  // and the low byte
  // delay(5); should not be needed
}

On the matlabside you need to reconstruct the integer do fread() - Read data from binary file - MATLAB fread - disclaimer No matlab expert :wink:

y=zeros(6000,1);
for ii=1:6000
    y(ii) = fread(s1, 2);      // read 2 bytes as one int16  into y(ii)
end
volt = .0049.*y; 
plot(volt);
ylabel('Volts');
xlabel('Sample');

(the #button is for code tags)

if that not works you might try
y(ii) = fread(s1, 2); // read 2 bytes as one int16 into y(ii)

high = fread(s1,1) *256; // read MSB byte
low = fread(s1,1); // read LSB byte
y(ii) = high + low;

Thank you for responding!

Do you have any idea how much of a sampling rate I should get with this?

Also do you understand why I needed to put in the delay of 5 ms? Do you think that is a problem with my board or the program?

Thank you again.

I would suspect that you're overrunning something on the PC end. Try just running the data into the serial monitor or a terminal program and see if that works without the delay then you'll know it's not the arduino or some hardware issue.

Assuming it's Matlab, have a look at this thread MathWorks - Site Temporarily Unavailable

What's a bluetooth EMG device by the way?