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
main.cpp
- Committer:
- Bartvaart
- Date:
- 2015-10-06
- Revision:
- 3:344b173f85fe
- Parent:
- 2:ae55928ff00f
- Child:
- 4:3b9e2d49d5fb
File content as of revision 3:344b173f85fe:
#include "mbed.h"
#include "HIDScope.h"
#include "encoder.h"
#include "Filter.h"
AnalogIn emg(A0); //Analog input van emg kabels
Ticker EMGticker;
HIDScope scope(2); //2 scopes
// constante variabelen:
//Sample frequentie
double Fs = 500; //Hz
double t = 1/ Fs; // voor EMGticker
// Filter1a: 50Hz Notch
double v1_50a = 0, v2_50a = 0;
const double a1_50a = -1.61803398875, a2_50a = 1.00000000000;
const double b0_50a = 1.00000000000, b1_50a = -1.61803398875, b2_50a = 1.00000000000;
const double gain_50a = 1.000000;
// Filter1b: 50Hz Notch
double v1_50b = 0, v2_50b = 0;
const double a1_50b = -1.61803398875, a2_50b = 1.00000000000;
const double b0_50b = 1.00000000000, b1_50b = -1.61803398875, b2_50b = 1.00000000000;
const double gain_50b = 1.000000;
// Filter1: 20Hz HighPass
double v1_HP = 0, v2_HP = 0;
const double a1_HP = -0.76475499450, a2_HP = 0.27692273367;
const double b0_HP = 1.00000000000, b1_HP = -2.00000000000, b2_HP = 1.00000000000;
const double gain_HP = 0.510419;
// Filter1: 5Hz LowPass
double v1_LP = 0, v2_LP = 0;
const double a1_LP = -1.16338171052, a2_LP = 0.42191097989;
const double b0_LP = 1.00000000000, b1_LP = 2.00000000000, b2_LP = 1.00000000000;
const double gain_LP = 0.064632;
void EMGfilter()
{
//u = input waarde
//y = output waarde
double u = emg.read(); // lees waarde van emg signaal uit
// Op deze manier worden de waardes ingelezen in Filter. Zorg dus voor dezelfde volgorde, zodat de waardes goed uitgelezen worden!:
// Filter(double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2, const double gain)
// 50Hz Notch filter
double y50a = Filter(u, v1_50a, v2_50a, a1_50a, a2_50a, b0_50a, b1_50a, b2_50a, gain_50a);
double y50b = Filter(y50a, v1_50b, v2_50b, a1_50b, a2_50b, b0_50b, b1_50b, b2_50b, gain_50b);
// High Pass filter. Tot 20Hz wordt weggefliterd
double yHP = Filter(y50b, v1_HP, v2_HP, a1_HP, a2_HP, b0_HP, b1_HP, b2_HP, gain_HP);
// Absolute waarde wordt genomen.
double y1 = fabs(yHP);
// 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);
double y = 10 * yLP;
// Plotten in HIDscope
scope.set(0,u); //ongefilterde waarde naar scope 1
scope.set(1,y); //gefilterde waarde naar scope 2
scope.send(); //stuur de waardes naar HIDscope
}
int main(){
EMGticker.attach(&EMGfilter, t); //500Hz
while(1){}
}