Simple moving average filter.
MAF.cpp@4:9002522153d7, 2019-03-01 (annotated)
- Committer:
- jonebuckman
- Date:
- Fri Mar 01 12:26:19 2019 +0000
- Revision:
- 4:9002522153d7
- Parent:
- 3:63b077baff96
Added documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jonebuckman | 4:9002522153d7 | 1 | /* Simple moving average filter |
jonebuckman | 4:9002522153d7 | 2 | * Copyright (c) 2019 Jon Buckman |
jonebuckman | 4:9002522153d7 | 3 | * |
jonebuckman | 4:9002522153d7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jonebuckman | 4:9002522153d7 | 5 | * you may not use this file except in compliance with the License. |
jonebuckman | 4:9002522153d7 | 6 | * You may obtain a copy of the License at |
jonebuckman | 4:9002522153d7 | 7 | * |
jonebuckman | 4:9002522153d7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jonebuckman | 4:9002522153d7 | 9 | * |
jonebuckman | 4:9002522153d7 | 10 | * Unless required by applicable law or agreed to in writing, software |
jonebuckman | 4:9002522153d7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jonebuckman | 4:9002522153d7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jonebuckman | 4:9002522153d7 | 13 | * See the License for the specific language governing permissions and |
jonebuckman | 4:9002522153d7 | 14 | * limitations under the License. |
jonebuckman | 4:9002522153d7 | 15 | */ |
KarimAzzouz | 1:fbc57eb4e61d | 16 | #include "MAF.h" |
KarimAzzouz | 1:fbc57eb4e61d | 17 | |
joe4465 | 2:21b70641f866 | 18 | MAF::MAF() |
joe4465 | 2:21b70641f866 | 19 | {} |
jonebuckman | 3:63b077baff96 | 20 | /* |
joe4465 | 2:21b70641f866 | 21 | float MAF::update(float data) |
joe4465 | 2:21b70641f866 | 22 | { |
KarimAzzouz | 1:fbc57eb4e61d | 23 | _k[0] = data; |
jonebuckman | 3:63b077baff96 | 24 | _result = _k[0]*0.1f + _k[1]*0.1f + _k[2]*0.1f + _k[3]*0.1f + _k[4]*0.1f + _k[5]*0.1f + _k[6]*0.1f + _k[7]*0.1f + _k[8]*0.1f + _k[9]*0.1f ; |
KarimAzzouz | 1:fbc57eb4e61d | 25 | _k[9] = _k[8]; |
KarimAzzouz | 1:fbc57eb4e61d | 26 | _k[8] = _k[7]; |
KarimAzzouz | 1:fbc57eb4e61d | 27 | _k[7] = _k[6]; |
KarimAzzouz | 1:fbc57eb4e61d | 28 | _k[6] = _k[5]; |
KarimAzzouz | 1:fbc57eb4e61d | 29 | _k[5] = _k[4]; |
KarimAzzouz | 1:fbc57eb4e61d | 30 | _k[4] = _k[3]; |
KarimAzzouz | 1:fbc57eb4e61d | 31 | _k[3] = _k[2]; |
KarimAzzouz | 1:fbc57eb4e61d | 32 | _k[2] = _k[1]; |
KarimAzzouz | 1:fbc57eb4e61d | 33 | _k[1] = _k[0]; |
KarimAzzouz | 1:fbc57eb4e61d | 34 | |
KarimAzzouz | 1:fbc57eb4e61d | 35 | return _result; |
jonebuckman | 3:63b077baff96 | 36 | } |
jonebuckman | 3:63b077baff96 | 37 | */ |
jonebuckman | 3:63b077baff96 | 38 | float MAF::update(float data) |
jonebuckman | 3:63b077baff96 | 39 | { |
jonebuckman | 3:63b077baff96 | 40 | _k[0] = data; |
jonebuckman | 3:63b077baff96 | 41 | _result = _k[0]*0.25f + _k[1]*0.25f + _k[2]*0.25f + _k[3]*0.25f ; |
jonebuckman | 3:63b077baff96 | 42 | _k[3] = _k[2]; |
jonebuckman | 3:63b077baff96 | 43 | _k[2] = _k[1]; |
jonebuckman | 3:63b077baff96 | 44 | _k[1] = _k[0]; |
jonebuckman | 3:63b077baff96 | 45 | |
jonebuckman | 3:63b077baff96 | 46 | return _result; |
jonebuckman | 3:63b077baff96 | 47 | } |