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 biquadFilter mbed
Diff: main.cpp
- Revision:
- 6:da06585e106c
- Parent:
- 5:02b3550e1ff0
- Child:
- 7:a928724ef731
--- a/main.cpp Tue Oct 25 18:32:01 2016 +0000
+++ b/main.cpp Tue Oct 25 20:38:53 2016 +0000
@@ -10,23 +10,28 @@
//Creating two scope channels
HIDScope scope(3);
+//Low-pass filter at 200Hz to avoid alliasing
+BiQuadChain low_pass_200;
+BiQuad bq1( 0.73638326364, 1.47272205824, 0.73638326364, 1.36239603912, 0.48048795767);
+BiQuad bq2( 0.83856791742, 1.67684080778, 0.83856791742, 1.68114429812, 0.7942832489);
+
//Notch filter
BiQuadChain notch_50;
-BiQuad bq1( 1.00007369335,-1.61815834791, 1.00007369335, -1.60983662066, 0.98986119869);
-BiQuad bq2( 1.00000000000,-1.61803910919, 1.00000000000, -1.60936554071, 0.99545624832);
-BiQuad bq3( 0.99035034846,-1.60242559561, 0.99035034846, -1.61934542233, 0.9955088075);
+BiQuad bq3( 1.00007369335,-1.61815834791, 1.00007369335, -1.60983662066, 0.98986119869);
+BiQuad bq4( 1.00000000000,-1.61803910919, 1.00000000000, -1.60936554071, 0.99545624832);
+BiQuad bq5( 0.99035034846,-1.60242559561, 0.99035034846, -1.61934542233, 0.9955088075);
//High pass filter
BiQuadChain high_pass;
-BiQuad bq4( 0.83315051810,-1.66630103620, 0.83315051810, -1.55025104412, 0.60696783282);
-BiQuad bq5( 0.86554941044,-1.73109882088, 0.86554941044, -1.74142633961, 0.78400451004);
-BiQuad bq6( 0.92490714701,-1.84981429401, 0.92490714701, -1.90032503529, 0.9352152620);
+BiQuad bq6( 0.83315051810,-1.66630103620, 0.83315051810, -1.55025104412, 0.60696783282);
+BiQuad bq7( 0.86554941044,-1.73109882088, 0.86554941044, -1.74142633961, 0.78400451004);
+BiQuad bq8( 0.92490714701,-1.84981429401, 0.92490714701, -1.90032503529, 0.9352152620);
//Low pass filter
BiQuadChain low_pass;
-BiQuad bq7( 0.00040400257, 0.00080800515, 0.00040400257,-1.92223307595, 0.92384908624);
-BiQuad bq8( 0.00040816681, 0.00081633362, 0.00040816681,-1.94204639240, 0.94367905964);
-BiQuad bq9( 0.00041558628, 0.00083117256, 0.00041558628,-1.97734803172, 0.9790103768);
+BiQuad bq9( 0.00040400257, 0.00080800515, 0.00040400257,-1.92223307595, 0.92384908624);
+BiQuad bq10( 0.00040816681, 0.00081633362, 0.00040816681,-1.94204639240, 0.94367905964);
+BiQuad bq11( 0.00041558628, 0.00083117256, 0.00041558628,-1.97734803172, 0.9790103768);
//Ticker
Ticker emgSampleTicker;
@@ -48,6 +53,7 @@
bool go_emgSample;
bool go_find_minmax;
double emg_sample[3];
+double emg_low_passed_200[3];
double emg_notch[3];
double emg_high_passed[3];
double emg_low_passed[3];
@@ -91,9 +97,10 @@
int main() {
//combine biquads in biquad chains for notch/high- low-pass filters
- notch_50.add( &bq1 ).add( &bq2 ).add( &bq3 );
- high_pass.add( &bq4 ).add( &bq5 ).add( &bq6 );
- low_pass.add( &bq7 ).add( &bq8 ).add( &bq9 );
+ low_pass_200.add( &bq1 ).add( &bq2 );
+ notch_50.add( &bq3 ).add( &bq4 ).add( &bq5 );
+ high_pass.add( &bq6 ).add( &bq7 ).add( &bq8 );
+ low_pass.add( &bq9 ).add( &bq10 ).add( &bq11 );
led.write(1);
change_state.attach( &calibrate,5);
@@ -115,8 +122,11 @@
emg_sample[2] = emg2.read();
for (int i = 0; i < 3; i++){
+ //low pass at 200Hz to avoid alliasing
+ emg_low_passed_200[i] = low_pass_200.step(emg_sample[i]);
+
//filter out the 50Hz components with a notch filter
- emg_notch[i] = notch_50.step(emg_sample[i]);
+ emg_notch[i] = notch_50.step(emg_low_passed_200[i]);
//high pass the signal (removing motion artifacts and offset)
emg_high_passed[i] = high_pass.step(emg_notch[i]);