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

gr_single_pole_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_SINGLE_POLE_IIR_H_
00023 #define _GR_SINGLE_POLE_IIR_H_
00024 
00025 #include <stdexcept>
00026 
00030 template<class o_type, class i_type, class tap_type> 
00031 class gr_single_pole_iir {
00032 public:
00038   gr_single_pole_iir (tap_type alpha = 1.0)
00039   {
00040     d_prev_output = 0;
00041     set_taps (alpha);
00042   }
00043 
00048   o_type filter (const i_type input);
00049 
00054   void filterN (o_type output[], const i_type input[], unsigned long n);
00055 
00059   void set_taps (tap_type alpha)
00060   { 
00061     if (alpha < 0 || alpha > 1)
00062       throw std::out_of_range ("Alpha must be in [0, 1]\n");
00063 
00064     d_alpha = alpha;
00065     d_one_minus_alpha = 1.0 - alpha;
00066   }
00067 
00069   void reset ()
00070   {
00071     d_prev_output = 0;
00072   }
00073     
00074 protected:
00075   tap_type      d_alpha;
00076   tap_type      d_one_minus_alpha;
00077   tap_type      d_prev_output;
00078 };
00079 
00080 
00081 //
00082 // general case.  We may want to specialize this
00083 //
00084 template<class o_type, class i_type, class tap_type> 
00085 o_type
00086 gr_single_pole_iir<o_type, i_type, tap_type>::filter (const i_type input)
00087 {
00088   tap_type      output;
00089 
00090   output = d_alpha * input + d_one_minus_alpha * d_prev_output;
00091   d_prev_output = output;
00092 
00093   return (o_type) output;
00094 }
00095 
00096 
00097 template<class o_type, class i_type, class tap_type> 
00098 void 
00099 gr_single_pole_iir<o_type, i_type, tap_type>::filterN (o_type output[],
00100                                                        const i_type input[],
00101                                                        unsigned long n)
00102 {
00103   for (unsigned i = 0; i < n; i++)
00104     output[i] = filter (input[i]);
00105 }
00106 
00107 
00108 #endif /* _GR_SINGLE_POLE_IIR_H_ */

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