00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _GR_SINGLE_ZERO_REC_H_
00023 #define _GR_SINGLE_ZERO_REC_H_
00024
00025 #include <stdexcept>
00026
00030 template<class o_type, class i_type, class tap_type>
00031 class gr_single_zero_rec {
00032 public:
00038 gr_single_zero_rec (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 tap_type prev_output () { return d_prev_output; }
00075
00076 protected:
00077 tap_type d_alpha;
00078 tap_type d_one_minus_alpha;
00079 tap_type d_prev_output;
00080 };
00081
00082
00083
00084
00085
00086 template<class o_type, class i_type, class tap_type>
00087 o_type
00088 gr_single_zero_rec<o_type, i_type, tap_type>::filter (const i_type input)
00089 {
00090 tap_type output;
00091
00092 output = d_alpha * input - d_one_minus_alpha * d_prev_output;
00093 d_prev_output = output;
00094
00095 return (o_type) output;
00096 }
00097
00098
00099 template<class o_type, class i_type, class tap_type>
00100 void
00101 gr_single_zero_rec<o_type, i_type, tap_type>::filterN (o_type output[],
00102 const i_type input[],
00103 unsigned long n)
00104 {
00105 for (unsigned i = 0; i < n; i++)
00106 output[i] = filter (input[i]);
00107 }
00108
00109
00110 #endif