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

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

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