[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r11312 - in gnuradio/branches/developers/trondeau/pfb/
From: |
trondeau |
Subject: |
[Commit-gnuradio] r11312 - in gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src: lib/filter python/gnuradio/blks2impl |
Date: |
Mon, 29 Jun 2009 20:24:48 -0600 (MDT) |
Author: trondeau
Date: 2009-06-29 20:24:48 -0600 (Mon, 29 Jun 2009)
New Revision: 11312
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.i
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py
Log:
Adding a polyphase filterbank aritrary resampler.
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc
(rev 0)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc
2009-06-30 02:24:48 UTC (rev 11312)
@@ -0,0 +1,159 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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 <gr_pfb_arb_resampler_ccf.h>
+#include <gr_fir_ccf.h>
+#include <gr_fir_util.h>
+#include <gr_io_signature.h>
+
+gr_pfb_arb_resampler_ccf_sptr gr_make_pfb_arb_resampler_ccf (float rate,
+ const
std::vector<float> &taps)
+{
+ return gr_pfb_arb_resampler_ccf_sptr (new gr_pfb_arb_resampler_ccf (rate,
taps));
+}
+
+
+gr_pfb_arb_resampler_ccf::gr_pfb_arb_resampler_ccf (float rate,
+ const std::vector<float>
&taps)
+ : gr_block ("pfb_arb_resampler_ccf",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)),
+ gr_make_io_signature (1, 1, sizeof(gr_complex))),
+ d_updated (false)
+{
+ d_int_rate = 32;
+ d_dec_rate = (unsigned int)floor(d_int_rate/rate);
+ d_flt_rate = (d_int_rate/rate) - d_dec_rate;
+ d_acc = 0;
+ d_last_filter = 0;
+
+ d_filters = std::vector<gr_fir_ccf*>(d_int_rate);
+
+ // Create an FIR filter for each channel and zero out the taps
+ std::vector<float> vtaps(0, d_int_rate);
+ for(unsigned int i = 0; i < d_int_rate; i++) {
+ d_filters[i] = gr_fir_util::create_gr_fir_ccf(vtaps);
+ }
+
+ // Now, actually set the filters' taps
+ set_taps(taps);
+}
+
+gr_pfb_arb_resampler_ccf::~gr_pfb_arb_resampler_ccf ()
+{
+ for(unsigned int i = 0; i < d_int_rate; i++) {
+ delete d_filters[i];
+ }
+}
+
+void
+gr_pfb_arb_resampler_ccf::set_taps (const std::vector<float> &taps)
+{
+ unsigned int i,j;
+
+ unsigned int ntaps = taps.size();
+ d_taps_per_filter = (unsigned int)ceil((double)ntaps/(double)d_int_rate);
+
+ // Create d_numchan vectors to store each channel's taps
+ d_taps.resize(d_int_rate);
+
+ // Partition the filter
+ for(i = 0; i < d_int_rate; i++) {
+ // Each channel uses all d_taps_per_filter with 0's if not enough taps to
fill out
+ d_taps[i] = std::vector<float>(d_taps_per_filter, 0);
+ for(j = 0; j < d_taps_per_filter; j++) {
+ d_taps[i][j] = taps[i + j*d_int_rate]; // add taps to channels in
reverse order
+ }
+
+ // Build a filter for each channel and add it's taps to it
+ d_filters[i]->set_taps(d_taps[i]);
+ }
+
+ // Set the history to ensure enough input items for each filter
+ set_history (d_taps_per_filter);
+
+ d_updated = true;
+}
+
+void
+gr_pfb_arb_resampler_ccf::print_taps()
+{
+ unsigned int i, j;
+ for(i = 0; i < d_int_rate; i++) {
+ printf("filter[%d]: [", i);
+ for(j = 0; j < d_taps_per_filter; j++) {
+ printf(" %.4e", d_taps[i][j]);
+ }
+ printf("]\n");
+ }
+}
+
+int
+gr_pfb_arb_resampler_ccf::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ gr_complex *in = (gr_complex *) input_items[0];
+ gr_complex *out = (gr_complex *) output_items[0];
+
+ if (d_updated) {
+ d_updated = false;
+ return 0; // history requirements may have changed.
+ }
+
+ int i = 0, j = 0, count = 0;
+ gr_complex o0, o1;
+
+ j = d_last_filter;
+ while(i < noutput_items) {
+ // start j by wrapping around mod the number of channels
+
+ while(j < d_int_rate) {
+ // Take the current filter output
+ o0 = d_filters[j]->filter(&in[count]);
+
+ // Take the next filter output; wrap around to 0 if necessary
+ if(j+1 == d_int_rate)
+ o1 = d_filters[0]->filter(&in[count+1]);
+ else
+ o1 = d_filters[j]->filter(&in[count]);
+
+ out[i] = o0 + (o1 - o0)*d_flt_rate;
+ i++;
+
+ d_acc += d_dec_rate + d_flt_rate;
+ j = (int)floor(d_acc);
+ }
+ count++;
+ j = j % d_int_rate;
+ d_acc = d_acc - floor(d_acc);
+ }
+
+ d_last_filter = j;
+
+ consume_each(count);
+ return i;
+}
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h
(rev 0)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h
2009-06-30 02:24:48 UTC (rev 11312)
@@ -0,0 +1,75 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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_GR_PFB_ARB_RESAMPLER_CCF_H
+#define INCLUDED_GR_PFB_ARB_RESAMPLER_CCF_H
+
+#include <gr_block.h>
+
+class gr_pfb_arb_resampler_ccf;
+typedef boost::shared_ptr<gr_pfb_arb_resampler_ccf>
gr_pfb_arb_resampler_ccf_sptr;
+gr_pfb_arb_resampler_ccf_sptr gr_make_pfb_arb_resampler_ccf (float rate,
+ const
std::vector<float> &taps);
+
+class gr_fir_ccf;
+
+/*!
+ * \brief FIR filter with gr_complex input, gr_complex output and float taps
+ * \ingroup filter_blk
+ */
+class gr_pfb_arb_resampler_ccf : public gr_block
+{
+ private:
+ friend gr_pfb_arb_resampler_ccf_sptr gr_make_pfb_arb_resampler_ccf (float
rate,
+ const
std::vector<float> &taps);
+
+ std::vector<gr_fir_ccf*> d_filters;
+ std::vector< std::vector<float> > d_taps;
+ unsigned int d_int_rate;
+ unsigned int d_dec_rate;
+ float d_flt_rate;
+ float d_acc;
+ unsigned int d_last_filter;
+ unsigned int d_taps_per_filter;
+ bool d_updated;
+
+ /*!
+ * Construct a Polyphase filterbank for channelization with the given
+ * number of channels and taps
+ */
+ gr_pfb_arb_resampler_ccf (float rate,
+ const std::vector<float> &taps);
+
+public:
+ ~gr_pfb_arb_resampler_ccf ();
+
+ void set_taps (const std::vector<float> &taps);
+ void print_taps();
+
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.i
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.i
(rev 0)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.i
2009-06-30 02:24:48 UTC (rev 11312)
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,pfb_arb_resampler_ccf);
+
+gr_pfb_arb_resampler_ccf_sptr gr_make_pfb_arb_resampler_ccf (float rate,
+ const
std::vector<float> &taps);
+
+class gr_pfb_arb_resampler_ccf : public gr_block
+{
+ private:
+ gr_pfb_arb_resampler_ccf (float rate,
+ const std::vector<float> &taps);
+
+ public:
+ ~gr_pfb_arb_resampler_ccf ();
+
+ void set_taps (const std::vector<float> &taps);
+ void print_taps();
+};
Added:
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py
===================================================================
---
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py
(rev 0)
+++
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py
2009-06-30 02:24:48 UTC (rev 11312)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 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.
+#
+
+from gnuradio import gr
+
+class pfb_arb_resampler_ccf(gr.hier_block2):
+ '''
+
+ '''
+ def __init__(self, rate, taps):
+ gr.hier_block2.__init__(self, "pfb_arb_resampler_ccf",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), #
Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) #
Output signature
+
+ self._rate = rate
+ self._taps = taps
+
+ self.pfb = gr.pfb_arb_resampler_ccf(self._rate, self._taps)
+
+ self.connect(self, self.pfb)
+ self.connect(self.pfb, self)
+
+
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r11312 - in gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src: lib/filter python/gnuradio/blks2impl,
trondeau <=