test
Dependencies: HIDScope MODSERIAL mbed-dsp mbed
Fork of emg_filter2 by
MAF.h@60:7b5ca1a4d7c3, 2014-10-20 (annotated)
- Committer:
- s1340735
- Date:
- Mon Oct 20 17:59:08 2014 +0000
- Revision:
- 60:7b5ca1a4d7c3
- Parent:
- 28:2d1c7d7635d0
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s1340735 | 28:2d1c7d7635d0 | 1 | /* Copyright (c) <2012> MIT License |
s1340735 | 28:2d1c7d7635d0 | 2 | * |
s1340735 | 28:2d1c7d7635d0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
s1340735 | 28:2d1c7d7635d0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
s1340735 | 28:2d1c7d7635d0 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
s1340735 | 28:2d1c7d7635d0 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
s1340735 | 28:2d1c7d7635d0 | 7 | * furnished to do so, subject to the following conditions: |
s1340735 | 28:2d1c7d7635d0 | 8 | * |
s1340735 | 28:2d1c7d7635d0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
s1340735 | 28:2d1c7d7635d0 | 10 | * substantial portions of the Software. |
s1340735 | 28:2d1c7d7635d0 | 11 | * |
s1340735 | 28:2d1c7d7635d0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
s1340735 | 28:2d1c7d7635d0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
s1340735 | 28:2d1c7d7635d0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
s1340735 | 28:2d1c7d7635d0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
s1340735 | 28:2d1c7d7635d0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
s1340735 | 28:2d1c7d7635d0 | 17 | * |
s1340735 | 28:2d1c7d7635d0 | 18 | * @section DESCRIPTION |
s1340735 | 28:2d1c7d7635d0 | 19 | * |
s1340735 | 28:2d1c7d7635d0 | 20 | * Moving Average Filter |
s1340735 | 28:2d1c7d7635d0 | 21 | * |
s1340735 | 28:2d1c7d7635d0 | 22 | * |
s1340735 | 28:2d1c7d7635d0 | 23 | */ |
s1340735 | 28:2d1c7d7635d0 | 24 | |
s1340735 | 28:2d1c7d7635d0 | 25 | #ifndef MAF_H |
s1340735 | 28:2d1c7d7635d0 | 26 | #define MAF_H |
s1340735 | 28:2d1c7d7635d0 | 27 | |
s1340735 | 28:2d1c7d7635d0 | 28 | #include "mbed.h" |
s1340735 | 28:2d1c7d7635d0 | 29 | |
s1340735 | 28:2d1c7d7635d0 | 30 | /** 10-Point Moving Average filter |
s1340735 | 28:2d1c7d7635d0 | 31 | * |
s1340735 | 28:2d1c7d7635d0 | 32 | * Example: |
s1340735 | 28:2d1c7d7635d0 | 33 | * @code |
s1340735 | 28:2d1c7d7635d0 | 34 | * // Update the filter with gyroscope readings |
s1340735 | 28:2d1c7d7635d0 | 35 | * #include "mbed.h" |
s1340735 | 28:2d1c7d7635d0 | 36 | * #include "ITG3200.h" |
s1340735 | 28:2d1c7d7635d0 | 37 | * #include "MAF.h" |
s1340735 | 28:2d1c7d7635d0 | 38 | * |
s1340735 | 28:2d1c7d7635d0 | 39 | * Serial pc(USBTX, USBRX); |
s1340735 | 28:2d1c7d7635d0 | 40 | * ITG3200 gyro(p9, p10); |
s1340735 | 28:2d1c7d7635d0 | 41 | * MAF Filter(); |
s1340735 | 28:2d1c7d7635d0 | 42 | * int Average; |
s1340735 | 28:2d1c7d7635d0 | 43 | * |
s1340735 | 28:2d1c7d7635d0 | 44 | * int main() { |
s1340735 | 28:2d1c7d7635d0 | 45 | * |
s1340735 | 28:2d1c7d7635d0 | 46 | * gyro.setLpBandwidth(LPFBW_42HZ); |
s1340735 | 28:2d1c7d7635d0 | 47 | * |
s1340735 | 28:2d1c7d7635d0 | 48 | * while(1){ |
s1340735 | 28:2d1c7d7635d0 | 49 | * |
s1340735 | 28:2d1c7d7635d0 | 50 | * Average = Filter.updateInt(gyro.getGyroX()); |
s1340735 | 28:2d1c7d7635d0 | 51 | * pc.printf("%i\n",Average); |
s1340735 | 28:2d1c7d7635d0 | 52 | * wait_ms(50); |
s1340735 | 28:2d1c7d7635d0 | 53 | * } |
s1340735 | 28:2d1c7d7635d0 | 54 | * } |
s1340735 | 28:2d1c7d7635d0 | 55 | * @endcode |
s1340735 | 28:2d1c7d7635d0 | 56 | */ |
s1340735 | 28:2d1c7d7635d0 | 57 | class MAF { |
s1340735 | 28:2d1c7d7635d0 | 58 | |
s1340735 | 28:2d1c7d7635d0 | 59 | public: |
s1340735 | 28:2d1c7d7635d0 | 60 | |
s1340735 | 28:2d1c7d7635d0 | 61 | /* Creates a 10-Point Moving Average Filter object |
s1340735 | 28:2d1c7d7635d0 | 62 | * |
s1340735 | 28:2d1c7d7635d0 | 63 | */ |
s1340735 | 28:2d1c7d7635d0 | 64 | MAF(void); |
s1340735 | 28:2d1c7d7635d0 | 65 | |
s1340735 | 28:2d1c7d7635d0 | 66 | /* Updates the filter |
s1340735 | 28:2d1c7d7635d0 | 67 | * @param data new data input for the filter,returns the float average |
s1340735 | 28:2d1c7d7635d0 | 68 | */ |
s1340735 | 28:2d1c7d7635d0 | 69 | float update(float data); |
s1340735 | 28:2d1c7d7635d0 | 70 | |
s1340735 | 28:2d1c7d7635d0 | 71 | /* Updates the filter |
s1340735 | 28:2d1c7d7635d0 | 72 | * @param data new data input for the filter, returns the integer average |
s1340735 | 28:2d1c7d7635d0 | 73 | */ |
s1340735 | 28:2d1c7d7635d0 | 74 | int updateInt(int data); |
s1340735 | 28:2d1c7d7635d0 | 75 | |
s1340735 | 28:2d1c7d7635d0 | 76 | private : |
s1340735 | 28:2d1c7d7635d0 | 77 | |
s1340735 | 28:2d1c7d7635d0 | 78 | float _k[10]; |
s1340735 | 28:2d1c7d7635d0 | 79 | int _a[10]; |
s1340735 | 28:2d1c7d7635d0 | 80 | |
s1340735 | 28:2d1c7d7635d0 | 81 | float _result; |
s1340735 | 28:2d1c7d7635d0 | 82 | int _resultInt; |
s1340735 | 28:2d1c7d7635d0 | 83 | }; |
s1340735 | 28:2d1c7d7635d0 | 84 | |
s1340735 | 28:2d1c7d7635d0 | 85 | #endif |