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 biquadFilter mbed
main.cpp@3:61f0fc41f3bc, 2015-10-19 (annotated)
- Committer:
- RichellBooyink
- Date:
- Mon Oct 19 14:08:50 2015 +0000
- Revision:
- 3:61f0fc41f3bc
- Parent:
- 2:e3259334299e
- Child:
- 4:8db85182a00d
De filters werken allemaal. Hier zijn ook de waarden van de gain vermenigvuldigd met de constande b waardes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RichellBooyink | 0:2ded24549b70 | 1 | #include "mbed.h" |
RichellBooyink | 0:2ded24549b70 | 2 | #include "HIDScope.h" |
RichellBooyink | 0:2ded24549b70 | 3 | |
RichellBooyink | 1:16165e207e70 | 4 | AnalogIn EMG(A0); |
RichellBooyink | 3:61f0fc41f3bc | 5 | HIDScope scope(4); |
RichellBooyink | 0:2ded24549b70 | 6 | |
RichellBooyink | 0:2ded24549b70 | 7 | // Filter1 = High pass filter tot 20 Hz |
RichellBooyink | 0:2ded24549b70 | 8 | double fh1_v1=0, fh1_v2=0, fh2_v1=0, fh2_v2=0; |
RichellBooyink | 0:2ded24549b70 | 9 | const double fh1_a1=-0.84909054461, fh1_a2=0.00000000000, fh1_b0= 1, fh1_b1=-1, fh1_b2=0; |
RichellBooyink | 0:2ded24549b70 | 10 | const double fh2_a1=-1.82553264091, fh2_a2=0.85001416809, fh2_b0= 1, fh2_b1=-2, fh2_b2=1; |
RichellBooyink | 0:2ded24549b70 | 11 | // Filter2 = Low pass filter na 60 Hz |
RichellBooyink | 0:2ded24549b70 | 12 | double fl1_v1=0, fl1_v2=0, fl2_v1=0, fl2_v2=0; |
RichellBooyink | 0:2ded24549b70 | 13 | const double fl1_a1=-0.66979455390, fl1_a2=0.00000000000, fl1_b0= 1, fl1_b1=1, fl1_b2=0; |
RichellBooyink | 0:2ded24549b70 | 14 | const double fl2_a1=-1.55376616139, fl2_a2=0.68023470431, fl2_b0= 1, fl2_b1=2, fl2_b2=1; |
RichellBooyink | 0:2ded24549b70 | 15 | // Filter3 = Notch filter at 50 Hz |
RichellBooyink | 0:2ded24549b70 | 16 | double fno1_v1=0, fno1_v2=0, fno2_v1=0, fno2_v2=0, fno3_v1=0, fno3_v2=0; |
RichellBooyink | 0:2ded24549b70 | 17 | const double fno1_a1 = -1.87934916386, fno1_a2= 0.97731851355, fno1_b0= 1, fno1_b1= -1.90090686046, fno1_b2= 1; |
RichellBooyink | 0:2ded24549b70 | 18 | const double fno2_a1 = -1.88341028603, fno2_a2= 0.98825147717, fno2_b0= 1, fno2_b1= -1.90090686046, fno2_b2= 1; |
RichellBooyink | 0:2ded24549b70 | 19 | const double fno3_a1 = -1.89635403726, fno3_a2= 0.98894004849, fno3_b0= 1, fno3_b1= -1.90090686046, fno3_b2= 1; |
RichellBooyink | 2:e3259334299e | 20 | double y1, y2, y3, y4, y5, y6, y7, u1, u2, u3, u4, u5, u6, u7; |
RichellBooyink | 3:61f0fc41f3bc | 21 | |
RichellBooyink | 3:61f0fc41f3bc | 22 | // Standaard formule voor het biquad filter |
RichellBooyink | 3:61f0fc41f3bc | 23 | double biquad(double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2) |
RichellBooyink | 3:61f0fc41f3bc | 24 | |
RichellBooyink | 3:61f0fc41f3bc | 25 | { |
RichellBooyink | 3:61f0fc41f3bc | 26 | double v = u - a1*v1 - a2*v2; |
RichellBooyink | 3:61f0fc41f3bc | 27 | double y = b0*v + b1*v1 + b2*v2; |
RichellBooyink | 3:61f0fc41f3bc | 28 | v2=v1; |
RichellBooyink | 3:61f0fc41f3bc | 29 | v1=v; |
RichellBooyink | 3:61f0fc41f3bc | 30 | return y; |
RichellBooyink | 3:61f0fc41f3bc | 31 | } |
RichellBooyink | 3:61f0fc41f3bc | 32 | |
RichellBooyink | 2:e3259334299e | 33 | void Filters() |
RichellBooyink | 0:2ded24549b70 | 34 | { |
RichellBooyink | 2:e3259334299e | 35 | u1 = EMG.read(); |
RichellBooyink | 2:e3259334299e | 36 | //Highpass |
RichellBooyink | 3:61f0fc41f3bc | 37 | y1 = biquad (u1, fh1_v1, fh1_v2, fh1_a1, fh1_a2, fh1_b0*0.924547, fh1_b1*0.924547, fh1_b2*0.924547); |
RichellBooyink | 3:61f0fc41f3bc | 38 | u2 = y1; |
RichellBooyink | 3:61f0fc41f3bc | 39 | y2 = biquad (u2, fh2_v1, fh2_v2, fh2_a1, fh2_a2, fh2_b0*0.918885, fh2_b1*0.918885, fh2_b2*0.918885); |
RichellBooyink | 2:e3259334299e | 40 | //Lowpass |
RichellBooyink | 2:e3259334299e | 41 | u3 = y2; |
RichellBooyink | 3:61f0fc41f3bc | 42 | y3 = biquad (u3, fl1_v1, fl1_v2, fl1_a1, fl1_a2, fl1_b0*0.165103, fl1_b1*0.165103, fl1_b2*0.165103); |
RichellBooyink | 2:e3259334299e | 43 | u4 = y3; |
RichellBooyink | 3:61f0fc41f3bc | 44 | y4 = biquad (u4, fl2_v1, fl2_v2, fl2_a1, fl2_a2, fl2_b0*0.031617, fl2_b1*0.031617, fl2_b2*0.031617); |
RichellBooyink | 2:e3259334299e | 45 | // Notch |
RichellBooyink | 2:e3259334299e | 46 | u5 = y4; |
RichellBooyink | 3:61f0fc41f3bc | 47 | y5 = biquad (u5, fno1_v1, fno1_v2, fno1_a1, fno1_a2, fno1_b0*1.004206, fno1_b1*1.004206, fno1_b2*1.004206); |
RichellBooyink | 2:e3259334299e | 48 | u6 = y5; |
RichellBooyink | 3:61f0fc41f3bc | 49 | y6 = biquad (u6, fno2_v1, fno2_v2, fno2_a1, fno2_a2, fno2_b0, fno2_b1, fno2_b2); |
RichellBooyink | 2:e3259334299e | 50 | u7 = y6; |
RichellBooyink | 3:61f0fc41f3bc | 51 | y7 = biquad (u7, fno3_v1, fno3_v2, fno3_a1, fno3_a2, fno3_b0*0.973227, fno3_b1*0.973227, fno3_b2*0.973227); |
RichellBooyink | 2:e3259334299e | 52 | scope.set (0, u1); |
RichellBooyink | 2:e3259334299e | 53 | scope.set (1, y2); |
RichellBooyink | 2:e3259334299e | 54 | scope.set (2, y4); |
RichellBooyink | 2:e3259334299e | 55 | scope.set (3, y7); |
RichellBooyink | 1:16165e207e70 | 56 | scope.send (); |
RichellBooyink | 1:16165e207e70 | 57 | } |
RichellBooyink | 2:e3259334299e | 58 | Ticker filter; |
RichellBooyink | 0:2ded24549b70 | 59 | int main () |
RichellBooyink | 2:e3259334299e | 60 | {filter.attach_us(Filters,1e3);} |
RichellBooyink | 0:2ded24549b70 | 61 | |
RichellBooyink | 0:2ded24549b70 | 62 | |
RichellBooyink | 0:2ded24549b70 | 63 | |
RichellBooyink | 2:e3259334299e | 64 | |
RichellBooyink | 2:e3259334299e | 65 |