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: USBDevice mbed-rtos mbed
Fork of JoyStick by
LowPassFilter.cpp@0:33bc88c4ab31, 2013-08-28 (annotated)
- Committer:
- rvt
- Date:
- Wed Aug 28 02:33:03 2013 +0000
- Revision:
- 0:33bc88c4ab31
- Child:
- 1:5b2ab44eb31f
Initial release with RTOS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rvt | 0:33bc88c4ab31 | 1 | #include "LowPassFilter.h" |
rvt | 0:33bc88c4ab31 | 2 | |
rvt | 0:33bc88c4ab31 | 3 | LowPassFilter::LowPassFilter(AnalogFilterInterface *chain,double alpha) : AnalogFilterInterface(chain) { |
rvt | 0:33bc88c4ab31 | 4 | _alpha = alpha; |
rvt | 0:33bc88c4ab31 | 5 | _beta = 1.0 - _alpha; |
rvt | 0:33bc88c4ab31 | 6 | smoothedValue = 0.0; |
rvt | 0:33bc88c4ab31 | 7 | } |
rvt | 0:33bc88c4ab31 | 8 | |
rvt | 0:33bc88c4ab31 | 9 | LowPassFilter::~LowPassFilter() { |
rvt | 0:33bc88c4ab31 | 10 | } |
rvt | 0:33bc88c4ab31 | 11 | |
rvt | 0:33bc88c4ab31 | 12 | |
rvt | 0:33bc88c4ab31 | 13 | void LowPassFilter::setData(long dataPoint) { |
rvt | 0:33bc88c4ab31 | 14 | getChain()->setData(dataPoint); |
rvt | 0:33bc88c4ab31 | 15 | smoothedValue = (getChain()->getData() * _beta) + (smoothedValue * _alpha); |
rvt | 0:33bc88c4ab31 | 16 | } |
rvt | 0:33bc88c4ab31 | 17 | |
rvt | 0:33bc88c4ab31 | 18 | long LowPassFilter::getData() { |
rvt | 0:33bc88c4ab31 | 19 | return smoothedValue; |
rvt | 0:33bc88c4ab31 | 20 | } |
rvt | 0:33bc88c4ab31 | 21 |