a 10-Point moving average filter that can return an int or a float depending on the function used
MAF.cpp@1:fbc57eb4e61d, 2013-05-05 (annotated)
- Committer:
- KarimAzzouz
- Date:
- Sun May 05 13:31:02 2013 +0000
- Revision:
- 1:fbc57eb4e61d
- Parent:
- 0:c1b48befe066
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KarimAzzouz | 1:fbc57eb4e61d | 1 | /* Copyright (c) <2012> MIT License |
KarimAzzouz | 1:fbc57eb4e61d | 2 | * |
KarimAzzouz | 1:fbc57eb4e61d | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
KarimAzzouz | 1:fbc57eb4e61d | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
KarimAzzouz | 1:fbc57eb4e61d | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
KarimAzzouz | 1:fbc57eb4e61d | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
KarimAzzouz | 1:fbc57eb4e61d | 7 | * furnished to do so, subject to the following conditions: |
KarimAzzouz | 1:fbc57eb4e61d | 8 | * |
KarimAzzouz | 1:fbc57eb4e61d | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
KarimAzzouz | 1:fbc57eb4e61d | 10 | * substantial portions of the Software. |
KarimAzzouz | 1:fbc57eb4e61d | 11 | * |
KarimAzzouz | 1:fbc57eb4e61d | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
KarimAzzouz | 1:fbc57eb4e61d | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
KarimAzzouz | 1:fbc57eb4e61d | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
KarimAzzouz | 1:fbc57eb4e61d | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
KarimAzzouz | 1:fbc57eb4e61d | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
KarimAzzouz | 1:fbc57eb4e61d | 17 | * |
KarimAzzouz | 1:fbc57eb4e61d | 18 | * @section DESCRIPTION |
KarimAzzouz | 1:fbc57eb4e61d | 19 | * |
KarimAzzouz | 1:fbc57eb4e61d | 20 | * 10-Point Moving Average Filter |
KarimAzzouz | 1:fbc57eb4e61d | 21 | */ |
KarimAzzouz | 1:fbc57eb4e61d | 22 | |
KarimAzzouz | 1:fbc57eb4e61d | 23 | #include "MAF.h" |
KarimAzzouz | 1:fbc57eb4e61d | 24 | |
KarimAzzouz | 1:fbc57eb4e61d | 25 | MAF::MAF(){} |
KarimAzzouz | 1:fbc57eb4e61d | 26 | |
KarimAzzouz | 1:fbc57eb4e61d | 27 | float MAF::update(float data){ |
KarimAzzouz | 1:fbc57eb4e61d | 28 | |
KarimAzzouz | 1:fbc57eb4e61d | 29 | _k[0] = data; |
KarimAzzouz | 1:fbc57eb4e61d | 30 | _result = _k[0]*0.1 + _k[1]*0.1 + _k[2]*0.1 + _k[3]*0.1 + _k[4]*0.1 + _k[5]*0.1 + _k[6]*0.1 + _k[7]*0.1 + _k[8]*0.1 + _k[9]*0.1 ; |
KarimAzzouz | 1:fbc57eb4e61d | 31 | _k[9] = _k[8]; |
KarimAzzouz | 1:fbc57eb4e61d | 32 | _k[8] = _k[7]; |
KarimAzzouz | 1:fbc57eb4e61d | 33 | _k[7] = _k[6]; |
KarimAzzouz | 1:fbc57eb4e61d | 34 | _k[6] = _k[5]; |
KarimAzzouz | 1:fbc57eb4e61d | 35 | _k[5] = _k[4]; |
KarimAzzouz | 1:fbc57eb4e61d | 36 | _k[4] = _k[3]; |
KarimAzzouz | 1:fbc57eb4e61d | 37 | _k[3] = _k[2]; |
KarimAzzouz | 1:fbc57eb4e61d | 38 | _k[2] = _k[1]; |
KarimAzzouz | 1:fbc57eb4e61d | 39 | _k[1] = _k[0]; |
KarimAzzouz | 1:fbc57eb4e61d | 40 | |
KarimAzzouz | 1:fbc57eb4e61d | 41 | return _result; |
KarimAzzouz | 1:fbc57eb4e61d | 42 | } |
KarimAzzouz | 1:fbc57eb4e61d | 43 | |
KarimAzzouz | 1:fbc57eb4e61d | 44 | int MAF::updateInt(int data){ |
KarimAzzouz | 1:fbc57eb4e61d | 45 | |
KarimAzzouz | 1:fbc57eb4e61d | 46 | _a[0] = data; |
KarimAzzouz | 1:fbc57eb4e61d | 47 | _result = _a[0]*0.1 + _a[1]*0.1 + _a[2]*0.1 + _a[3]*0.1 + _a[4]*0.1 + _a[5]*0.1 + _a[6]*0.1 + _a[7]*0.1 + _a[8]*0.1 + _a[9]*0.1 ; |
KarimAzzouz | 1:fbc57eb4e61d | 48 | _a[9] = _a[8]; |
KarimAzzouz | 1:fbc57eb4e61d | 49 | _a[8] = _a[7]; |
KarimAzzouz | 1:fbc57eb4e61d | 50 | _a[7] = _a[6]; |
KarimAzzouz | 1:fbc57eb4e61d | 51 | _a[6] = _a[5]; |
KarimAzzouz | 1:fbc57eb4e61d | 52 | _a[5] = _a[4]; |
KarimAzzouz | 1:fbc57eb4e61d | 53 | _a[4] = _a[3]; |
KarimAzzouz | 1:fbc57eb4e61d | 54 | _a[3] = _a[2]; |
KarimAzzouz | 1:fbc57eb4e61d | 55 | _a[2] = _a[1]; |
KarimAzzouz | 1:fbc57eb4e61d | 56 | _a[1] = _a[0]; |
KarimAzzouz | 1:fbc57eb4e61d | 57 | |
KarimAzzouz | 1:fbc57eb4e61d | 58 | return _resultInt; |
KarimAzzouz | 0:c1b48befe066 | 59 | } |