MATLAB Issue in EMG signal using matlab with arduino

AI Thread Summary
The discussion revolves around issues with EMG signal acquisition using an Arduino and MATLAB, where the signal appears incorrectly sampled despite good oscilloscope readings. The user suspects potential problems with the Arduino's ADC or the communication between Arduino and MATLAB, particularly regarding the sampling frequency. It is suggested that the Arduino's default sampling rate of 9600 Hz may be inadequate for the EMG signal's frequency range, which requires a minimum of 1 kHz sampling according to Nyquist Theorem. Recommendations include regulating the sample time for consistency and possibly switching to serial communication for better control. The conversation emphasizes the importance of proper sampling rates and timing to avoid aliasing and ensure accurate data representation.
Mo_Tuk
Messages
28
Reaction score
8
Hello

I'm working on project for "design & implementation of EMG data acquisition"
for now I completed the design and connected the output of the system to arduino uno to read the emg signal in real time with MATLAB 2017b using arduino support package.

the problem is that the signal looks as its sampled in wrong way although when i used oscilloscope the signal was very good so this means the hardware is working fine, is this problem could be related to ADC of the arduino or the communication between arduino and matlab??

the attached image shows the plot of the signal in matlab.
any suggestion...

matlab code:
Matlab:
a = arduino('COM3', 'UNO');
configurePin(a, 'A0', 'AnalogInput');

total_sample = 400;
for sample_no = 1:total_sample
    data(sample_no)= readVoltage(a, 'A0');
end

%% Plot EMG Signal vs Sample Number
%Figure caption
figure();
grid ON;
plot(data)
hold on;
plot(data, 'ro')
title('Plot of EMG Signal'); xlabel('Sample Number'); ylabel('Amplitude (V)');

% Rectification of the EMG signal
data = data - 2.635; % to shift down an emg signal
rec_data = abs(data);
figure();
plot(rec_data)
title('Rectified EMG'); xlabel('Sample Number'); ylabel('Amplitude (V)');
 

Attachments

  • 2.jpg
    2.jpg
    19.4 KB · Views: 569
  • 5 rec.jpg
    5 rec.jpg
    21.9 KB · Views: 853
Last edited by a moderator:
Physics news on Phys.org
Can you show a picture or screenshot of your o'scope signal, since it is reading correctly? I don't know enough about the Arduino to know if it is loading down your EMG output. Is your oscilloscope on an unloaded signal, or while it is hooked to the Arduino?
 
It is a little hard to tell with the plots having different horizontal sizes, but it sure looks like the second plot is the AC coupled, fullwave rectified version of the first plot. (or perhaps not AC coupled but with the 2.6V offset removed)

Here are the two plots at the same scale and another with them combined.
upload_2018-12-27_0-7-25.png
upload_2018-12-27_0-16-13.png
upload_2018-12-27_0-8-20.png
upload_2018-12-27_0-7-25.png


upload_2018-12-27_0-16-13.png


upload_2018-12-27_0-8-20.png

Cheers,
Tom
 

Attachments

  • upload_2018-12-27_0-5-46.png
    upload_2018-12-27_0-5-46.png
    31.4 KB · Views: 517
  • upload_2018-12-27_0-7-25.png
    upload_2018-12-27_0-7-25.png
    31.7 KB · Views: 1,129
  • upload_2018-12-27_0-8-20.png
    upload_2018-12-27_0-8-20.png
    55.8 KB · Views: 1,178
  • upload_2018-12-27_0-16-13.png
    upload_2018-12-27_0-16-13.png
    32.4 KB · Views: 1,094
scottdave said:
Can you show a picture or screenshot of your o'scope signal, since it is reading correctly? I don't know enough about the Arduino to know if it is loading down your EMG output. Is your oscilloscope on an unloaded signal, or while it is hooked to the Arduino?
Thanks Scottdave
This screenshot shows the output of the system which connected directly to oscilloscope, knowing that the sample rate of this scope is up to 2 GS/s Real Time
 

Attachments

  • 1.PNG
    1.PNG
    9 KB · Views: 537
  • 2.PNG
    2.PNG
    9 KB · Views: 491
Tom.G said:
It is a little hard to tell with the plots having different horizontal sizes, but it sure looks like the second plot is the AC coupled, fullwave rectified version of the first plot. (or perhaps not AC coupled but with the 2.6V offset removed)

Cheers,
Tom

Thanks, Tom
About the 2.5 offset, I made it in hardware "DC level shifter" because I want to shift the signal up so all signal will be in positive side, to let the ADC of the arduino digitized correctly.
I hope you understand me..

Can I change the sampling frequency of the ADC to higher one, so the emg signal will be plotted more smoothly and has more sampling points.
 
