Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gr_iir.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio 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  * GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 #ifndef _GR_IIR_H_
00023 #define _GR_IIR_H_
00024 
00025 #include <vector>
00026 using std::vector;
00027 
00031 template<class o_type, class i_type, class tap_type> 
00032 class gr_iir {
00033 public:
00044   gr_iir (const vector<tap_type>& fftaps, const vector<tap_type>& fbtaps)
00045           : fftaps (fftaps),fbtaps(fbtaps),
00046             latest(0),prev_output(fftaps.size()),prev_input(fftaps.size()) {}
00047 
00048   gr_iir () :latest(0) { }
00049 
00050   virtual ~gr_iir () {}
00051 
00056   virtual o_type filter (const i_type input);
00057 
00062   virtual void filterN (o_type output[], const i_type input[],
00063                         unsigned long n); // const;
00064 
00068   unsigned ntaps () const { return fftaps.size (); }
00069 
00073   virtual void set_taps (const vector<tap_type> &newfftaps, 
00074                           const vector<tap_type> &newfbtaps) 
00075   { 
00076     fftaps = newfftaps; 
00077     fbtaps = newfbtaps;
00078     prev_output.resize (fftaps.size ());
00079     prev_input.resize (fftaps.size ());
00080   }
00081 
00082 protected:
00083   vector<tap_type>      fftaps;
00084   vector<tap_type>      fbtaps;
00085   int latest;
00086   vector<o_type>        prev_output;
00087   vector<o_type>        prev_input;
00088 };
00089 
00090 
00091 //
00092 // general case.  We may want to specialize this
00093 //
00094 template<class o_type, class i_type, class tap_type> 
00095 o_type
00096 gr_iir<o_type, i_type, tap_type>::filter (const i_type input)
00097 {
00098   o_type        acc;    // FIXME.  Is this the best acc type?
00099   unsigned      i = 0;
00100   unsigned      n = ntaps ();
00101 
00102   acc = fftaps[0] * input;
00103   for (i = 1; i < n; i ++)
00104     acc += fftaps[i] * prev_input[(latest + i) % n] + fbtaps[i] * prev_output[(latest + i) % n];
00105 
00106   prev_output[latest] = acc;
00107   prev_input[latest] = input;
00108   latest--;
00109   if(latest<0)
00110           latest+=n;
00111   return (o_type) acc;
00112 }
00113 
00114 
00115 template<class o_type, class i_type, class tap_type> 
00116 void 
00117 gr_iir<o_type, i_type, tap_type>::filterN (o_type output[],
00118                                            const i_type input[],
00119                                            unsigned long n)
00120 {
00121   for (unsigned i = 0; i < n; i++)
00122     output[i] = filter (input[i]);
00123 }
00124 
00125 
00126 #endif /* _IIR_H_ */

Generated on Tue Mar 15 23:46:36 2005 for GNU Radio by  doxygen 1.4.0