00001 // 00002 // Copyright(c) 1993-1996 Tony Kirke 00003 // author="Tony Kirke" * 00004 /* 00005 * SPUC - Signal processing using C++ - A DSP library 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2, or (at your option) 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 #ifndef LOOPFILTER 00022 #define LOOPFILTER 00023 #include <spuc.h> 00024 namespace SPUC { 00031 00032 00033 00034 00035 00036 00037 00038 template <class Numeric> class loop_filter 00039 { 00040 public: 00042 long k0_en; 00044 long k1_en; 00046 Numeric k0; 00048 Numeric k1; 00050 Numeric k1_acc; 00051 00052 protected: 00053 Numeric loop_out; 00054 Numeric k1_prod, k0_prod; 00055 00056 public: 00058 loop_filter(void) { k0 = k1 = k1_acc = 0; k0_en = k1_en = 0;} 00060 void reset(void) { k1_acc = k1_prod = k0_prod = loop_out = 0; } 00062 Numeric update(Numeric error) { 00063 k0_prod = (k0_en) ? error*k0 : 0; 00064 k1_prod = (k1_en) ? error*k1 : 0; 00065 loop_out = k1_acc + k0_prod; // Use last k1_acc! 00066 k1_acc += k1_prod; 00067 return(loop_out); 00068 } 00069 }; 00070 } // namespace SPUC 00071 #endif