资源简介
肌电信号处理python代码
代码片段和文件信息
import numpy as np
class emg_processing():
# 提取活动段
def get_act(dataqua):
semg = np.array(data)
semg = semg.transpose()
semg = np.maximum(semg -semg)
semg = semg.mean(axis=1)
jg_flag = 0
act_flag = 0
yangben_flag = 0
sample_num = []
window_len = 40
act_data = [[]]
qua_data = [[]]
for i in range(int(len(semg)/window_len)):
temp = np.array(semg[i*window_len:(i+1)*window_len])
if temp.mean() >= 2.4:
# print(‘data is act‘)
act_flag = 1
jg_flag = 0
for j in range(8):
act_data[yangben_flag].extend(data[j][i * window_len:(i+1) * window_len])
for k in range(4):
qua_data[yangben_flag].extend(qua[k][i * 3:(i+1) * 3])
else:
# print(‘data is rest‘)
if act_flag == 1:
if jg_flag < 3:
for j in range(8):
act_data[yangben_flag].extend(data[j][i * window_len:(i + 1) * window_len])
for k in range(4):
qua_data[yangben_flag].extend(qua[k][i * 3:(i+1) * 3])
jg_flag += 1
else:
if len(act_data[yangben_flag]) > 10*8*window_len:
yangben_flag += 1
act_data.append([])
qua_data.append([])
act_flag = 0
jg_flag = 0
act_data=act_data[0:-1]
qua_data=qua_data[0:-1]
for i in range(len(act_data)):
sample_num.append(int(len(act_data[i])/8/window_len))
print(‘样本个数:‘ len(act_data))
print(‘样本窗数:‘ sample_num)
# print(act_data)
return act_data sample_numqua_data
# 数据配齐
def data_normalization(selfact_data mean_window_num):
# 将返回的每个样本窗数,带标签的rawdata,进行数据配齐
feature = [ ]
label = [ ]
print(‘actdata:‘np.array(act_data).shape)
for i in range(len(act_data)):
#print(len(act_data[i]))
for j in range(len(act_data[i])):
data = []
data_1 = []
for x in range(64):
data.append([])
for y in range(int(len(act_data[i][j])/1920)):
data_1.append(act_data[i][j][1920*y:1920*(y+1)])
for k in range(64):
data[k].extend(data_1[y][k*30:(k+1)*30])
# print(‘data:‘np.array(data).shape)
# for m in range(int(len(data)/64)):
# data_1.append(data[m*64:(m+1)*64])
window_len = len(act_data[i][j])/64/int(mean_window_num)
# print(window_len)
# data_2=[]
评论
共有 条评论