GNU Radio 3.7.0 C++ API
fir_filter_with_buffer.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2010,2012 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 3, 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., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H
00024 #define INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H
00025 
00026 #include <gnuradio/filter/api.h>
00027 #include <vector>
00028 #include <gnuradio/gr_complex.h>
00029 
00030 namespace gr {
00031   namespace filter {
00032     namespace kernel {
00033 
00034       /*!
00035        * \brief FIR with internal buffer for float input, float output and float taps.
00036        * \ingroup filter
00037        */
00038       class FILTER_API fir_filter_with_buffer_fff
00039       {
00040       private:
00041         std::vector<float> d_taps;
00042         unsigned int  d_ntaps;
00043         float        *d_buffer_ptr;
00044         float        *d_buffer;
00045         unsigned int  d_idx;
00046         float       **d_aligned_taps;
00047         float        *d_output;
00048         int           d_align;
00049         int           d_naligned;
00050 
00051       public:
00052       
00053         // CONSTRUCTORS
00054 
00055         /*!
00056          * \brief construct new FIR with given taps.
00057          *
00058          * Note that taps must be in forward order, e.g., coefficient 0 is
00059          * stored in new_taps[0], coefficient 1 is stored in
00060          * new_taps[1], etc.
00061          */
00062         fir_filter_with_buffer_fff(const std::vector<float> &taps);
00063 
00064         ~fir_filter_with_buffer_fff();
00065 
00066         // MANIPULATORS
00067 
00068         /*!
00069          * \brief compute a single output value.
00070          *
00071          * \p input is a single input value of the filter type
00072          *
00073          * \returns the filtered input value.
00074          */
00075         float filter(float input);
00076 
00077         /*!
00078          * \brief compute a single output value; designed for decimating filters.
00079          *
00080          * \p input is a single input value of the filter type. The value of dec is the
00081          *    decimating value of the filter, so input[] must have dec valid values.
00082          *    The filter pushes dec number of items onto the circ. buffer before computing
00083          *    a single output.
00084          *
00085          * \returns the filtered input value.
00086          */
00087         float filter(const float input[], unsigned long dec);
00088 
00089         /*!
00090          * \brief compute an array of N output values.
00091          *
00092          * \p input must have (n - 1 + ntaps()) valid entries.
00093          * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
00094          */
00095         void filterN(float output[],
00096                      const float input[],
00097                      unsigned long n);
00098 
00099         /*!
00100          * \brief compute an array of N output values, decimating the input
00101          *
00102          * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
00103          * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
00104          * compute the output values.
00105          */
00106         void filterNdec(float output[], const float input[],
00107                         unsigned long n, unsigned long decimate);
00108 
00109         // ACCESSORS
00110 
00111         /*!
00112          * \return number of taps in filter.
00113          */
00114         unsigned int ntaps() const { return d_ntaps; }
00115 
00116         /*!
00117          * \brief install \p new_taps as the current taps.
00118          */
00119         void set_taps(const std::vector<float> &taps);
00120 
00121         /*!
00122          * \return current taps
00123          */
00124         std::vector<float> taps() const;
00125       };
00126 
00127 
00128       /**************************************************************/
00129 
00130 
00131       /*!
00132        * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
00133        * \ingroup filter
00134        */
00135       class FILTER_API fir_filter_with_buffer_ccc
00136       {
00137       private:
00138         std::vector<gr_complex> d_taps;
00139         unsigned int  d_ntaps;
00140         gr_complex   *d_buffer_ptr;
00141         gr_complex   *d_buffer;
00142         unsigned int  d_idx;
00143         gr_complex  **d_aligned_taps;
00144         gr_complex   *d_output;
00145         int           d_align;
00146         int           d_naligned;
00147 
00148       public:
00149       
00150         // CONSTRUCTORS
00151 
00152         /*!
00153          * \brief construct new FIR with given taps.
00154          *
00155          * Note that taps must be in forward order, e.g., coefficient 0 is
00156          * stored in new_taps[0], coefficient 1 is stored in
00157          * new_taps[1], etc.
00158          */
00159         fir_filter_with_buffer_ccc(const std::vector<gr_complex> &taps);
00160 
00161         ~fir_filter_with_buffer_ccc();
00162 
00163         // MANIPULATORS
00164 
00165         /*!
00166          * \brief compute a single output value.
00167          *
00168          * \p input is a single input value of the filter type
00169          *
00170          * \returns the filtered input value.
00171          */
00172         gr_complex filter(gr_complex input);
00173 
00174         /*!
00175          * \brief compute a single output value; designed for decimating filters.
00176          *
00177          * \p input is a single input value of the filter type. The value of dec is the
00178          *    decimating value of the filter, so input[] must have dec valid values.
00179          *    The filter pushes dec number of items onto the circ. buffer before computing
00180          *    a single output.
00181          *
00182          * \returns the filtered input value.
00183          */
00184         gr_complex filter(const gr_complex input[], unsigned long dec);
00185 
00186         /*!
00187          * \brief compute an array of N output values.
00188          *
00189          * \p input must have (n - 1 + ntaps()) valid entries.
00190          * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
00191          */
00192         void filterN(gr_complex output[],
00193                      const gr_complex input[],
00194                      unsigned long n);
00195 
00196         /*!
00197          * \brief compute an array of N output values, decimating the input
00198          *
00199          * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
00200          * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
00201          * compute the output values.
00202          */
00203         void filterNdec(gr_complex output[], const gr_complex input[],
00204                         unsigned long n, unsigned long decimate);
00205 
00206         // ACCESSORS
00207 
00208         /*!
00209          * \return number of taps in filter.
00210          */
00211         unsigned int ntaps() const { return d_ntaps; }
00212 
00213         /*!
00214          * \brief install \p new_taps as the current taps.
00215          */
00216         void set_taps(const std::vector<gr_complex> &taps);
00217 
00218         /*!
00219          * \return current taps
00220          */
00221         std::vector<gr_complex> taps() const;
00222       };
00223 
00224 
00225       /**************************************************************/
00226 
00227 
00228       /*!
00229        * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
00230        * \ingroup filter
00231        */
00232       class FILTER_API fir_filter_with_buffer_ccf
00233       {
00234       private:
00235         std::vector<float> d_taps;
00236         unsigned int  d_ntaps;
00237         gr_complex   *d_buffer_ptr;
00238         gr_complex   *d_buffer;
00239         unsigned int  d_idx;
00240         float       **d_aligned_taps;
00241         gr_complex   *d_output;
00242         int           d_align;
00243         int           d_naligned;
00244 
00245       public:
00246       
00247         // CONSTRUCTORS
00248 
00249         /*!
00250          * \brief construct new FIR with given taps.
00251          *
00252          * Note that taps must be in forward order, e.g., coefficient 0 is
00253          * stored in new_taps[0], coefficient 1 is stored in
00254          * new_taps[1], etc.
00255          */
00256         fir_filter_with_buffer_ccf(const std::vector<float> &taps);
00257 
00258         ~fir_filter_with_buffer_ccf();
00259 
00260         // MANIPULATORS
00261 
00262         /*!
00263          * \brief compute a single output value.
00264          *
00265          * \p input is a single input value of the filter type
00266          *
00267          * \returns the filtered input value.
00268          */
00269         gr_complex filter(gr_complex input);
00270 
00271         /*!
00272          * \brief compute a single output value; designed for decimating filters.
00273          *
00274          * \p input is a single input value of the filter type. The value of dec is the
00275          *    decimating value of the filter, so input[] must have dec valid values.
00276          *    The filter pushes dec number of items onto the circ. buffer before computing
00277          *    a single output.
00278          *
00279          * \returns the filtered input value.
00280          */
00281         gr_complex filter(const gr_complex input[], unsigned long dec);
00282 
00283         /*!
00284          * \brief compute an array of N output values.
00285          *
00286          * \p input must have (n - 1 + ntaps()) valid entries.
00287          * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
00288          */
00289         void filterN(gr_complex output[],
00290                      const gr_complex input[],
00291                      unsigned long n);
00292 
00293         /*!
00294          * \brief compute an array of N output values, decimating the input
00295          *
00296          * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
00297          * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
00298          * compute the output values.
00299          */
00300         void filterNdec(gr_complex output[], const gr_complex input[],
00301                         unsigned long n, unsigned long decimate);
00302 
00303         // ACCESSORS
00304 
00305         /*!
00306          * \return number of taps in filter.
00307          */
00308         unsigned int ntaps() const { return d_ntaps; }
00309 
00310         /*!
00311          * \brief install \p new_taps as the current taps.
00312          */
00313         void set_taps(const std::vector<float> &taps);
00314 
00315         /*!
00316          * \return current taps
00317          */
00318         std::vector<float> taps() const;
00319       };
00320 
00321 
00322     } /* namespace kernel */
00323   } /* namespace filter */
00324 } /* namespace gr */
00325 
00326 #endif /* INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H */