00001 // 00002 // Copyright(c) 1993-1996 Tony Kirke 00003 // author="Tony Kirke" * 00004 /* Permission to use, copy, modify, distribute and sell this software 00005 * and its documentation for any purpose is hereby granted without fee, 00006 * provided that the above copyright notice appear in all copies and 00007 * that both that copyright notice and this permission notice appear 00008 * in supporting documentation. This software is provided "as is" 00009 * without express or implied warranty. 00010 */ 00011 #ifndef IIR1STHP 00012 #define IIR1STHP 00013 namespace SPUC { 00015 // 00021 template <class Numeric> class iir_hp1 00022 { 00023 protected: 00024 double gain; 00025 double coeff; 00026 Numeric out; 00027 Numeric previous_out; 00028 Numeric previous_in; 00029 00030 public: 00031 iir_hp1(double A=0) { 00032 set_coeff(A); 00033 previous_in = previous_out = out = 0 ; 00034 } 00035 void set_coeff(double A) { 00036 coeff=A; 00037 gain=(1+coeff)/2.0; 00038 } 00040 iir_hp1(const char* file) 00041 { 00042 FILE *iirf = fopen(file,"r"); 00043 fscanf(iirf,"%lf",&coeff); 00044 fclose(iirf); 00045 previous_in = previous_out = out = 0; 00046 set_coeff(coeff); 00047 } 00049 void print() {printf("IIR Coefficient gain = %lf\n",gain);} 00051 Numeric clock(Numeric input) { 00052 // Shift previous outputs and calculate new output */ 00053 out = coeff*previous_out + (input-previous_in); 00054 previous_out = out; 00055 previous_in = input; 00056 return(gain*out); 00057 } 00059 void reset() { 00060 previous_in = previous_out = out = 0; 00061 } 00062 }; 00063 } // namespace SPUC 00064 #endif