将肌电传感器与开发板相连接。这里我使用一块XIAO ESP32C3开发板来连接传感器。使用arduino编程。肌电传感器使用3.3V供电,使用C3的A0(GPIO2)管脚用来接收ADC信号。


参考着例程:
#include "Arduino.h"
#include "EMGFilters.h"
#define TIMING_DEBUG 1
#define SensorInputPin A0 // input pin number
EMGFilters myFilter;
SAMPLE_FREQUENCY sampleRate = SAMPLE_FREQ_1000HZ; // 修改为正确的枚举类型
NOTCH_FREQUENCY humFreq = NOTCH_FREQ_50HZ; // 修改为正确的枚举类型
static int Throhold = 40000;
unsigned long timeStamp;
unsigned long timeBudget;
void setup() {
myFilter.init(sampleRate, humFreq, true, true, true);
Serial.begin(115200);
timeBudget = 1e6 / 1000; // 直接使用数值或根据枚举值计算
}
void loop() {
timeStamp = micros();
int Value = analogRead(SensorInputPin);
// filter processing
int DataAfterFilter = myFilter.update(Value);
int envlope = sq(DataAfterFilter);
// any value under throhold will be set to zero
envlope = (envlope > Throhold) ? envlope : 0;
timeStamp = micros() - timeStamp;
if (TIMING_DEBUG) {
// Serial.print("Read Data: "); Serial.println(Value);
// Serial.print("Filtered Data: ");Serial.println(DataAfterFilter);
// Serial.print("Squared Data: ");
Serial.println(envlope);
// Serial.print("Filters cost time: "); Serial.println(timeStamp);
// the filter cost average around 520 us
}
/*------------end here---------------------*/
// if less than timeBudget, then you still have (timeBudget - timeStamp) to
// do your work
delayMicroseconds(500);
// if more than timeBudget, the sample rate need to reduce to
// SAMPLE_FREQ_500HZ
}这个例程调用了肌电的官方“EMGFilters”,这是一个用于处理肌电图(EMG)信号的数字滤波器库,主要功能是对原始EMG传感器数据进行多级滤波处理。主要功能:输入原始EMG信号数据(可选择启用/禁用各级滤波器);按顺序处理:陷波滤波 → 低通滤波 → 高通滤波。滤波器有:低通滤波器(LPF) 去除高频噪声 截止频率150Hz。高通滤波器(HPF) 去除直流分量和低频漂移 截止频率20Hz。陷波滤波器(AHF)去除工频干扰50Hz或60Hz。
在代码中有个阈值设置:Throhold 。当设置为0时,就是所有的波都进行放大处理。这里我将将传感器贴在小臂上。松弛状态下收集波形图。

可以看见,在小臂松弛状态下,波形在几千上下波动,经过几轮测试,设置阈值为40000。这里就意味着将40000内的波全部过滤掉了。
这是设置好阈值后的小臂松弛波形图。

握拳时捕获到的波形图。


这里发现有几个问题:
1、传感器贴的位置会影响到获取波形的结果。
2、不同的动作,对应的波形图感觉没有特别强的特征。不太好做动作的识别。这幅图是握拳,搬动物品,和挥拳的动作。

3、肌肉松弛时,捶打肌肉也会有波形产生。
我要赚赏金
