Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

iir_1st.h

Go to the documentation of this file.
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_1ST
00022 #define IIR_1ST
00023 #include <iostream>
00024 using namespace std;
00025 namespace SPUC {
00035 template <class Numeric> class iir_1st
00036 {
00037     protected:   
00038         double gain;                    
00039         Numeric out;
00040         Numeric previous_out;
00041                 Numeric previous_in;
00042         
00043     public:
00044         iir_1st(double A=0) : gain(A) {
00045                 previous_in = previous_out = out = 0 ; }
00046                 void set_coeff(double A) { gain=A;}
00048                 iir_1st(const char* file)
00049                   {
00050                         FILE *iirf = fopen(file,"r"); 
00051                         fscanf(iirf,"%lf",&gain);
00052                         fclose(iirf);
00053                         previous_in = previous_out = out = 0;
00054                   }             
00056                 void print() {
00057                         cout << "IIR Coefficient gain = " << gain << "\n";
00058                 }
00060                 Numeric clock(Numeric input) {
00061                   // Shift previous outputs and calculate new output */
00062                   //    out = gain*previous_out + (1-gain)*input;
00063                   out = gain*previous_out + (input+previous_in);
00064                   previous_out = out;
00065                   previous_in = input;
00066                   return(out);
00067                 }
00069                 void reset() {
00070                   previous_in = previous_out = out = 0;
00071                 }
00072 };                                               
00073 } // namespace SPUC 
00074 #endif

Generated on Fri Sep 16 11:02:27 2005 for spuc by  doxygen 1.4.4