even versimpelen

Dependencies:   HIDScope MODSERIAL PID QEI biquadFilter mbed

Fork of cpfromralph1 by Remi van Veen

Committer:
relvorelvo
Date:
Wed Nov 02 12:55:41 2016 +0000
Revision:
22:68ab712b62b2
Parent:
21:136a1ab8163c
Child:
23:e5db011bd410
Working filters

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
relvorelvo 21:136a1ab8163c 3 #include "BiQuad.h"
relvorelvo 21:136a1ab8163c 4 #include "MODSERIAL.h"
vsluiter 0:32bb76391d89 5
vsluiter 4:8b298dfada81 6 //Define objects
relvorelvo 21:136a1ab8163c 7 AnalogIn emg1_in( A0 );
relvorelvo 21:136a1ab8163c 8 AnalogIn emg2_in( A1 );
tomlankhorst 19:2bf824669684 9
tomlankhorst 14:f83354387756 10 Ticker sample_timer;
relvorelvo 22:68ab712b62b2 11 HIDScope scope( 3 );
relvorelvo 21:136a1ab8163c 12 DigitalOut red(LED_RED);
relvorelvo 21:136a1ab8163c 13 DigitalOut blue(LED_BLUE);
relvorelvo 21:136a1ab8163c 14 DigitalOut green(LED_GREEN);
relvorelvo 22:68ab712b62b2 15 DigitalOut emg1_out( D8 );
relvorelvo 22:68ab712b62b2 16 DigitalOut emg2_out( D9 );
relvorelvo 21:136a1ab8163c 17 MODSERIAL pc(USBTX, USBRX);
relvorelvo 21:136a1ab8163c 18
relvorelvo 21:136a1ab8163c 19
relvorelvo 21:136a1ab8163c 20 // EMG variables
relvorelvo 21:136a1ab8163c 21 double emg1;
relvorelvo 21:136a1ab8163c 22 double emg1highfilter;
relvorelvo 21:136a1ab8163c 23 double emg1notchfilter;
relvorelvo 22:68ab712b62b2 24 double emg1abs;
relvorelvo 21:136a1ab8163c 25 double emg1lowfilter;
relvorelvo 22:68ab712b62b2 26 double emgpeak;
relvorelvo 21:136a1ab8163c 27
relvorelvo 21:136a1ab8163c 28 double emg2;
relvorelvo 21:136a1ab8163c 29 double emg2highfilter;
relvorelvo 21:136a1ab8163c 30 double emg2notchfilter;
relvorelvo 22:68ab712b62b2 31 double emg2abs;
relvorelvo 21:136a1ab8163c 32 double emg2lowfilter;
vsluiter 2:e314bb3b2d99 33
relvorelvo 21:136a1ab8163c 34 // Filter settings
relvorelvo 21:136a1ab8163c 35 BiQuad filterhigh(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01);
relvorelvo 22:68ab712b62b2 36 BiQuad filternotch(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01);
relvorelvo 22:68ab712b62b2 37 BiQuad filterlow(1.439e-02,2.794e-02,1.397e-02,-1.7229,7.788e-01);
relvorelvo 22:68ab712b62b2 38 BiQuad filterpeak(1.0878,-1.950,8.771e-01,-1.95032,9.5499e-01);
relvorelvo 21:136a1ab8163c 39
relvorelvo 21:136a1ab8163c 40 // Filtering
relvorelvo 21:136a1ab8163c 41 void filter() {
relvorelvo 22:68ab712b62b2 42 emg1 = emg1_in.read();
relvorelvo 22:68ab712b62b2 43 emg1highfilter = filterhigh.step(emg1);
relvorelvo 22:68ab712b62b2 44 emg1notchfilter = filternotch.step(emg1highfilter);
relvorelvo 22:68ab712b62b2 45 emg1abs = fabs(emg1notchfilter);
relvorelvo 22:68ab712b62b2 46 emg1lowfilter = filterlow.step(emg1abs);
relvorelvo 22:68ab712b62b2 47 emgpeak = filterpeak.step(emg1lowfilter);
relvorelvo 21:136a1ab8163c 48
relvorelvo 22:68ab712b62b2 49 emg2 = emg2_in.read();
relvorelvo 22:68ab712b62b2 50 emg2highfilter = filterhigh.step(emg2);
relvorelvo 22:68ab712b62b2 51 emg2notchfilter = filternotch.step(emg2highfilter);
relvorelvo 22:68ab712b62b2 52 emg2abs = fabs(emg2notchfilter);
relvorelvo 22:68ab712b62b2 53 emg2lowfilter = filterlow.step(emg2abs);
relvorelvo 21:136a1ab8163c 54
tomlankhorst 19:2bf824669684 55 /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
relvorelvo 21:136a1ab8163c 56 scope.set(0, emg1_in.read() );
relvorelvo 22:68ab712b62b2 57 scope.set(1, emg1lowfilter );
relvorelvo 22:68ab712b62b2 58 scope.set(2, emgpeak );
relvorelvo 22:68ab712b62b2 59 /* Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 60 scope.send();
tomlankhorst 18:21d8e7a81cf5 61 /* To indicate that the function is working, the LED is toggled */
relvorelvo 22:68ab712b62b2 62 green = !green;
vsluiter 2:e314bb3b2d99 63 }
vsluiter 0:32bb76391d89 64
vsluiter 0:32bb76391d89 65 int main()
tomlankhorst 19:2bf824669684 66 {
tomlankhorst 15:0da764eea774 67
relvorelvo 22:68ab712b62b2 68 sample_timer.attach(&filter, 0.001);
relvorelvo 22:68ab712b62b2 69
tomlankhorst 15:0da764eea774 70 while(1) {}
vsluiter 0:32bb76391d89 71 }