Silvie van den Bogaard / Mbed 2 deprecated emg_calibration

Dependencies:   BiQuad4th_order Biquad HIDScope MODSERIAL biquadFilter mbed

Files at this revision

API Documentation at this revision

Comitter:
Duif
Date:
Wed Oct 31 12:57:37 2018 +0000
Child:
1:f99650c5b9eb
Commit message:
Weird error. Editions made so the calibration can be checked;

Changed in this revision

BiQuad4th_order.lib Show annotated file Show diff for this revision Revisions of this file
Biquad.lib Show annotated file Show diff for this revision Revisions of this file
Filter/Filter/FilterDesign.cpp Show annotated file Show diff for this revision Revisions of this file
Filter/Filter/FilterDesign.h Show annotated file Show diff for this revision Revisions of this file
Filter/FilterDesign.cpp Show annotated file Show diff for this revision Revisions of this file
Filter/FilterDesign.h Show annotated file Show diff for this revision Revisions of this file
Filter2/FilterDesign2.cpp Show annotated file Show diff for this revision Revisions of this file
Filter2/FilterDesign2.h Show annotated file Show diff for this revision Revisions of this file
biquadFilter.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BiQuad4th_order.lib	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Mirjam/code/BiQuad4th_order/#caa20b96f300
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Biquad.lib	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Gerth/code/Biquad/#3a80d1f8f30a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter/Filter/FilterDesign.cpp	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,62 @@
+#include "FilterDesign.h"
+#include "BiQuad.h"
+#include "BiQuad4.h"
+
+// Notch filter op 50 Hz
+double nb0 = 0.999103206817809;
+double nb1 = -1.994263409725146;
+double nb2 = 0.999103206817809;
+double na1 = -1.994263409725146;
+double na2 = 0.998206413635618;
+
+// 4th order Butterworth High pass 10 Hz
+double hpb0 = 0.922946103200875;
+double hpb1 = -3.691784412803501;
+double hpb2 = 5.537676619205252; 
+double hpb3 = -3.691784412803501;
+double hpb4 = 0.922946103200875;
+double hpa1 = -3.839672788481732;
+double hpa2 = 5.531745865737864;
+double hpa3 = -3.543889487580057;
+double hpa4 = 0.851829509414351;
+
+/*
+// 4th order Butterworth Low pass 6 Hz
+double lpb0 = 0.000000109473538449645 ;
+double lpb1 = 0.000000437894153798579 ;
+double lpb2 = 0.000000656841230697869; 
+double lpb3 = 0.000000437894153798579;
+double lpb4 = 0.000000109473538449645;
+double lpa1 = -3.903798995738811;
+double lpa2 = 5.715997307717368;
+double lpa3 = -3.720469814151233;
+double lpa4 = 0.908273253749291;
+*/
+
+//4th order Butterworth low pass 9 Hz
+double lpb0 = 0.00000054134117189603 ;
+double lpb1 = 0.00000216536468758410  ;
+double lpb2 = 0.00000324804703137616; 
+double lpb3 = 0.00000216536468758410;
+double lpb4 = 0.00000054134117189603;
+double lpa1 = -3.855703428197204;
+double lpa2 = 5.577429961461492;
+double lpa3 = -3.587322565783154;
+double lpa4 = 0.865604693977616;
+
+double gain = 10.00000;
+
+BiQuad notch50(nb0, nb1, nb2, na1, na2);
+BiQuad4 highpass(hpb0, hpb1, hpb2, hpb3, hpb4, hpa1, hpa2, hpa3, hpa4);
+BiQuad4 lowpass(lpb0, lpb1, lpb2, lpb3, lpb4, lpa1, lpa2, lpa3, lpa4);
+
+double FilterDesign(double u)
+{   
+    double y_n = notch50.step(u);
+    double y_hp = highpass.step(y_n);
+    double y_abs = abs(y_hp);
+    double y_lp = lowpass.step(y_abs);
+    double y_gain = y_lp*gain;
+    
+    return y_gain;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter/Filter/FilterDesign.h	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,3 @@
+#include "mbed.h"
+ 
+double FilterDesign(double u);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter/FilterDesign.cpp	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,62 @@
+#include "FilterDesign.h"
+#include "BiQuad.h"
+#include "BiQuad4.h"
+
+// Notch filter op 50 Hz
+double nb0 = 0.999103206817809;
+double nb1 = -1.994263409725146;
+double nb2 = 0.999103206817809;
+double na1 = -1.994263409725146;
+double na2 = 0.998206413635618;
+
+// 4th order Butterworth High pass 10 Hz
+double hpb0 = 0.922946103200875;
+double hpb1 = -3.691784412803501;
+double hpb2 = 5.537676619205252; 
+double hpb3 = -3.691784412803501;
+double hpb4 = 0.922946103200875;
+double hpa1 = -3.839672788481732;
+double hpa2 = 5.531745865737864;
+double hpa3 = -3.543889487580057;
+double hpa4 = 0.851829509414351;
+
+/*
+// 4th order Butterworth Low pass 6 Hz
+double lpb0 = 0.000000109473538449645 ;
+double lpb1 = 0.000000437894153798579 ;
+double lpb2 = 0.000000656841230697869; 
+double lpb3 = 0.000000437894153798579;
+double lpb4 = 0.000000109473538449645;
+double lpa1 = -3.903798995738811;
+double lpa2 = 5.715997307717368;
+double lpa3 = -3.720469814151233;
+double lpa4 = 0.908273253749291;
+*/
+
+//4th order Butterworth low pass 9 Hz
+double lpb0 = 0.00000054134117189603 ;
+double lpb1 = 0.00000216536468758410  ;
+double lpb2 = 0.00000324804703137616; 
+double lpb3 = 0.00000216536468758410;
+double lpb4 = 0.00000054134117189603;
+double lpa1 = -3.855703428197204;
+double lpa2 = 5.577429961461492;
+double lpa3 = -3.587322565783154;
+double lpa4 = 0.865604693977616;
+
+double gain = 10.00000;
+
+BiQuad notch50(nb0, nb1, nb2, na1, na2);
+BiQuad4 highpass(hpb0, hpb1, hpb2, hpb3, hpb4, hpa1, hpa2, hpa3, hpa4);
+BiQuad4 lowpass(lpb0, lpb1, lpb2, lpb3, lpb4, lpa1, lpa2, lpa3, lpa4);
+
+double FilterDesign(double u)
+{   
+    double y_n = notch50.step(u);
+    double y_hp = highpass.step(y_n);
+    double y_abs = abs(y_hp);
+    double y_lp = lowpass.step(y_abs);
+    double y_gain = y_lp*gain;
+    
+    return y_gain;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter/FilterDesign.h	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,3 @@
+#include "mbed.h"
+ 
+double FilterDesign(double u);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter2/FilterDesign2.cpp	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,62 @@
+#include "FilterDesign2.h"
+#include "BiQuad.h"
+#include "BiQuad4.h"
+
+// Notch filter op 50 Hz
+double nb0_2 = 0.999103206817809;
+double nb1_2 = -1.994263409725146;
+double nb2_2 = 0.999103206817809;
+double na1_2 = -1.994263409725146;
+double na2_2 = 0.998206413635618;
+
+// 4th order Butterworth High pass 10 Hz
+double hpb0_2 = 0.922946103200875;
+double hpb1_2 = -3.691784412803501;
+double hpb2_2 = 5.537676619205252; 
+double hpb3_2 = -3.691784412803501;
+double hpb4_2 = 0.922946103200875;
+double hpa1_2 = -3.839672788481732;
+double hpa2_2 = 5.531745865737864;
+double hpa3_2 = -3.543889487580057;
+double hpa4_2 = 0.851829509414351;
+
+/*
+// 4th order Butterworth Low pass 6 Hz
+double lpb0 = 0.000000109473538449645 ;
+double lpb1 = 0.000000437894153798579 ;
+double lpb2 = 0.000000656841230697869; 
+double lpb3 = 0.000000437894153798579;
+double lpb4 = 0.000000109473538449645;
+double lpa1 = -3.903798995738811;
+double lpa2 = 5.715997307717368;
+double lpa3 = -3.720469814151233;
+double lpa4 = 0.908273253749291;
+*/
+
+//4th order Butterworth low pass 9 Hz
+double lpb0_2 = 0.00000054134117189603 ;
+double lpb1_2 = 0.00000216536468758410  ;
+double lpb2_2 = 0.00000324804703137616; 
+double lpb3_2 = 0.00000216536468758410;
+double lpb4_2 = 0.00000054134117189603;
+double lpa1_2 = -3.855703428197204;
+double lpa2_2 = 5.577429961461492;
+double lpa3_2 = -3.587322565783154;
+double lpa4_2 = 0.865604693977616;
+
+double gain_2 = 10.00000;
+
+BiQuad notch50_2(nb0_2, nb1_2, nb2_2, na1_2, na2_2);
+BiQuad4 highpass_2(hpb0_2, hpb1_2, hpb2_2, hpb3_2, hpb4_2, hpa1_2, hpa2_2, hpa3_2, hpa4_2);
+BiQuad4 lowpass_2(lpb0_2, lpb1_2, lpb2_2, lpb3_2, lpb4_2, lpa1_2, lpa2_2, lpa3_2, lpa4_2);
+
+double FilterDesign2(double u)
+{   
+    double y_n_2 = notch50_2.step(u);
+    double y_hp_2 = highpass_2.step(y_n_2);
+    double y_abs_2 = abs(y_hp_2);
+    double y_lp_2 = lowpass_2.step(y_abs_2);
+    double y_gain_2 = y_lp_2*gain_2;
+    
+    return y_gain_2;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter2/FilterDesign2.h	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,3 @@
+#include "mbed.h"
+ 
+double FilterDesign2(double u);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/biquadFilter.lib	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tomlankhorst/code/biquadFilter/#26861979d305
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "BiQuad.h"
+#include "BiQuad4.h"
+#include "FilterDesign.h"
+#include "FilterDesign2.h"
+MODSERIAL pc(USBTX, USBRX); //makes sure the computer is hooked up
+
+AnalogIn emg1_raw(A0);
+AnalogIn emg2_raw(A1);
+DigitalOut led(LED_RED);
+
+//global variables
+double emg1_cal = 0.00000; //measured value of the first emg
+double emg2_cal = 0.00000; //measured value of the second emg
+double EMG_calibrated_max_1 = 0.00000; //final calibration value of EMG1
+double EMG_calibrated_max_2 = 0.00000; //final calibration value of EMG2
+
+
+void EMG_calibration(){
+    for (int i = 0; i <= 10; i++) //10 measuring points
+        { 
+        emg1_cal = FilterDesign(emg1_raw.read());
+        emg2_cal = FilterDesign2(emg2_raw.read());
+        
+        if (emg1_cal > EMG_calibrated_max_1){
+            EMG_calibrated_max_1 = emg1_cal;}
+            
+        if (emg2_cal > EMG_calibrated_max_2){
+            EMG_calibrated_max_2 = emg2_cal;}
+        
+        wait(0.5f);
+        }
+}
+
+        
+
+int main(){
+    pc.baud(115200);
+    while (true) {
+        led = 0;
+        EMG_calibration();
+        led = 1;
+        pc.printf("EMG1 = %f, EMG2 = %f \r\n",EMG_calibrated_max_1,EMG_calibrated_max_2);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 31 12:57:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/675da3299148
\ No newline at end of file