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

iir_2nd.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_2ND
00022 #define IIR_2ND
00023 namespace SPUC {
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 template <class Numeric> class iir_2nd
00036 {
00037     protected:   
00038         Numeric b0,b1,b2;                    
00039         Numeric a1,a2;
00040         Numeric in[3];
00041         Numeric out[3]; 
00042         
00043     public:
00044         iir_2nd(Numeric B0, Numeric B1, Numeric B2, Numeric A1, Numeric A2) : b0(B0), b1(B1), b2(B2), a1(A1), a2(A2) {
00045                 in[0] = in[1] = in[2] = out[2] = out[1] = out[0] = 0 ; }
00046         iir_2nd(Numeric A1=0, Numeric A2=0) : b0(1), b1(2), b2(1), a1(A1), a2(A2) {
00047                 in[0] = in[1] = in[2] = out[2] = out[1] = out[0] = 0 ; } 
00048         void reset() {
00049                 in[0] = in[1] = in[2] = out[2] = out[1] = out[0] = 0 ; } 
00050                 void set_a(Numeric A1, Numeric A2) { a1=A1; a2=A2;}
00051                 void set_b(Numeric A1, Numeric A2) { b1=A1; b2=A2;}
00052                 void set_coeff(Numeric A1, Numeric A2) { a1=A1; a2=A2;}
00053 
00055 iir_2nd(const char* file)
00056 {
00057         FILE *iirf = fopen(file,"r"); 
00058         fscanf(iirf,"%lf %lf %lf %lf %lf",&b0,&b1,&b2,&a1,&a2);
00059         fclose(iirf);
00060         in[0] = in[1] = in[2] = out[2] = out[1] = out[0] = 0;
00061 }             
00063 void print() {
00064     printf("IIR Coefficients B0 = %lf, B1 =  %lf, B2 = %lf",b0,b1,b2);
00065     printf(" A0 = 1, A1 = %lf, A2 = %lf\n",a1,a2);
00066 }
00068 Numeric clock(Numeric input) {
00069         // Shift inputs by one time sample and place new sample into array
00070         in[0] = in[1];
00071         in[1] = in[2];
00072         in[2] = input;
00073         // Shift previous outputs and calculate new output */
00074         out[0] = out[1];
00075         out[1] = out[2];
00076         out[2] = b0*in[2] + b1*in[1] + b2*in[0] - a1*out[1] - a2*out[0];
00077         return(out[2]);
00078 }
00079 };                                               
00080 } // namespace SPUC 
00081 #endif

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