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 TextLCD mbed
Fork of TotalControlEmg2 by
Revision 10:897db0bdb2fe, committed 2015-10-07
- Comitter:
- Bartvaart
- Date:
- Wed Oct 07 14:34:55 2015 +0000
- Parent:
- 9:1655d67d8a53
- Child:
- 11:17b1d5f5370b
- Child:
- 13:b01231e0b743
- Commit message:
- Filter werkt vloeiend; vergroting weg
Changed in this revision
--- a/Filterdesigns.cpp Wed Oct 07 13:48:19 2015 +0000
+++ b/Filterdesigns.cpp Wed Oct 07 14:34:55 2015 +0000
@@ -1,5 +1,6 @@
#include "Filterdesigns.h"
#include "Filter.h"
+#include "Meanvalue.h"
// Inputwaardes
// Filter1a: 50Hz Notch
@@ -32,8 +33,14 @@
double gem = 0.4557; // gemiddelde waarde emgsignaal
+//gemiddelde bepalen
+double sum = 0;
+int a = 0;
+int delay = 40;
+int samples_length = 10;
-void Filterdesign1(double u, double &y)
+
+void Filterdesign1(double u, double &y, double &ymean)
{
//u = input waarde
//y = output waarde
@@ -56,5 +63,9 @@
// Low Pass filter. Alles vanaf 5Hz wordt weggefilterd
double yLP = Filter(y1, v1_LP, v2_LP, a1_LP, a2_LP, b0_LP, b1_LP, b2_LP, gain_LP);
- y = 10 * yLP;
+ y = yLP;
+
+ //ymean = Meanvalue(y, sum, a, ymean, delay);
+ ymean = Meansmooth(y, samples_length, ymean);
+
}
\ No newline at end of file
--- a/Filterdesigns.h Wed Oct 07 13:48:19 2015 +0000 +++ b/Filterdesigns.h Wed Oct 07 14:34:55 2015 +0000 @@ -1,3 +1,3 @@ #include "mbed.h" -void Filterdesign1(double u, double &y); \ No newline at end of file +void Filterdesign1(double u, double &y, double &ymean); \ No newline at end of file
--- a/Meanvalue.cpp Wed Oct 07 13:48:19 2015 +0000
+++ b/Meanvalue.cpp Wed Oct 07 14:34:55 2015 +0000
@@ -1,8 +1,8 @@
#include "Meanvalue.h"
-//gemiddelde bepalen
+double samples[30] = {};
-double Meanvalue(double y, double &sum, double &ymean, int &a, int delay){
+double Meanvalue(double y, double &sum, int &a, double &ymean, int delay){
sum = sum + y;
a = a + 1;
@@ -18,6 +18,21 @@
return ymean;
}
}
+
+double Meansmooth(double y, int samples_length, double &ymean){
-//double Meansmooth(double y, double &sum, int &a, double &ymean, int delay){
- // }
\ No newline at end of file
+ for ( int n=30 ; n>1 ; n-- ){
+ samples[n] = samples[n-1];
+ }
+
+ samples[1] = y;
+
+ for ( int n=30 ; n>0 ; n-- ){
+ ymean = ymean + samples [n];
+ }
+ ymean = ymean / 30;
+
+ return ymean;
+
+ }
+
\ No newline at end of file
--- a/Meanvalue.h Wed Oct 07 13:48:19 2015 +0000 +++ b/Meanvalue.h Wed Oct 07 14:34:55 2015 +0000 @@ -1,3 +1,6 @@ #include "mbed.h" -double Meanvalue(double y, double &sum, double &ymean, int &a, int delay); \ No newline at end of file +double Meanvalue(double y, double &sum, int &a, double &ymean, int delay); + + +double Meansmooth(double y, int samples_length, double &ymean); \ No newline at end of file
--- a/main.cpp Wed Oct 07 13:48:19 2015 +0000
+++ b/main.cpp Wed Oct 07 14:34:55 2015 +0000
@@ -1,7 +1,6 @@
#include "mbed.h"
#include "HIDScope.h"
#include "Filterdesigns.h"
-#include "Meanvalue.h"
AnalogIn emg(A0); //Analog input van emg kabels
HIDScope scope(3); //2 scopes
@@ -11,20 +10,13 @@
double Fs = 500; //Hz
double t = 1/ Fs; // voor EMGticker
-// gemidelde waarde
-double sum = 0;
+double y = 0;
double ymean = 0;
-int a = 0;
-int delay = 40;
-
-double y=0;
-
void EMGfilter(){
//uitlezen emg signaal
double u = emg.read();
- Filterdesign1(u, y);
- double ymean = Meanvalue(y, sum, ymean, a, delay);
+ Filterdesign1(u,y, ymean);
// Plotten in HIDscope
scope.set(0,u); //ongefilterde waarde naar scope 1
