![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Filter emg 7-10-15 v1
Dependencies: HIDScope mbed MODSERIAL
Filterdesigns.cpp@24:38cd27737a43, 2016-10-12 (annotated)
- Committer:
- Bartvaart
- Date:
- Wed Oct 12 15:31:14 2016 +0000
- Revision:
- 24:38cd27737a43
- Parent:
- 21:8fe8419de3e9
andries
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 | |
Bartvaart | 7:040591b3f019 | 4 | // Inputwaardes |
Bartvaart | 13:b01231e0b743 | 5 | |
Bartvaart | 13:b01231e0b743 | 6 | |
Bartvaart | 13:b01231e0b743 | 7 | //Notch 50Hz |
Bartvaart | 13:b01231e0b743 | 8 | |
Bartvaart | 7:040591b3f019 | 9 | // Filter1a: 50Hz Notch |
Bartvaart | 6:8197f9446daf | 10 | double v1_50a = 0, v2_50a = 0; |
Bartvaart | 15:c1a8f28d6583 | 11 | const double a1_50a = -1.52337295428, a2_50a = 0.93195385841; |
Bartvaart | 15:c1a8f28d6583 | 12 | const double b0_50a = 1.00000000000, b1_50a = -1.61854514929, b2_50a = 1.0; |
Bartvaart | 6:8197f9446daf | 13 | const double gain_50a = 1.000000; |
Bartvaart | 6:8197f9446daf | 14 | |
Bartvaart | 6:8197f9446daf | 15 | // Filter1b: 50Hz Notch |
Bartvaart | 6:8197f9446daf | 16 | double v1_50b = 0, v2_50b = 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 | |
Bartvaart | 13:b01231e0b743 | 23 | // Filter2a: 20Hz HighPass |
Bartvaart | 15:c1a8f28d6583 | 24 | double v1_HP = 0, v2_HP = 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 | |
Bartvaart | 13:b01231e0b743 | 31 | // Filter3a: 3Hz LowPass |
Bartvaart | 15:c1a8f28d6583 | 32 | double v1_LP = 0, v2_LP = 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 | |
Bartvaart | 6:8197f9446daf | 37 | // constante variabelen: |
Bartvaart | 6:8197f9446daf | 38 | |
Bartvaart | 17:cfe44346645c | 39 | double y=0; |
Bartvaart | 6:8197f9446daf | 40 | |
Bartvaart | 20:11e1244ad2ad | 41 | double Filterdesigns(double u) |
Bartvaart | 5:b400209df739 | 42 | { |
Bartvaart | 5:b400209df739 | 43 | //u = input waarde |
Bartvaart | 5:b400209df739 | 44 | //y = output waarde |
Bartvaart | 16:8f175d2a472f | 45 | |
Bartvaart | 5:b400209df739 | 46 | // Op deze manier worden de waardes ingelezen in Filter. Zorg dus voor dezelfde volgorde, zodat de waardes goed uitgelezen worden!: |
Bartvaart | 5:b400209df739 | 47 | // 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) |
Bartvaart | 6:8197f9446daf | 48 | |
Bartvaart | 5:b400209df739 | 49 | // 50Hz Notch filter |
Bartvaart | 5:b400209df739 | 50 | double y50a = Filter(u, v1_50a, v2_50a, a1_50a, a2_50a, b0_50a, b1_50a, b2_50a, gain_50a); |
Bartvaart | 5:b400209df739 | 51 | double y50b = Filter(y50a, v1_50b, v2_50b, a1_50b, a2_50b, b0_50b, b1_50b, b2_50b, gain_50b); |
Bartvaart | 6:8197f9446daf | 52 | |
Bartvaart | 5:b400209df739 | 53 | // High Pass filter. Tot 20Hz wordt weggefliterd |
Bartvaart | 24:38cd27737a43 | 54 | double yHP = Filter(y50b, v1_HP, v2_HP, a1_HP, a2_HP, b0_HP, b1_HP, b2_HP, gain_HP); |
Bartvaart | 6:8197f9446daf | 55 | |
Bartvaart | 5:b400209df739 | 56 | // Absolute waarde wordt genomen. |
Bartvaart | 15:c1a8f28d6583 | 57 | double y1 = fabs(yHP); |
Bartvaart | 6:8197f9446daf | 58 | |
Bartvaart | 6:8197f9446daf | 59 | // Low Pass filter. Alles vanaf 5Hz wordt weggefilterd |
Bartvaart | 15:c1a8f28d6583 | 60 | double yLP = Filter(y1, v1_LP, v2_LP, a1_LP, a2_LP, b0_LP, b1_LP, b2_LP, gain_LP); |
Bartvaart | 6:8197f9446daf | 61 | |
Bartvaart | 16:8f175d2a472f | 62 | y = 10 * yLP; |
Bartvaart | 17:cfe44346645c | 63 | |
Bartvaart | 17:cfe44346645c | 64 | return y; |
Bartvaart | 5:b400209df739 | 65 | } |