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

double_lagrange.h

Go to the documentation of this file.
00001 
00002 
00003 
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 //
00022 #ifndef DLAGRANGE
00023 #define DLAGRANGE
00024 #include <complex.h>
00025 namespace SPUC {
00029 class double_lagrange
00030 {
00031       public: 
00032                 long num_taps;
00033         double* coeff;
00034       protected:
00035         double* z; 
00036         double output;
00037       
00038       public: 
00039       // Get current output
00040       double out() { return(output); }
00041       // Clock in new sample & compute current output
00042       //double clock(double in) { return(update(in)); }    
00043       double check(long i) { return(z[i]); }
00044         
00045           double_lagrange(void) { };
00046           double_lagrange(long n) : num_taps(n) {
00047                 int i;
00048                 coeff = new double[n];
00049                 z = new double[n];
00050                 for (i=0;i<n;i++) z[i] = coeff[i] = 0;  
00051         } 
00052           void set_size(long n) {
00053                 int i;
00054                 num_taps = n;
00055                 coeff = new double[n];
00056                 z = new double[n];
00057                 for (i=0;i<n;i++) z[i] = coeff[i] = 0;  
00058         } 
00059         // Update
00060         double update(double in, double offset) {
00061                 int i;                                                       
00062                 // Update history of inputs
00063                 for (i=num_taps;i>0;i--) z[i] = z[i-1];  
00064                 // Add new input
00065                 z[0] = in;   
00066                 // Calculate coefficients
00067                 for (k=0;k<n;k++) {
00068                         coeff[k] = 1;
00069                         for (i=0;i<n;i++) {
00070                                 if (k!=i) coeff[i] *= (offset-i)/(k-i);
00071                         }
00072                 // Perform FIR
00073                 for (output=0,i=0;i<num_taps;i++) output += coeff[i]*z[i];
00074                 return(output);
00075         }
00076 };
00077 } // namespace SPUC 
00078 #endif      

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