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
Filterdesigns.cpp@50:16314b798754, 2015-10-28 (annotated)
- Committer:
- RemcoDas
- Date:
- Wed Oct 28 09:28:48 2015 +0000
- Revision:
- 50:16314b798754
- Parent:
- 41:91c8c39d7a33
- Child:
- 56:1ac2487a9610
Final, schoongeveegd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bartvaart | 5:b400209df739 | 1 | #include "Filterdesigns.h" |
Bartvaart | 6:8197f9446daf | 2 | #include "Filter.h" |
Bartvaart | 6:8197f9446daf | 3 | |
RemcoDas | 50:16314b798754 | 4 | // Inputvalues |
Bartvaart | 13:b01231e0b743 | 5 | //Notch 50Hz |
Bartvaart | 13:b01231e0b743 | 6 | |
Bartvaart | 7:040591b3f019 | 7 | // Filter1a: 50Hz Notch |
RemcoDas | 41:91c8c39d7a33 | 8 | double v1_50a_L = 0, v2_50a_L = 0; // Left EMG memory |
RemcoDas | 41:91c8c39d7a33 | 9 | double v1_50a_R = 0, v2_50a_R = 0; // Right EMG memory |
Bartvaart | 15:c1a8f28d6583 | 10 | const double a1_50a = -1.52337295428, a2_50a = 0.93195385841; |
Bartvaart | 15:c1a8f28d6583 | 11 | const double b0_50a = 1.00000000000, b1_50a = -1.61854514929, b2_50a = 1.0; |
Bartvaart | 6:8197f9446daf | 12 | const double gain_50a = 1.000000; |
Bartvaart | 6:8197f9446daf | 13 | |
Bartvaart | 6:8197f9446daf | 14 | // Filter1b: 50Hz Notch |
RemcoDas | 30:8ae855348d22 | 15 | double v1_50b_L = 0, v2_50b_L = 0; |
RemcoDas | 30:8ae855348d22 | 16 | double v1_50b_R = 0, v2_50b_R = 0; |
Bartvaart | 15:c1a8f28d6583 | 17 | const double a1_50b = -1.60486796113, a2_50b = 0.93780356783; |
Bartvaart | 15:c1a8f28d6583 | 18 | const double b0_50b = 1.00000000000, b1_50b = -1.61854514929, b2_50b = 1.0; |
Bartvaart | 15:c1a8f28d6583 | 19 | const double gain_50b = 0.934872; |
Bartvaart | 6:8197f9446daf | 20 | |
Bartvaart | 13:b01231e0b743 | 21 | //HighPass 20Hz |
Bartvaart | 13:b01231e0b743 | 22 | // Filter2a: 20Hz HighPass |
RemcoDas | 30:8ae855348d22 | 23 | double v1_HP_L = 0, v2_HP_L = 0; |
RemcoDas | 30:8ae855348d22 | 24 | double v1_HP_R = 0, v2_HP_R = 0; |
Bartvaart | 21:8fe8419de3e9 | 25 | const double a1_HP = -0.76475499450, a2_HP = 0.27692273367; |
Bartvaart | 21:8fe8419de3e9 | 26 | const double b0_HP = 1.00000000000, b1_HP = -2.0, b2_HP = 1.00000000000; |
Bartvaart | 21:8fe8419de3e9 | 27 | const double gain_HP = 0.510419; |
Bartvaart | 6:8197f9446daf | 28 | |
Bartvaart | 13:b01231e0b743 | 29 | //LowPass 3Hz |
Bartvaart | 13:b01231e0b743 | 30 | // Filter3a: 3Hz LowPass |
RemcoDas | 30:8ae855348d22 | 31 | double v1_LP_L = 0, v2_LP_L = 0; |
RemcoDas | 30:8ae855348d22 | 32 | double v1_LP_R = 0, v2_LP_R = 0; |
Bartvaart | 15:c1a8f28d6583 | 33 | const double a1_LP = -1.93503824887, a2_LP = 0.93708289663; |
Bartvaart | 15:c1a8f28d6583 | 34 | const double b0_LP = 1.00000000000, b1_LP = 2.0, b2_LP = 1.00000000000; |
Bartvaart | 15:c1a8f28d6583 | 35 | const double gain_LP = 0.000511; |
Bartvaart | 6:8197f9446daf | 36 | |
RemcoDas | 41:91c8c39d7a33 | 37 | // Filter with memory values left EMG |
RemcoDas | 50:16314b798754 | 38 | double FilterdesignsLeft(double u){ // input u |
RemcoDas | 50:16314b798754 | 39 | double y = 0; // output |
Bartvaart | 5:b400209df739 | 40 | // 50Hz Notch filter |
RemcoDas | 30:8ae855348d22 | 41 | double y50a = Filter(u, v1_50a_L, v2_50a_L, a1_50a, a2_50a, b0_50a, b1_50a, b2_50a, gain_50a); |
RemcoDas | 30:8ae855348d22 | 42 | double y50b = Filter(y50a, v1_50b_L, v2_50b_L, a1_50b, a2_50b, b0_50b, b1_50b, b2_50b, gain_50b); |
RemcoDas | 30:8ae855348d22 | 43 | |
RemcoDas | 50:16314b798754 | 44 | // High Pass filter. To 20Hz is filtered |
RemcoDas | 30:8ae855348d22 | 45 | double yHP = Filter(y50b, v1_HP_L, v2_HP_L, a1_HP, a2_HP, b0_HP, b1_HP, b2_HP, gain_HP); |
RemcoDas | 30:8ae855348d22 | 46 | |
RemcoDas | 50:16314b798754 | 47 | // Absolute value |
RemcoDas | 30:8ae855348d22 | 48 | double y1 = fabs(yHP); |
RemcoDas | 30:8ae855348d22 | 49 | |
RemcoDas | 50:16314b798754 | 50 | // Low Pass filter 5Hz |
RemcoDas | 30:8ae855348d22 | 51 | double yLP = Filter(y1, v1_LP_L, v2_LP_L, a1_LP, a2_LP, b0_LP, b1_LP, b2_LP, gain_LP); |
Bartvaart | 6:8197f9446daf | 52 | |
RemcoDas | 50:16314b798754 | 53 | y = 10 * yLP; // scaling |
RemcoDas | 30:8ae855348d22 | 54 | return y; |
RemcoDas | 30:8ae855348d22 | 55 | } |
RemcoDas | 41:91c8c39d7a33 | 56 | |
RemcoDas | 41:91c8c39d7a33 | 57 | // Filter with memory values left EMG |
RemcoDas | 50:16314b798754 | 58 | double FilterdesignsRight(double u){ // input u |
RemcoDas | 50:16314b798754 | 59 | double y = 0; // output |
RemcoDas | 30:8ae855348d22 | 60 | |
RemcoDas | 30:8ae855348d22 | 61 | // 50Hz Notch filter |
RemcoDas | 30:8ae855348d22 | 62 | double y50a = Filter(u, v1_50a_R, v2_50a_R, a1_50a, a2_50a, b0_50a, b1_50a, b2_50a, gain_50a); |
RemcoDas | 30:8ae855348d22 | 63 | double y50b = Filter(y50a, v1_50b_R, v2_50b_R, a1_50b, a2_50b, b0_50b, b1_50b, b2_50b, gain_50b); |
RemcoDas | 30:8ae855348d22 | 64 | |
RemcoDas | 50:16314b798754 | 65 | // High Pass filter. Tot 20Hz is filtered |
RemcoDas | 41:91c8c39d7a33 | 66 | double yHP = Filter(y50b, v1_HP_R, v2_HP_R, a1_HP, a2_HP, b0_HP, b1_HP, b2_HP, gain_HP); |
Bartvaart | 6:8197f9446daf | 67 | |
RemcoDas | 50:16314b798754 | 68 | // Absolute value |
Bartvaart | 15:c1a8f28d6583 | 69 | double y1 = fabs(yHP); |
Bartvaart | 6:8197f9446daf | 70 | |
RemcoDas | 50:16314b798754 | 71 | // Low Pass filter, 50Hz |
RemcoDas | 30:8ae855348d22 | 72 | double yLP = Filter(y1, v1_LP_R, v2_LP_R, a1_LP, a2_LP, b0_LP, b1_LP, b2_LP, gain_LP); |
Bartvaart | 6:8197f9446daf | 73 | |
RemcoDas | 50:16314b798754 | 74 | y = 10 * yLP; // scaling |
Bartvaart | 17:cfe44346645c | 75 | return y; |
RemcoDas | 41:91c8c39d7a33 | 76 | } |