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 MODSERIAL QEI biquadFilter mbed Servo
Diff: help_functions/processing_chain_emg.h
- Revision:
- 41:e9d6fdf02074
- Parent:
- 25:734a26538711
--- a/help_functions/processing_chain_emg.h Wed Oct 31 14:24:58 2018 +0000
+++ b/help_functions/processing_chain_emg.h Wed Oct 31 15:05:04 2018 +0000
@@ -6,59 +6,59 @@
// filter chains for high pass, low pass and notch filters
BiQuadChain bqc0;
BiQuadChain bqc1;
+BiQuadChain bqc2;
+BiQuadChain bqc3;
-// these are for sampling frequency 1000 Hz
-BiQuad bq0low( 0.1311, 0.2622, 0.1311, -0.7478, 0.2722);
-BiQuad bq0high( 0.9150, -1.8299, 0.9150, -1.8227, 0.8372);
-BiQuad bq0notch( 0.9695, -1.8442, 0.9695, -1.8442, 0.9391);
+// Filters for sampling frequency 1000 Hz
-BiQuad bq1low( 0.1311, 0.2622, 0.1311, -0.7478, 0.2722);
-BiQuad bq1high( 0.9150, -1.8299, 0.9150, -1.8227, 0.8372);
-BiQuad bq1notch( 0.9695, -1.8442, 0.9695, -1.8442, 0.9391);
+// emg signal 0 filters
+//BiQuad bq0low( 0.3913/10000.0, 0.7826/10000.0, 0.3913/10000.0, -1.9822, 0.9824); // 2 Hz cutoff
+BiQuad bq0low( 0.0877/1000.0, 0.1753/1000.0, 0.0877/1000.0, -1.9733, 0.9737); // 3 Hz cutoff
+//BiQuad bq0low( 0.3460/1000.0, 0.6921/1000.0, 0.3460/1000.0, -1.9467, 0.9481); // 6 Hz cutoff
+BiQuad bq0high( 0.9150, -1.8299, 0.9150, -1.8227, 0.8372); //cutoff at 20 Hz
+BiQuad bq0notch( 0.9695, -1.8442, 0.9695, -1.8442, 0.9391); //notch 50 Hz
+BiQuad bq0notch2( 0.9695, -1.5687, 0.9695, -1.5687, 0.9391);//notch 100 Hz
+BiQuad bq0notch3( 0.9695, -1.1398, 0.9695, -1.1398, 0.9391);//notch 150 Hz
+BiQuad bq0notch4( 0.9695, -0.5992, 0.9695, -0.5992, 0.9391);//notch 200 Hz
-// old filters
-//BiQuad bqlow( 0.3767, 0.7533, 0.3767, 0.3172, 0.1894);
-//BiQuad bqhigh( 0.6458, -1.2917, 0.6458, -1.1620, 0.4213);
-//BiQuad bqnotch( 0.5, 0, 0.5, 0, 0);
+// emg signal 1 filters
+//BiQuad bq1low( 0.3913/10000.0, 0.7826/10000.0, 0.3913/10000.0, -1.9822, 0.9824); // 2 Hz cutoff
+BiQuad bq1low( 0.0877/1000.0, 0.1753/1000.0, 0.0877/1000.0, -1.9733, 0.9737); // 3 Hz cutoff
+//BiQuad bq1low( 0.3460/1000.0, 0.6921/1000.0, 0.3460/1000.0, -1.9467, 0.9481); // 6 Hz cutoff
+BiQuad bq1high( 0.9150, -1.8299, 0.9150, -1.8227, 0.8372); //cutoff at 20 Hz
+BiQuad bq1notch( 0.9695, -1.8442, 0.9695, -1.8442, 0.9391); //notch 50 Hz
+BiQuad bq1notch2( 0.9695, -1.5687, 0.9695, -1.5687, 0.9391);//notch 100 Hz
+BiQuad bq1notch3( 0.9695, -1.1398, 0.9695, -1.1398, 0.9391);//notch 150 Hz
+BiQuad bq1notch4( 0.9695, -0.5992, 0.9695, -0.5992, 0.9391);//notch 200 Hz
-const int k = 300; // number of moving average samples
-double movavg0[k]= { }; // array with samples emg0
-double movavg1[k]= { }; // array with samples emg1
-int n = 0; // counter
-bool full = 0; // boolean to check if we have already had 300 samples
+// emg signal 2 filters
+//BiQuad bq2low( 0.3913/10000.0, 0.7826/10000.0, 0.3913/10000.0, -1.9822, 0.9824); // 2 Hz cutoff
+BiQuad bq2low( 0.0877/1000.0, 0.1753/1000.0, 0.0877/1000.0, -1.9733, 0.9737); // 3 Hz cutoff
+//BiQuad bq2low( 0.3460/1000.0, 0.6921/1000.0, 0.3460/1000.0, -1.9467, 0.9481); // 6 Hz cutoff
+BiQuad bq2high( 0.9150, -1.8299, 0.9150, -1.8227, 0.8372); //cutoff at 20 Hz
+BiQuad bq2notch( 0.9695, -1.8442, 0.9695, -1.8442, 0.9391); //notch 50 Hz
+BiQuad bq2notch2( 0.9695, -1.5687, 0.9695, -1.5687, 0.9391);//notch 100 Hz
+BiQuad bq2notch3( 0.9695, -1.1398, 0.9695, -1.1398, 0.9391);//notch 150 Hz
+BiQuad bq2notch4( 0.9695, -0.5992, 0.9695, -0.5992, 0.9391);//notch 200 Hz
-void processing_chain_emg(double &raw_emg_0, double &raw_emg_1, double &process_emg_0, double &process_emg_1) {
+// emg signal 3 filters
+//BiQuad bq3low( 0.3913/10000.0, 0.7826/10000.0, 0.3913/10000.0, -1.9822, 0.9824); // 2 Hz cutoff
+BiQuad bq3low( 0.0877/1000.0, 0.1753/1000.0, 0.0877/1000.0, -1.9733, 0.9737); // 3 Hz cutoff
+//BiQuad bq3low( 0.3460/1000.0, 0.6921/1000.0, 0.3460/1000.0, -1.9467, 0.9481); // 6 Hz cutoff
+BiQuad bq3high( 0.9150, -1.8299, 0.9150, -1.8227, 0.8372); //cutoff at 20 Hz
+BiQuad bq3notch( 0.9695, -1.8442, 0.9695, -1.8442, 0.9391); //notch 50 Hz
+BiQuad bq3notch2( 0.9695, -1.5687, 0.9695, -1.5687, 0.9391);//notch 100 Hz
+BiQuad bq3notch3( 0.9695, -1.1398, 0.9695, -1.1398, 0.9391);//notch 150 Hz
+BiQuad bq3notch4( 0.9695, -0.5992, 0.9695, -0.5992, 0.9391);//notch 200 Hz
+
+
+void processing_chain_emg(double &raw_emg_0, double &raw_emg_1, double &raw_emg_2, double &raw_emg_3, double &process_emg_0, double &process_emg_1, double &process_emg_2, double &process_emg_3) {
// we first filter high pass and notch, then rectifier and after that low pass
- movavg0[n] = bq0low.step(fabs(bqc0.step( raw_emg_0 )));
- movavg1[n] = bq1low.step(fabs(bqc1.step( raw_emg_1 )));
+ process_emg_0 = bq0low.step(fabs(bqc0.step( raw_emg_0 )));
+ process_emg_1 = bq1low.step(fabs(bqc1.step( raw_emg_1 )));
+ process_emg_2 = bq2low.step(fabs(bqc2.step( raw_emg_2 )));
+ process_emg_3 = bq3low.step(fabs(bqc3.step( raw_emg_3 )));
- // moving average
- double emgavg0 = 0, emgavg1 = 0;
- if(full == 0){
- for(int i=0;i<k;i++){
- emgavg0 = emgavg0 + movavg0[i];
- emgavg1 = emgavg1 + movavg1[i];
- }
- emgavg0 = emgavg0/(n+1);
- emgavg1 = emgavg1/(n+1);
- }
- else{
- for(int i=0;i<k;i++){
- emgavg0 = emgavg0 + movavg0[i];
- emgavg1 = emgavg1 + movavg1[i];
- }
- emgavg0 = emgavg0/k;
- emgavg1 = emgavg1/k;
- }
- n++;
- if(n == k){
- n = 0; // reset counter when end array reached
- full = 1; // assures we are past 300 samples
- }
-
- // outputs
- process_emg_0 = emgavg0;
- process_emg_1 = emgavg1;
}