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 IIR_HPF 00022 #define IIR_HPF 00023 namespace SPUC { 00026 // 00032 template <class Numeric> class iir_hpf 00033 { 00034 protected: 00035 double gain; 00036 double a; 00037 Numeric out; 00038 Numeric previous_out; 00039 Numeric previous_in; 00040 00041 public: 00042 iir_hpf(double A=0) { 00043 gain = (1-A)/(A+1); 00044 a = 1.0/(A+1); 00045 previous_in = previous_out = out = 0 ; } 00047 iir_hpf(const char* file) 00048 { 00049 FILE *iirf = fopen(file,"r"); 00050 fscanf(iirf,"%lf",&gain); 00051 fclose(iirf); 00052 previous_in = previous_out = out = 0; 00053 } 00055 void print() { 00056 cout << "IIR B0 = " << a << ", "; 00057 cout << "A0 = " << gain << "\n"; 00058 } 00060 Numeric clock(Numeric input) { 00061 // Shift previous outputs and calculate new output */ 00062 out = gain*previous_out + a*(input-previous_in); 00063 previous_out = out; 00064 previous_in = input; 00065 return(out); 00066 } 00068 void reset() { 00069 previous_in = previous_out = out = 0; 00070 } 00071 }; 00072 } // namespace SPUC 00073 #endif