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)。
标签:emg,Calculate,肌肉疲劳,fft,计算,np,using,data From: https://www.cnblogs.com/can-glan/p/17147839.html