'Algorithm for detecting the lowest level of EMG activity?

How, having only data from the EMG sensor, to determine whether a person is in the REM phase? In other words, I need to detect the lowest level of activity from the sensor's EMG. Well, or at least register the phase change ...

In more detail... I'm going to make a REM phase detector using an EMG (electromyography) sensor. There is already a sketch of the Android application on the github, if you are interested, I can post a link. Although there is still work to be done...)

The device should work based on the fact that in different states of the brain (wakefulness, slow sleep, REM sleep), different levels of activity will be recorded from the sensor. In REM sleep, this activity is minimal.

The Bluetooth sensor is attached to the body before going to bed, the Android program is launched, communicates with the sensor and sends the data read from it to the connected TCP client via WiFi. TCP client - python script running on a nettop. It receives data, and by design should determine in real time whether the current level of activity is the minimum for the entire observation period. If so, the script will tell the server (Android program) to turn on the hint - it can be a vibration on the phone or a fitness bracelet, playing an audio sample through a headphone, light flashes, a slight electric shock =), etc.

Because only one EMG sensor is used, I admit that it will not be possible to catch REM sleep phases with 100% accuracy, but this is not necessary. If the accuracy is 80% - it's already good. For starters, even an algorithm for detecting a change in the current activity level is suitable. - There will be something to experiment with and something to build on.

The problem is with the algorithm. I would not like to use fixed thresholds, because these thresholds will be different for different people, and even for the same person at different times and in different states they will differ. Therefore, I will be glad to ideas and tips from your side.

enter image description here enter image description here enter image description here enter image description here enter image description here

I found an interesting article "A Self-adaptive Threshold Method for Automatic Sleep Stage Classifi- cation Using EOG and EMG" (https://www.researchgate.net/publication/281722966_A_Self-adaptive_Threshold_Method_for_Automatic_Sleep_Stage_Classification_Using_EOG_and_EMG): But there remains incomprehensible, a few points. First, how is the energy calculated (Step 1-4: Energy)?

    d = f.read(epoche_seconds*SAMPLE_RATE*2)
    if not d:
        break
    
    print('epoche#{}'.format(i))

    fmt = '<{}H'.format(len(d) // 2)
    t = unpack(fmt, d)
    d = list(t)
    d = np.array(d)
    d = d / (1 << 14) # 14 - bits per sample

    df=pd.DataFrame({'signal': d, 'id': [x*2 for x in range(len(d))]})
    df = df.set_index('id')
    
    d = df.signal
    # signal prepare:
    d = butter_bandpass_filter(d, lowcut, highcut, SAMPLE_RATE, order=2)

    # extract signal futures:
    future_iv = np.mean(np.absolute(d))
    print('iv={}'.format(future_iv))
    future_var = np.var(d)
    print('var={}'.format(future_var))
    
    ws = 6
    df = pd.DataFrame({'signal': np.absolute(d)})
    future_e = df.rolling(ws).sum()[ws-1:].max().signal
    print('E={}'.format(future_e))

-- Will it be right?

Secondly, can someone elaborate on this:

Step 2-1: normalized processed EMG and EOG feature vectors were processed with normalized function before involved into classification steps. Feature vectors were normalized as the follow- ing function (4): enter image description here Where, Xmax and Xmin were got by following steps: first, sort x(i) vector, and set window length N represents 50 ; then compare 2Nk (k, values from 10 to 1) with the length of x(i) , if 2Nk is bigger than the later one, reduce k , until 2Nk is lower than the length of x(i). If length of x(i) is greater than 2Nk, compute the mean of 50 larger values as Xmax, and the average of 50 smaller values as Xmin.

?



Solution 1:[1]

If you are looking for REM (deep sleep); a spectogram will show you intensity and frequency information on a 1 page graph/chart. People of a certain age refer to spectograms as TFFT - the wiki link is... https://en.wikipedia.org/wiki/Spectrogram

Can you input the data into a spectogram display/plot. Use a large FFT window (you probably have hours of data) with a small overlap (15%). I would recommend starting with an FFT window around 1 second.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J. R. Schweitzer