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

cfir.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 RFIR
00022 #define RFIR
00023 #include <iostream.h>
00024 #include <fstream.h>
00025 #include <complex.h>
00026 namespace SPUC {
00030 
00031 
00032 
00033 
00034 template <class Numeric> class rfir
00035 {
00036  public: 
00037   long num_taps;
00038   Numeric* coeff;
00039 //      protected:
00040   complex<Numeric>* z; 
00041   complex<Numeric> output;
00042       
00043  public: 
00044   // Set tap weights
00045   void settap(long i, Numeric tap) { coeff[i] = tap; }  
00046   // Get current output
00047   complex<Numeric> out() { return(output); }
00048   // Clock in new sample & compute current output
00049   complex<Numeric> check(long i) { return(z[i]); }
00050   rfir(void) { ;};
00051 rfir(long n) : num_taps(n)
00052 {
00053         int i;
00054         coeff = new Numeric[n];
00055         z = new complex<Numeric>[n];
00056         for (i=0;i<n;i++) z[i] = 0;
00057         for (i=0;i<n;i++) coeff[i] = 0;  
00058 } 
00059 void set_size(long n) 
00060 {
00061         int i;
00062         num_taps = n;
00063         coeff = new Numeric[n];
00064         z = new cmlx<Numeric>[n];
00065         for (i=0;i<n;i++) z[i] = 0;
00066         for (i=0;i<n;i++) coeff[i] = 0;  
00067 } 
00068 rfir(const char* file) { read_taps(file); };               
00069 // Update
00070 complex<Numeric> update(complex<Numeric> in)
00071 {
00072         int i;                                                       
00073         // Update history of inputs
00074         for (i=num_taps;i>0;i--) z[i] = z[i-1];  
00075         // Add new input
00076         z[0] = in;   
00077         // Perform FIR
00078         for (output=0,i=0;i<num_taps;i++) output += coeff[i]*z[i];
00079         return(output);
00080 }
00081 void read_taps(const char* file);
00082 void print(void);
00083 
00084 };
00085 } // namespace SPUC 
00086 #endif

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