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

fir_interp.h

Go to the documentation of this file.
00001 #ifndef FIRI
00002 #define FIRI
00003 #include <fir.h>
00004 // 
00005 // Copyright(c) 1993-1996 Tony Kirke
00006 // author="Tony Kirke" *
00007 /*
00008  * SPUC - Signal processing using C++ - A DSP library
00009  * 
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014  * 
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023 */
00024 namespace SPUC {
00028 
00029 
00030 template <class Numeric> class fir_interp : public fir<Numeric>
00031 {
00032         public: 
00033         long num_low;
00034     long rate;    
00035     long phase;   
00036         long auto_mode; 
00037     
00038     public: 
00040     void skip() { phase++; phase = phase%rate; }; 
00042         void set_rate(long r) { rate = r; num_low = (fir<Numeric>::num_taps/r - 1);}
00043         void set_automatic(void) { auto_mode = 1;};
00044         void set_manual(int def_phase=0) { auto_mode = 0; phase=def_phase;};
00045 
00046 
00048     fir_interp<Numeric>(const char* i) : phase(0), auto_mode(1), fir<Numeric>(i) {      };
00049     fir_interp<Numeric>(void) : phase(0), auto_mode(1) {        };
00050         fir_interp<Numeric>(long n) : phase(0), auto_mode(1),
00051                 fir<Numeric>(n) {       };
00052         void reset() {
00053                 fir<Numeric>::reset();
00054                 phase = 0;
00055         }
00056         Numeric coeff_sum() { return(fir<Numeric>::coeff_sum()); }
00057     void input(Numeric in) {
00058                 int i;                                           
00059                 // Update history of inputs
00060                 for (i=num_low;i>0;i--) fir<Numeric>::z[i] = fir<Numeric>::z[i-1];  
00061                 // Add new input
00062                 fir<Numeric>::z[0] = in;   
00063         }
00065         Numeric clock(long set_phase) {
00066                 phase = set_phase;
00067                 return(clock());
00068         }
00071         Numeric clock(void) {
00072                 // Perform FIR
00073                 Numeric output;
00074                 int i;
00075                 for (output=0,i=0;i<num_low;i++) {
00076                         output += fir<Numeric>::coeff[(i+1)*rate+phase]*fir<Numeric>::z[i];
00077                 }
00078                 // Increment to next polyphase filter
00079                 if (auto_mode) phase++;                                       
00080                 phase = phase%rate;
00081                 return(output); 
00082         }
00083 
00084 };      
00085 } // namespace SPUC 
00086 #endif

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