From f35a7d31f6650752dac693e3f412e5e0dcaf66fa Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 28 Feb 2010 17:36:59 -0500 Subject: Renaming ffft filter base class to reflect its use with floats. --- gnuradio-core/src/lib/filter/gr_fft_filter_fff.cc | 4 +- gnuradio-core/src/lib/filter/gr_fft_filter_fff.h | 6 +- gnuradio-core/src/lib/filter/gri_fft_filter.cc | 155 --------------------- gnuradio-core/src/lib/filter/gri_fft_filter.h | 58 -------- gnuradio-core/src/lib/filter/gri_fft_filter_fff.cc | 155 +++++++++++++++++++++ gnuradio-core/src/lib/filter/gri_fft_filter_fff.h | 58 ++++++++ 6 files changed, 217 insertions(+), 219 deletions(-) delete mode 100644 gnuradio-core/src/lib/filter/gri_fft_filter.cc delete mode 100644 gnuradio-core/src/lib/filter/gri_fft_filter.h create mode 100644 gnuradio-core/src/lib/filter/gri_fft_filter_fff.cc create mode 100644 gnuradio-core/src/lib/filter/gri_fft_filter_fff.h (limited to 'gnuradio-core') diff --git a/gnuradio-core/src/lib/filter/gr_fft_filter_fff.cc b/gnuradio-core/src/lib/filter/gr_fft_filter_fff.cc index 8a9def19b..08c2c022f 100644 --- a/gnuradio-core/src/lib/filter/gr_fft_filter_fff.cc +++ b/gnuradio-core/src/lib/filter/gr_fft_filter_fff.cc @@ -25,7 +25,7 @@ #endif #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ gr_fft_filter_fff::gr_fft_filter_fff (int decimation, const std::vector & { set_history(1); - d_filter = new gri_fft_filter(decimation, taps); + d_filter = new gri_fft_filter_fff(decimation, taps); d_nsamples = d_filter->set_taps(taps); set_output_multiple(d_nsamples); } diff --git a/gnuradio-core/src/lib/filter/gr_fft_filter_fff.h b/gnuradio-core/src/lib/filter/gr_fft_filter_fff.h index 673d5d4e6..04cb3c8f0 100644 --- a/gnuradio-core/src/lib/filter/gr_fft_filter_fff.h +++ b/gnuradio-core/src/lib/filter/gr_fft_filter_fff.h @@ -28,7 +28,7 @@ class gr_fft_filter_fff; typedef boost::shared_ptr gr_fft_filter_fff_sptr; gr_fft_filter_fff_sptr gr_make_fft_filter_fff (int decimation, const std::vector &taps); -class gri_fft_filter; +class gri_fft_filter_fff; /*! * \brief Fast FFT filter with float input, float output and float taps @@ -39,11 +39,9 @@ class gr_fft_filter_fff : public gr_sync_decimator private: friend gr_fft_filter_fff_sptr gr_make_fft_filter_fff (int decimation, const std::vector &taps); - int d_ntaps; int d_nsamples; - int d_fftsize; // fftsize = ntaps + nsamples - 1 - gri_fft_filter *d_filter; bool d_updated; + gri_fft_filter_fff *d_filter; std::vector d_new_taps; /*! diff --git a/gnuradio-core/src/lib/filter/gri_fft_filter.cc b/gnuradio-core/src/lib/filter/gri_fft_filter.cc deleted file mode 100644 index 3d7dd152d..000000000 --- a/gnuradio-core/src/lib/filter/gri_fft_filter.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -gri_fft_filter::gri_fft_filter (int decimation, const std::vector &taps) - : d_fftsize(-1), d_decimation(decimation), d_fwdfft(0), d_invfft(0) -{ - set_taps(taps); -} - -gri_fft_filter::~gri_fft_filter () -{ - delete d_fwdfft; - delete d_invfft; -} - -/* - * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps - */ -int -gri_fft_filter::set_taps (const std::vector &taps) -{ - int i = 0; - compute_sizes(taps.size()); - - d_tail.resize(tailsize()); - for (i = 0; i < tailsize(); i++) - d_tail[i] = 0; - - float *in = d_fwdfft->get_inbuf(); - gr_complex *out = d_fwdfft->get_outbuf(); - - float scale = 1.0 / d_fftsize; - - // Compute forward xform of taps. - // Copy taps into first ntaps slots, then pad with zeros - for (i = 0; i < d_ntaps; i++) - in[i] = taps[i] * scale; - - for (; i < d_fftsize; i++) - in[i] = 0; - - d_fwdfft->execute(); // do the xform - - // now copy output to d_xformed_taps - for (i = 0; i < d_fftsize/2+1; i++) - d_xformed_taps[i] = out[i]; - - return d_nsamples; -} - -// determine and set d_ntaps, d_nsamples, d_fftsize - -void -gri_fft_filter::compute_sizes(int ntaps) -{ - int old_fftsize = d_fftsize; - d_ntaps = ntaps; - d_fftsize = (int) (2 * pow(2.0, ceil(log(ntaps) / log(2)))); - d_nsamples = d_fftsize - d_ntaps + 1; - - if (0) - fprintf(stderr, "gri_fft_filter: ntaps = %d, fftsize = %d, nsamples = %d\n", - d_ntaps, d_fftsize, d_nsamples); - - assert(d_fftsize == d_ntaps + d_nsamples -1 ); - - if (d_fftsize != old_fftsize){ // compute new plans - delete d_fwdfft; - delete d_invfft; - d_fwdfft = new gri_fft_real_fwd(d_fftsize); - d_invfft = new gri_fft_real_rev(d_fftsize); - d_xformed_taps.resize(d_fftsize/2+1); - } -} - -int -gri_fft_filter::filter (int nitems, const float *input, float *output) -{ - int dec_ctr = 0; - int j = 0; - int ninput_items = nitems * d_decimation; - - for (int i = 0; i < ninput_items; i += d_nsamples){ - - memcpy(d_fwdfft->get_inbuf(), &input[i], d_nsamples * sizeof(float)); - - for (j = d_nsamples; j < d_fftsize; j++) - d_fwdfft->get_inbuf()[j] = 0; - - d_fwdfft->execute(); // compute fwd xform - - gr_complex *a = d_fwdfft->get_outbuf(); - gr_complex *b = &d_xformed_taps[0]; - gr_complex *c = d_invfft->get_inbuf(); - - for (j = 0; j < d_fftsize/2+1; j++) // filter in the freq domain - c[j] = a[j] * b[j]; - - d_invfft->execute(); // compute inv xform - - // add in the overlapping tail - - for (j = 0; j < tailsize(); j++) - d_invfft->get_outbuf()[j] += d_tail[j]; - - // copy nsamples to output - - //memcpy(out, d_invfft->get_outbuf(), d_nsamples * sizeof(float)); - //out += d_nsamples; - - j = dec_ctr; - while (j < d_nsamples) { - *output++ = d_invfft->get_outbuf()[j]; - j += d_decimation; - } - dec_ctr = (j - d_nsamples); - - // stash the tail - memcpy(&d_tail[0], d_invfft->get_outbuf() + d_nsamples, - tailsize() * sizeof(float)); - } - - assert(dec_ctr == 0); - - return nitems; -} diff --git a/gnuradio-core/src/lib/filter/gri_fft_filter.h b/gnuradio-core/src/lib/filter/gri_fft_filter.h deleted file mode 100644 index 174a596c2..000000000 --- a/gnuradio-core/src/lib/filter/gri_fft_filter.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GRI_FFT_FILTER_H -#define INCLUDED_GRI_FFT_FILTER_H - -#include -#include - -class gri_fft_real_fwd; -class gri_fft_real_rev; - -class gri_fft_filter -{ - private: - int d_ntaps; - int d_nsamples; - int d_fftsize; // fftsize = ntaps + nsamples - 1 - int d_decimation; - gri_fft_real_fwd *d_fwdfft; // forward "plan" - gri_fft_real_rev *d_invfft; // inverse "plan" - std::vector d_tail; // state carried between blocks for overlap-add - std::vector d_xformed_taps; // Fourier xformed taps - std::vector d_new_taps; - - void compute_sizes(int ntaps); - int tailsize() const { return d_ntaps - 1; } - - public: - gri_fft_filter (int decimation, const std::vector &taps); - ~gri_fft_filter (); - - int set_taps (const std::vector &taps); - - int filter (int nitems, const float *input, float *output); - -}; - -#endif /* INCLUDED_GRI_FFT_FILTER_H */ diff --git a/gnuradio-core/src/lib/filter/gri_fft_filter_fff.cc b/gnuradio-core/src/lib/filter/gri_fft_filter_fff.cc new file mode 100644 index 000000000..246d876b2 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gri_fft_filter_fff.cc @@ -0,0 +1,155 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +gri_fft_filter_fff::gri_fft_filter_fff (int decimation, const std::vector &taps) + : d_fftsize(-1), d_decimation(decimation), d_fwdfft(0), d_invfft(0) +{ + set_taps(taps); +} + +gri_fft_filter_fff::~gri_fft_filter_fff () +{ + delete d_fwdfft; + delete d_invfft; +} + +/* + * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps + */ +int +gri_fft_filter_fff::set_taps (const std::vector &taps) +{ + int i = 0; + compute_sizes(taps.size()); + + d_tail.resize(tailsize()); + for (i = 0; i < tailsize(); i++) + d_tail[i] = 0; + + float *in = d_fwdfft->get_inbuf(); + gr_complex *out = d_fwdfft->get_outbuf(); + + float scale = 1.0 / d_fftsize; + + // Compute forward xform of taps. + // Copy taps into first ntaps slots, then pad with zeros + for (i = 0; i < d_ntaps; i++) + in[i] = taps[i] * scale; + + for (; i < d_fftsize; i++) + in[i] = 0; + + d_fwdfft->execute(); // do the xform + + // now copy output to d_xformed_taps + for (i = 0; i < d_fftsize/2+1; i++) + d_xformed_taps[i] = out[i]; + + return d_nsamples; +} + +// determine and set d_ntaps, d_nsamples, d_fftsize + +void +gri_fft_filter_fff::compute_sizes(int ntaps) +{ + int old_fftsize = d_fftsize; + d_ntaps = ntaps; + d_fftsize = (int) (2 * pow(2.0, ceil(log(ntaps) / log(2)))); + d_nsamples = d_fftsize - d_ntaps + 1; + + if (0) + fprintf(stderr, "gri_fft_filter_fff: ntaps = %d, fftsize = %d, nsamples = %d\n", + d_ntaps, d_fftsize, d_nsamples); + + assert(d_fftsize == d_ntaps + d_nsamples -1 ); + + if (d_fftsize != old_fftsize){ // compute new plans + delete d_fwdfft; + delete d_invfft; + d_fwdfft = new gri_fft_real_fwd(d_fftsize); + d_invfft = new gri_fft_real_rev(d_fftsize); + d_xformed_taps.resize(d_fftsize/2+1); + } +} + +int +gri_fft_filter_fff::filter (int nitems, const float *input, float *output) +{ + int dec_ctr = 0; + int j = 0; + int ninput_items = nitems * d_decimation; + + for (int i = 0; i < ninput_items; i += d_nsamples){ + + memcpy(d_fwdfft->get_inbuf(), &input[i], d_nsamples * sizeof(float)); + + for (j = d_nsamples; j < d_fftsize; j++) + d_fwdfft->get_inbuf()[j] = 0; + + d_fwdfft->execute(); // compute fwd xform + + gr_complex *a = d_fwdfft->get_outbuf(); + gr_complex *b = &d_xformed_taps[0]; + gr_complex *c = d_invfft->get_inbuf(); + + for (j = 0; j < d_fftsize/2+1; j++) // filter in the freq domain + c[j] = a[j] * b[j]; + + d_invfft->execute(); // compute inv xform + + // add in the overlapping tail + + for (j = 0; j < tailsize(); j++) + d_invfft->get_outbuf()[j] += d_tail[j]; + + // copy nsamples to output + + //memcpy(out, d_invfft->get_outbuf(), d_nsamples * sizeof(float)); + //out += d_nsamples; + + j = dec_ctr; + while (j < d_nsamples) { + *output++ = d_invfft->get_outbuf()[j]; + j += d_decimation; + } + dec_ctr = (j - d_nsamples); + + // stash the tail + memcpy(&d_tail[0], d_invfft->get_outbuf() + d_nsamples, + tailsize() * sizeof(float)); + } + + assert(dec_ctr == 0); + + return nitems; +} diff --git a/gnuradio-core/src/lib/filter/gri_fft_filter_fff.h b/gnuradio-core/src/lib/filter/gri_fft_filter_fff.h new file mode 100644 index 000000000..35a2d2310 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gri_fft_filter_fff.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GRI_FFT_FILTER_FFF_H +#define INCLUDED_GRI_FFT_FILTER_FFF_H + +#include +#include + +class gri_fft_real_fwd; +class gri_fft_real_rev; + +class gri_fft_filter_fff +{ + private: + int d_ntaps; + int d_nsamples; + int d_fftsize; // fftsize = ntaps + nsamples - 1 + int d_decimation; + gri_fft_real_fwd *d_fwdfft; // forward "plan" + gri_fft_real_rev *d_invfft; // inverse "plan" + std::vector d_tail; // state carried between blocks for overlap-add + std::vector d_xformed_taps; // Fourier xformed taps + std::vector d_new_taps; + + void compute_sizes(int ntaps); + int tailsize() const { return d_ntaps - 1; } + + public: + gri_fft_filter_fff (int decimation, const std::vector &taps); + ~gri_fft_filter_fff (); + + int set_taps (const std::vector &taps); + + int filter (int nitems, const float *input, float *output); + +}; + +#endif /* INCLUDED_GRI_FFT_FILTER_FFF_H */ -- cgit