Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope mbed MODSERIAL QEI
main.cpp
- Committer:
- poephoofd
- Date:
- 2017-10-13
- Revision:
- 2:a08bff88216d
- Parent:
- 1:50ae89200a53
- Child:
- 3:9c5aea210f1d
File content as of revision 2:a08bff88216d:
#include "mbed.h"
#include"BiQuad.h"
#include "HIDScope.h"
#include "MODSERIAL.h"
//Initialize Analog EMG inputs
AnalogIn EMGData_1( A0 );
AnalogIn EMGData_2( A1 );
AnalogIn EMGData_3( A2 );
HIDScope scope(4); // 4 channels of data
Ticker MainTicker;
MODSERIAL pc(USBTX, USBRX);
const double Ts= 0.002; //fs = 500Hz
double EMG_MainsReject_1 = 0;
double EMG_MainsReject_2 = 0;
double EMG_MainsReject_3 = 0;
double EMG_Filtered_1 = 0;
double EMG_Filtered_2 = 0;
double EMG_Filtered_3 = 0;
double EMG_Abs_1 = 0;
double EMG_Abs_2 = 0;
double EMG_Abs_3 = 0;
double EMG_Envelope_1 = 0;
double EMG_Envelope_2 = 0;
double EMG_Envelope_3 = 0;
//High Pass Filter
double a_0_0=1, a_0_1=-1.475480443592646, a_0_2=0.586919508061190,
b_0_0=0.765599987913459, b_0_1=-1.531199975826918, b_0_2=0.765599987913459;
BiQuad HiPass(b_0_0, b_0_1, b_0_2, a_0_0, a_0_1, a_0_2);
/***********/
//Low Pass Filter
double a_1_0=1, a_1_1=-1.307285028849324, a_1_2=0.491812237222575,
b_1_0=0.0009446918438401619, b_1_1=0.001889383687680, b_1_2=0.0009446918438401619;
BiQuad LoPass(b_1_0, b_1_1, b_1_2, a_1_0, a_1_1, a_1_2);
/***********/
//Notch Filter
double a_2_0=1, a_2_1=-1.525271192436899, a_2_2=0.881618592363190,
b_2_0=0.940809296181595, b_2_1=-1.525271192436899, b_2_2=0.940809296181595;
BiQuad MainsReject(b_2_0, b_2_1, b_2_2, a_2_0, a_2_1, a_2_2);
/***********/
void ReadAndFilterEMG()
{
//MainsReject Filter EMG Data
EMG_MainsReject_1 = MainsReject.step(EMGData_1);
EMG_MainsReject_2 = MainsReject.step(EMGData_2);
EMG_MainsReject_3 = MainsReject.step(EMGData_3);
/*****/
//High Pass Filter EMG Data
EMG_Filtered_1 = HiPass.step(EMG_MainsReject_1);
EMG_Filtered_2 = HiPass.step(EMG_MainsReject_2);
EMG_Filtered_3 = HiPass.step(EMG_MainsReject_3);
/*****/
//Abs Filtered EMG Data
EMG_Abs_1 = abs(EMG_Filtered_1);
EMG_Abs_2 = abs(EMG_Filtered_2);
EMG_Abs_3 = abs(EMG_Filtered_3);
/*****/
//Low Pass Filter
EMG_Envelope_1 = LoPass.step(EMG_Abs_1);
EMG_Envelope_2 = LoPass.step(EMG_Abs_2);
EMG_Envelope_3 = LoPass.step(EMG_Abs_3);
/*****/
//Send scope data
scope.set(0, EMGData_1); //Raw Data
scope.set(1, EMG_Filtered_1); //Notch and High Pass Filtered
scope.set(2, EMG_Abs_1); //Absolute value
scope.set(3, EMG_Envelope_1); //Envelope Detected output
scope.send();
/*****/
}
int main(void)
{
pc.baud(115200); //Set Baud rate for Serial communication
MainTicker.attach(&ReadAndFilterEMG, Ts); //Attach time based interrupt
/*
while(true)
{
}
*/
return 0;
}
