00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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;
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