|
00001 /// \file CATFilterEWMA.h 00002 /// \brief Exponentially weighted moving average filter (EWMA / Low pass) 00003 /// \ingroup CAT 00004 /// 00005 /// f(x) = coef * f(x-1) + (1-coef) * x 00006 /// 00007 /// Copyright (c) 2002-2008 by Michael Ellison. 00008 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00009 /// 00010 // $Author: mikeellison $ 00011 // $Date: 2008-01-19 19:19:35 -0600 (Sat, 19 Jan 2008) $ 00012 // $Revision: $ 00013 // $NoKeywords: $ 00014 //--------------------------------------------------------------------------- 00015 #ifndef _CATFilterEWMA_H_ 00016 #define _CATFilterEWMA_H_ 00017 00018 #include "CATFilter.h" 00019 00020 /// \class CATFilterEWMA 00021 /// \brief Exponentially weighted moving average filter (EWMA / Low pass) 00022 /// \ingroup CAT 00023 /// 00024 /// f(x) = coef * f(x-1) + (1-coef) * x 00025 /// 00026 class CATFilterEWMA : public CATFilter 00027 { 00028 public: 00029 /// CATFilterEWMA() - constructor for EWMA filter 00030 /// 00031 /// \param coefficient - filter coefficient. High values = slower movement. 00032 CATFilterEWMA(CATFloat32 coefficient); 00033 00034 virtual ~CATFilterEWMA(); 00035 00036 /// SetCoefficient() sets the filter coefficient. 00037 /// 00038 /// \param coef - filter coefficient 00039 void SetCoefficient( CATFloat32 coef); 00040 00041 CATFloat32 GetCoefficient(); 00042 00043 /// Filter() - add a value and get the next one 00044 inline CATFloat32 Filter( CATFloat32 rawVal ) 00045 { 00046 fLastFiltered = CATTruncDenormals((fCoef * fLastFiltered) + (1.0f - fCoef) * rawVal); 00047 return fLastFiltered; 00048 } 00049 00050 protected: 00051 CATFloat32 fCoef; 00052 }; 00053 00054 00055 #endif //_CATFilterEWMA_H_
1.5.4