Mo_Tuk said:
Can I change the sampling frequency of the ADC to higher one, so the EMG signal will be plotted more smoothly and has more sampling points.
I think that's the real issue. What is the sampling rate, right now? I'm trying to figure out from the plots. If there are 2 seconds between pulses, then that's about 75 samples in 2 seconds ~ 40 samples per second, maybe.
 
Mo_Tuk said:
Can I change the sampling frequency of the ADC to higher one, so the emg signal will be plotted more smoothly and has more sampling points.
Maybe. If I'm reading the scope settings right (50ms per div), the scope trace you posted as 2.PNG shows the highest signal frequency is about 100Hz. So far you haven't told us the sample frequency you are using. Since the minimum sampling frequency needed is twice the signal frequency, you need to sample at 200Hz or higher. You can use a higher sample freq. if you wish; any higher than 4 or maybe 8 times the signal frequency is generally of little use for anything other than drawing pretty pictures (traces).

For computation of which fingers are doing what, your existing data looks fine, in fact may even be too much data! (looks fine to me anyhow, but I've never built the system you are putting together :smile:)

Cheers,
Tom
 
  • Like
Likes Mo_Tuk
Tom.G said:
Maybe. If I'm reading the scope settings right (50ms per div), the scope trace you posted as 2.PNG shows the highest signal frequency is about 100Hz. So far you haven't told us the sample frequency you are using. Since the minimum sampling frequency needed is twice the signal frequency, you need to sample at 200Hz or higher. You can use a higher sample freq. if you wish; any higher than 4 or maybe 8 times the signal frequency is generally of little use for anything other than drawing pretty pictures (traces).

For computation of which fingers are doing what, your existing data looks fine, in fact may even be too much data! (looks fine to me anyhow, but I've never built the system you are putting together :smile:)

Cheers,
Tom

The designed system has (20 to 500 Hz) band-pass filter which means that the emg signal frequencies should be in this range,and as Nyquist Theorem the minimum sampling frequency in this case should be at least 1k Hz, and I searched about ADC of the arduino and found that it has deafult fs=9600 Hz.
if ADC of arduino works fine, what is the problem then? or should I have external ADC ?

Tom.G said:
For computation of which fingers are doing what, your existing data looks fine, in fact may even be too much data! (looks fine to me anyhow, but I've never built the system you are putting together :smile:)
Do you mean the data which plotted in matlab??

cheers, Mo_Tuk
 
First - I would try to regulate the Sample Time for the Arduino, you do have a tight loop, and it should be consistent, but it would not take much variance to cause weird data. I would read the DS for the main uC in the Arduino to see how the ADC is done, it may be on its own clock ( this is probably the 9600Hz you mention) but also the TIMING diagram of the ADC, in this type of plot time is just as important as the magnitude. IF the ADC is on the 9600 clock and then you read the sample on a different time-base; for example your loop is 4x the sample frequency - you will read 4 x the same value, but it is not valid data, it is just the same sample being read 4 x, You can essentially get aliasing in the sample DATA) And THEN there is the impact of the actual signal and how well the filtering is working. ( On the scope can you do a freq sweep, to confirm you are not seeing anything above 1000kHz or so?

Another option or consideration is to record a sample and a time stamp, (use micros), then plot against the "real: time of the sample, not the assumed uniform sample time.

There is a reason the most expensive part of the scope is the "front end".
 
  • Like
Likes Mo_Tuk
  • #10
Windadct said:
First - I would try to regulate the Sample Time for the Arduino, you do have a tight loop, and it should be consistent, but it would not take much variance to cause weird data. I would read the DS for the main uC in the Arduino to see how the ADC is done, it may be on its own clock ( this is probably the 9600Hz you mention) but also the TIMING diagram of the ADC, in this type of plot time is just as important as the magnitude. IF the ADC is on the 9600 clock and then you read the sample on a different time-base; for example your loop is 4x the sample frequency - you will read 4 x the same value, but it is not valid data, it is just the same sample being read 4 x, You can essentially get aliasing in the sample DATA) And THEN there is the impact of the actual signal and how well the filtering is working. ( On the scope can you do a freq sweep, to confirm you are not seeing anything above 1000kHz or so?

Another option or consideration is to record a sample and a time stamp, (use micros), then plot against the "real: time of the sample, not the assumed uniform sample time.

There is a reason the most expensive part of the scope is the "front end".

Thanks, Windadct
I don't know what the code installed in ardiuno because when I installed arduino package, the MATLAB automatically install some code to arduino board.
I will change the communication using serial command instead of using arduino package and I will attache the results.

cheers, Mo_Tuk
 

Similar threads

Replies
8
Views
2K
Replies
1
Views
3K
Replies
2
Views
2K
Replies
1
Views
432
Replies
1
Views
3K
Replies
1
Views
1K
Replies
1
Views
10K
Replies
1
Views
2K
Back
Top