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

gr_fir.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_FIR_H_
00023 #define _GR_FIR_H_
00024 
00025 #warning "gr_fir.h is deprecated.  Please transition to gr_fir_???.h"
00026 
00027 #include <vector>
00028 using std::vector;
00029 
00033 template<class o_type, class i_type, class tap_type> 
00034 class gr_fir {
00035 public:
00043   gr_fir (const vector<tap_type> &new_taps) : taps (new_taps) {}
00044   gr_fir () {}
00045 
00046   virtual ~gr_fir () {}
00047 
00056   virtual o_type filter (const i_type input[]);
00057 
00064   virtual void filterN (o_type output[], const i_type input[],
00065                         unsigned long n);
00066 
00073   virtual void filterNdec (o_type output[], const i_type input[],
00074                            unsigned long n, unsigned decimate);
00075 
00079   unsigned ntaps () const { return taps.size (); }
00080 
00084   virtual void set_taps (const vector<tap_type> &new_taps)
00085   {
00086     taps = new_taps;
00087   }
00088 
00089 protected:
00090   vector<tap_type>      taps;
00091 };
00092 
00093 
00094 //
00095 // general case.  We may want to specialize this
00096 //
00097 template<class o_type, class i_type, class tap_type> 
00098 o_type
00099 gr_fir<o_type, i_type, tap_type>::filter (const i_type input[])
00100 {
00101   tap_type      acc = 0;        // FIXME.  Is this the best acc type?
00102   unsigned      i = 0;
00103   unsigned      n = (ntaps () / 4) * 4;
00104 
00105   for (i = 0; i < n; i += 4){
00106     acc += taps[i + 0] * input[i + 0];
00107     acc += taps[i + 1] * input[i + 1];
00108     acc += taps[i + 2] * input[i + 2];
00109     acc += taps[i + 3] * input[i + 3];
00110   }
00111 
00112   for (; i < ntaps (); i++)
00113     acc += taps[i] * input[i];
00114 
00115   return (o_type) acc;
00116 }
00117 
00118 
00119 template<class o_type, class i_type, class tap_type> 
00120 void 
00121 gr_fir<o_type, i_type, tap_type>::filterN (o_type output[],
00122                                            const i_type input[],
00123                                            unsigned long n)
00124 {
00125   for (unsigned i = 0; i < n; i++)
00126     output[i] = filter (&input[i]);
00127 }
00128 
00129 template<class o_type, class i_type, class tap_type> 
00130 void 
00131 gr_fir<o_type, i_type, tap_type>::filterNdec (o_type output[],
00132                                               const i_type input[],
00133                                               unsigned long n,
00134                                               unsigned decimate)
00135 {
00136   unsigned j = 0;
00137   for (unsigned i = 0; i < n; i++){
00138     output[i] = filter (&input[j]);
00139     j += decimate;
00140   }
00141 }
00142 
00143 
00144 #endif /* _FIR_H_ */

Generated on Wed Mar 23 12:30:22 2005 for GNU Radio by  doxygen 1.4.0