00001 // ---------------------------------------------------------------------------- 00002 // 00003 // $Id$ 00004 // 00005 // Copyright 2008, 2009, 2010, 2011, 2012 Antonio Franchi and Paolo Stegagno 00006 // 00007 // This file is part of MIP. 00008 // 00009 // MIP is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // MIP is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it 00023 // 00024 // ---------------------------------------------------------------------------- 00025 00026 00030 00034 00035 #ifndef __FIR_FILTER_H_ 00036 #define __FIR_FILTER_H_ 00037 00038 #ifdef MIP_HOST_APPLE 00039 #include <applePatch.h> 00040 #endif 00041 00042 #include <list> 00043 00044 #include<baselib.h> 00045 00046 00047 #define FIR_TIME_DEBUG 0 00048 00049 using namespace MipBaselib; 00050 00052 /* @{ */ 00053 00054 enum FirFilterShapes{ 00055 FIR_SHAPES_CONSTANT, 00056 FIR_SHAPES_NUM 00057 }; 00058 00059 struct FirFilterPar{ 00060 FirFilterShapes shape; 00061 Time lag; 00062 00063 FirFilterPar(FirFilterShapes s=FIR_SHAPES_CONSTANT, Time l=Time(1,0)){ 00064 shape = s; 00065 lag = l; 00066 } 00067 }; 00068 00069 struct FirFilterVar{ 00070 list<Decimal> samples; 00071 list<Time> timeStamps; 00072 Time lastTimeStamp; 00073 }; 00074 00075 struct FirFilterIn{ 00076 Decimal sample; 00077 00078 FirFilterIn(Decimal s=0.0){ 00079 sample = s; 00080 } 00081 }; 00082 00083 struct FirFilterOut{ 00084 Decimal sample; 00085 int size; 00086 }; 00087 00088 class FirFilter{ 00089 private: 00090 FirFilterPar _par; 00091 FirFilterVar _var; 00092 00093 void _eraseOldSamples(); 00094 Decimal _average(FirFilterOut& out); 00095 00096 public: 00097 FirFilter(FirFilterPar par){ 00098 _par = par; 00099 } 00100 00101 void step(FirFilterIn& in,FirFilterOut& out); 00102 }; 00103 00104 #endif 00105 00106 00107 /* @} */ 00108 00109