Ries Twisk / Mbed 2 deprecated JoyStick

Dependencies:   USBDevice mbed-rtos mbed

Fork of JoyStick by Ries Twisk

LowPassFilter.cpp

Committer:
rvt
Date:
2013-08-28
Revision:
0:33bc88c4ab31
Child:
1:5b2ab44eb31f

File content as of revision 0:33bc88c4ab31:

#include "LowPassFilter.h"

LowPassFilter::LowPassFilter(AnalogFilterInterface *chain,double alpha) :  AnalogFilterInterface(chain) {
        _alpha = alpha;
        _beta = 1.0 - _alpha;
        smoothedValue = 0.0;
}

LowPassFilter::~LowPassFilter() {
}


void LowPassFilter::setData(long dataPoint) {
    getChain()->setData(dataPoint);
    smoothedValue = (getChain()->getData() * _beta) + (smoothedValue * _alpha);
}

long LowPassFilter::getData() {
    return smoothedValue;
}