Working moving average filter. IIR filters (low pass, high pass) still have to be implemented via biquad.
Dependencies: HIDScope biquadFilter mbed
Fork of EMG by
Revision 22:d2393c670afd, committed 2018-10-13
- Comitter:
- MaikOvermars
- Date:
- Sat Oct 13 15:48:22 2018 +0000
- Parent:
- 21:3ac3c2e9d9ae
- Commit message:
- Implemented biquad cascade of notch, low pass and high pass filter, all second order. This is in addition to the moving average and rectifier. Not tested yet on live emg-signal.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3ac3c2e9d9ae -r d2393c670afd main.cpp --- a/main.cpp Fri Oct 12 13:12:31 2018 +0000 +++ b/main.cpp Sat Oct 13 15:48:22 2018 +0000 @@ -11,18 +11,21 @@ // filter chains for high pass, low pass and notch filters BiQuadChain bqc; -BiQuad bq1( 4.1660e04,8.3320e04,4.1660e04,1.4797e+00,.5582e01); -BiQuad bq2( 1.0000e+00, 2.0000e+00, 1.0000e+00, 1.7010e+00,7.8850e01); +BiQuad bqlow( 0.0128, 0.0256, 0.0128, -1.6556, 0.7068); +BiQuad bqhigh( 0.6458, -1.2917, 0.6458, -1.1620, 0.4213); +BiQuad bqnotch( 0.5, 0, 0.5, 0, 0); volatile double y[50]= { }; volatile int n = 0; volatile bool full = 0; void emgSample() { - //double emgFiltered = bqc.step( emg0.read() ); - double emgFiltered = emg0.read(); - scope.set(0,emgFiltered); + double emgRaw = emg0.read(); + scope.set(0,emgRaw); - // moving average + double emgFiltered = bqc.step( emgRaw ); + scope.set(1,emgFiltered); + + // moving average and rectifier y[n] = abs(emgFiltered - 0.45); double emgavg = 0; if(full == 0){ @@ -42,7 +45,7 @@ n = 0; full = 1; } - scope.set(1,emgavg); + scope.set(2,emgavg); scope.send(); // do stuff with filtered point emgavg } @@ -50,7 +53,7 @@ int main() { - bqc.add( &bq1 ).add( &bq2 ); + bqc.add( &bqlow ).add( &bqhigh ).add( &bqnotch ); emgSampleTicker.attach( &emgSample, 0.01 ); /*empty loop, sample() is executed periodically*/