-

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
import numpy as np

def calculate_fatigue(emg_data, sample_rate):
    """Calculate muscle fatigue using EMG data."""
    
    # Calculate the root mean square (RMS) of the EMG data
    rms = np.sqrt(np.mean(np.square(emg_data)))
    
    # Calculate the mean frequency (MF) of the EMG data using a Fourier transform
    fft_data = np.fft.fft(emg_data)
    freqs = np.fft.fftfreq(len(emg_data), 1/sample_rate)
    mf = np.sum(np.abs(fft_data) * freqs) / np.sum(np.abs(fft_data))
    
    # Calculate the median frequency (MD) of the EMG data using a Fourier transform
    power_spectrum = np.square(np.abs(fft_data))
    md = freqs[np.argmax(power_spectrum[:len(power_spectrum)//2])]
    
    # Calculate the fatigue index (FI) using the ratio of the RMS value at the end of exercise
    # to the RMS value at the beginning of exercise
    fi = rms[-1] / rms[0]
    
    # Calculate the fatigue level (FL) using the formula FL = (MF - MD) / FI
    fl = (mf - md) / fi
    
    return fl

 

emg_data 是肌电数据的一维NumPy数组,sample_rate 是采样频率。

先计算肌电数据的均方根(RMS)值,然后使用傅里叶变换计算肌电数据的平均频率(MF)和中位数频率(MD)。

之后计算肌电数据的疲劳指数(FI),并使用MF、MD和FI计算肌肉疲劳度(FL)。

posted on 2023-02-23 14:24  p_xcn  阅读(214)  评论(0)    收藏  举报