# EMG threshold

Hello

I'm new to arduino , and I'm wondering how to write a code to find the max , min and threshold values of the EMG signal after asking the subject to contract and relax his/her arm in the setup section so the program do it one time only

in the setup section

Lets see the code you have in setup() now. It seems far more likely that you'll prompt the user to contract and then relax in setup() and then measure the action in loop(). You can structure loop() so that it loops until the contraction is noted, and then sets a flag. Only do useful stuff if the flag is false.

This is the entire code , we used this code to make the servo moves when the EMG was higher than 75 “threshold” it’s not written in this code, we have seen the signal on the serial plotter first then we have chosen 75 threshold and 160 as max, but my question is how to find them without seeing the serial plotter and serial monitor ?

EMG.txt (555 Bytes)

can you show a plot and explain what you saw that made you select 75 as the threshold? or was it simply some fraction of the sum of min and max?

it’s easy enough to capture max and min

``````   if (max = 0)
max = min = value
else if (max < value)
max = value;
else if (min > value)
min = value;
``````
``````   if (max = 0)
``````

Nope.

Try

``````   if (max == 0)
``````

thanks

gcjr:
can you show a plot and explain what you saw that made you select 75 as the threshold?

he observed the serial plotter in relaxing (min) and contracting (max) ( the green line is the average signal ) his arm and decided that min is less than 50 and added a cursor at 50 and the noise of the relaxing was in the range of 50 so he made 75 the threshold

and the third picture is what he is asking us to do suggest you read the the post Creating a threshold when reading a heart rate. It describes using leaky integration to maintain a running average of the signal peak and valley.

suggest you do something similar and possibly set a threshold to something between the peak and valley