Issue in EMG signal using matlab with arduino

In summary: EMG samples per second, while the sampled frequency of the scope is about 2 GS/s so it looks like the sampled data is too much for the MATLAB code to handle.In summary, the design of the system is complete, but the hardware is working fine. The problem is that the signal looks as if it is sampled in the wrong way, despite being good when looked at with an oscilloscope. The attached image shows the plot of the signal in MATLAB. Any suggestions as to what the problem may be would be appreciated.
  • #1
Mo_Tuk
28
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: 497
  • 5 rec.jpg
    5 rec.jpg
    21.9 KB · Views: 778
Last edited by a moderator:
Physics news on Phys.org
  • #2
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?
 
  • #3
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: 459
  • upload_2018-12-27_0-7-25.png
    upload_2018-12-27_0-7-25.png
    31.7 KB · Views: 1,056
  • upload_2018-12-27_0-8-20.png
    upload_2018-12-27_0-8-20.png
    55.8 KB · Views: 1,057
  • upload_2018-12-27_0-16-13.png
    upload_2018-12-27_0-16-13.png
    32.4 KB · Views: 1,035
  • #4
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: 470
  • 2.PNG
    2.PNG
    9 KB · Views: 437
  • #5
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.
 
  • #6
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.
 
  • #7
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
  • #8
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
 
  • #9
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
 

1. What is an EMG signal and why is it important?

An EMG signal, or electromyography signal, is an electrical signal generated by the contraction of muscles. It is important because it can provide information about muscle activity and function, which can be useful in diagnosing and treating neuromuscular disorders.

2. How can I use Matlab with an Arduino to analyze EMG signals?

Matlab can be used with an Arduino by connecting the Arduino to the computer and using the Matlab Arduino support package. This allows you to read and analyze data from the Arduino, including EMG signals.

3. What are some common issues that can arise when working with EMG signals using Matlab and Arduino?

Some common issues include noise interference, incorrect sensor placement, and signal amplification problems. It is important to carefully set up and calibrate your equipment to minimize these issues.

4. How can I improve the quality of my EMG signal analysis using Matlab?

One way to improve the quality of your EMG signal analysis is by filtering the data to remove noise and artifacts. You can also perform signal processing techniques, such as smoothing or feature extraction, to obtain more accurate results.

5. Are there any resources available to help with troubleshooting EMG signal issues in Matlab with Arduino?

Yes, there are many online resources, such as forums and tutorials, that can provide guidance and troubleshooting tips for working with EMG signals using Matlab with Arduino. You can also consult with experts in the field or refer to the Matlab documentation for assistance.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • General Math
Replies
1
Views
751
  • Engineering and Comp Sci Homework Help
Replies
1
Views
956
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top