summaryrefslogtreecommitdiff
path: root/gnuradio-core
diff options
context:
space:
mode:
authorTom Rondeau2010-02-28 17:37:48 -0500
committerTom Rondeau2010-02-28 17:37:48 -0500
commit72c47024f4b4677f116222a0adfadeedf180122c (patch)
treea90494116f5666b7c07b1c0cf9becaefe098a028 /gnuradio-core
parentf35a7d31f6650752dac693e3f412e5e0dcaf66fa (diff)
downloadgnuradio-72c47024f4b4677f116222a0adfadeedf180122c.tar.gz
gnuradio-72c47024f4b4677f116222a0adfadeedf180122c.tar.bz2
gnuradio-72c47024f4b4677f116222a0adfadeedf180122c.zip
New fft filter base class to handle complex data types. Passes make check.
Diffstat (limited to 'gnuradio-core')
-rw-r--r--gnuradio-core/src/lib/filter/Makefile.am6
-rw-r--r--gnuradio-core/src/lib/filter/gr_fft_filter_ccc.cc138
-rw-r--r--gnuradio-core/src/lib/filter/gr_fft_filter_ccc.h16
-rw-r--r--gnuradio-core/src/lib/filter/gri_fft_filter_ccc.cc163
-rw-r--r--gnuradio-core/src/lib/filter/gri_fft_filter_ccc.h57
5 files changed, 238 insertions, 142 deletions
diff --git a/gnuradio-core/src/lib/filter/Makefile.am b/gnuradio-core/src/lib/filter/Makefile.am
index c7133ce22..2d7fb0db8 100644
--- a/gnuradio-core/src/lib/filter/Makefile.am
+++ b/gnuradio-core/src/lib/filter/Makefile.am
@@ -184,7 +184,8 @@ libfilter_la_common_SOURCES = \
$(GENERATED_CC) \
gr_adaptive_fir_ccf.cc \
gr_cma_equalizer_cc.cc \
- gri_fft_filter.cc \
+ gri_fft_filter_fff.cc \
+ gri_fft_filter_ccc.cc \
gr_fft_filter_ccc.cc \
gr_fft_filter_fff.cc \
gr_goertzel_fc.cc \
@@ -260,7 +261,8 @@ grinclude_HEADERS = \
gr_altivec.h \
gr_cma_equalizer_cc.h \
gr_cpu.h \
- gri_fft_filter.h \
+ gri_fft_filter_fff.h \
+ gri_fft_filter_ccc.h \
gr_fft_filter_ccc.h \
gr_fft_filter_fff.h \
gr_filter_delay_fc.h \
diff --git a/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.cc b/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.cc
index 3dd40d56d..b1f04fd0f 100644
--- a/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.cc
+++ b/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.cc
@@ -30,6 +30,7 @@
#endif
#include <gr_fft_filter_ccc.h>
+#include <gri_fft_filter_ccc.h>
#include <gr_io_signature.h>
#include <gri_fft.h>
#include <math.h>
@@ -52,31 +53,18 @@ gr_fft_filter_ccc::gr_fft_filter_ccc (int decimation, const std::vector<gr_compl
gr_make_io_signature (1, 1, sizeof (gr_complex)),
gr_make_io_signature (1, 1, sizeof (gr_complex)),
decimation),
- d_fftsize(-1), d_fwdfft(0), d_invfft(0), d_updated(false)
+ d_updated(false)
{
- // if (decimation != 1)
- // throw std::invalid_argument("gr_fft_filter_ccc: decimation must be 1");
-
set_history(1);
- actual_set_taps(taps);
+ d_filter = new gri_fft_filter_ccc(decimation, taps);
+ d_nsamples = d_filter->set_taps(taps);
+ set_output_multiple(d_nsamples);
}
gr_fft_filter_ccc::~gr_fft_filter_ccc ()
{
- delete d_fwdfft;
- delete d_invfft;
-}
-
-#if 0
-static void
-print_vector_complex(const std::string label, const std::vector<gr_complex> &x)
-{
- std::cout << label;
- for (unsigned i = 0; i < x.size(); i++)
- std::cout << x[i] << " ";
- std::cout << "\n";
+ delete d_filter;
}
-#endif
void
gr_fft_filter_ccc::set_taps (const std::vector<gr_complex> &taps)
@@ -85,130 +73,26 @@ gr_fft_filter_ccc::set_taps (const std::vector<gr_complex> &taps)
d_updated = true;
}
-/*
- * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps
- */
-void
-gr_fft_filter_ccc::actual_set_taps (const std::vector<gr_complex> &taps)
-{
- int i = 0;
- compute_sizes(taps.size());
-
- d_tail.resize(tailsize());
- for (i = 0; i < tailsize(); i++)
- d_tail[i] = 0;
-
- gr_complex *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; i++)
- d_xformed_taps[i] = out[i];
-
- //print_vector_complex("transformed taps:", d_xformed_taps);
-}
-
-// determine and set d_ntaps, d_nsamples, d_fftsize
-
-void
-gr_fft_filter_ccc::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, "gr_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_complex(d_fftsize, true);
- d_invfft = new gri_fft_complex(d_fftsize, false);
- d_xformed_taps.resize(d_fftsize);
- }
-
- set_output_multiple(d_nsamples);
-}
-
int
gr_fft_filter_ccc::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
- gr_complex *in = (gr_complex *) input_items[0];
+ const gr_complex *in = (const gr_complex *) input_items[0];
gr_complex *out = (gr_complex *) output_items[0];
if (d_updated){
- actual_set_taps(d_new_taps);
+ d_nsamples = d_filter->set_taps(d_new_taps);
d_updated = false;
+ set_output_multiple(d_nsamples);
return 0; // output multiple may have changed
}
assert(noutput_items % d_nsamples == 0);
- int dec_ctr = 0;
- int j = 0;
- int ninput_items = noutput_items * decimation();
-
- for (int i = 0; i < ninput_items; i += d_nsamples){
-
- memcpy(d_fwdfft->get_inbuf(), &in[i], d_nsamples * sizeof(gr_complex));
-
- 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; 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(gr_complex));
- //out += d_nsamples;
-
- j = dec_ctr;
- while (j < d_nsamples) {
- *out++ = d_invfft->get_outbuf()[j];
- j += decimation();
- }
- dec_ctr = (j - d_nsamples);
-
- // stash the tail
- memcpy(&d_tail[0], d_invfft->get_outbuf() + d_nsamples,
- tailsize() * sizeof(gr_complex));
- }
+ d_filter->filter(noutput_items, in, out);
- assert((out - (gr_complex *) output_items[0]) == noutput_items);
- assert(dec_ctr == 0);
+ //assert((out - (gr_complex *) output_items[0]) == noutput_items);
return noutput_items;
}
diff --git a/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.h b/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.h
index c5363dcbb..cfb9ff35d 100644
--- a/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.h
+++ b/gnuradio-core/src/lib/filter/gr_fft_filter_ccc.h
@@ -28,8 +28,7 @@ class gr_fft_filter_ccc;
typedef boost::shared_ptr<gr_fft_filter_ccc> gr_fft_filter_ccc_sptr;
gr_fft_filter_ccc_sptr gr_make_fft_filter_ccc (int decimation, const std::vector<gr_complex> &taps);
-class gr_fir_ccc;
-class gri_fft_complex;
+class gri_fft_filter_ccc;
/*!
* \brief Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps
@@ -40,15 +39,10 @@ class gr_fft_filter_ccc : public gr_sync_decimator
private:
friend gr_fft_filter_ccc_sptr gr_make_fft_filter_ccc (int decimation, const std::vector<gr_complex> &taps);
- int d_ntaps;
int d_nsamples;
- int d_fftsize; // fftsize = ntaps + nsamples - 1
- gri_fft_complex *d_fwdfft; // forward "plan"
- gri_fft_complex *d_invfft; // inverse "plan"
- std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add
- std::vector<gr_complex> d_xformed_taps; // Fourier xformed taps
- std::vector<gr_complex> d_new_taps;
bool d_updated;
+ gri_fft_filter_ccc *d_filter;
+ std::vector<gr_complex> d_new_taps;
/*!
* Construct a FFT filter with the given taps
@@ -58,10 +52,6 @@ class gr_fft_filter_ccc : public gr_sync_decimator
*/
gr_fft_filter_ccc (int decimation, const std::vector<gr_complex> &taps);
- void compute_sizes(int ntaps);
- int tailsize() const { return d_ntaps - 1; }
- void actual_set_taps (const std::vector<gr_complex> &taps);
-
public:
~gr_fft_filter_ccc ();
diff --git a/gnuradio-core/src/lib/filter/gri_fft_filter_ccc.cc b/gnuradio-core/src/lib/filter/gri_fft_filter_ccc.cc
new file mode 100644
index 000000000..4c596630c
--- /dev/null
+++ b/gnuradio-core/src/lib/filter/gri_fft_filter_ccc.cc
@@ -0,0 +1,163 @@
+/* -*- 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 <gri_fft_filter_ccc.h>
+#include <gri_fft.h>
+#include <assert.h>
+#include <stdexcept>
+#include <cstdio>
+
+gri_fft_filter_ccc::gri_fft_filter_ccc (int decimation, const std::vector<gr_complex> &taps)
+ : d_fftsize(-1), d_decimation(decimation), d_fwdfft(0), d_invfft(0)
+{
+ set_taps(taps);
+}
+
+gri_fft_filter_ccc::~gri_fft_filter_ccc ()
+{
+ delete d_fwdfft;
+ delete d_invfft;
+}
+
+#if 0
+static void
+print_vector_complex(const std::string label, const std::vector<gr_complex> &x)
+{
+ std::cout << label;
+ for (unsigned i = 0; i < x.size(); i++)
+ std::cout << x[i] << " ";
+ std::cout << "\n";
+}
+#endif
+
+
+/*
+ * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps
+ */
+int
+gri_fft_filter_ccc::set_taps (const std::vector<gr_complex> &taps)
+{
+ int i = 0;
+ compute_sizes(taps.size());
+
+ d_tail.resize(tailsize());
+ for (i = 0; i < tailsize(); i++)
+ d_tail[i] = 0;
+
+ gr_complex *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; i++)
+ d_xformed_taps[i] = out[i];
+
+ return d_nsamples;
+}
+
+// determine and set d_ntaps, d_nsamples, d_fftsize
+
+void
+gri_fft_filter_ccc::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_ccc: 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_complex(d_fftsize, true);
+ d_invfft = new gri_fft_complex(d_fftsize, false);
+ d_xformed_taps.resize(d_fftsize);
+ }
+}
+
+int
+gri_fft_filter_ccc::filter (int nitems, const gr_complex *input, gr_complex *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(gr_complex));
+
+ 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; 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
+ 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(gr_complex));
+ }
+
+ assert(dec_ctr == 0);
+
+ return nitems;
+}
diff --git a/gnuradio-core/src/lib/filter/gri_fft_filter_ccc.h b/gnuradio-core/src/lib/filter/gri_fft_filter_ccc.h
new file mode 100644
index 000000000..a65a3b0e6
--- /dev/null
+++ b/gnuradio-core/src/lib/filter/gri_fft_filter_ccc.h
@@ -0,0 +1,57 @@
+/* -*- 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_CCC_H
+#define INCLUDED_GRI_FFT_FILTER_CCC_H
+
+#include <gr_complex.h>
+#include <vector>
+
+class gri_fft_complex;
+
+class gri_fft_filter_ccc
+{
+ private:
+ int d_ntaps;
+ int d_nsamples;
+ int d_fftsize; // fftsize = ntaps + nsamples - 1
+ int d_decimation;
+ gri_fft_complex *d_fwdfft; // forward "plan"
+ gri_fft_complex *d_invfft; // inverse "plan"
+ std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add
+ std::vector<gr_complex> d_xformed_taps; // Fourier xformed taps
+ std::vector<gr_complex> d_new_taps;
+
+ void compute_sizes(int ntaps);
+ int tailsize() const { return d_ntaps - 1; }
+
+ public:
+ gri_fft_filter_ccc (int decimation, const std::vector<gr_complex> &taps);
+ ~gri_fft_filter_ccc ();
+
+ int set_taps (const std::vector<gr_complex> &taps);
+
+ int filter (int nitems, const gr_complex *input, gr_complex *output);
+
+};
+
+#endif /* INCLUDED_GRI_FFT_FILTER_CCC_H */