commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r11310 - in gnuradio/branches/developers/trondeau/pfb/


From: trondeau
Subject: [Commit-gnuradio] r11310 - in gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src: lib/filter python/gnuradio/blks2impl
Date: Mon, 29 Jun 2009 20:23:00 -0600 (MDT)

Author: trondeau
Date: 2009-06-29 20:22:59 -0600 (Mon, 29 Jun 2009)
New Revision: 11310

Added:
   
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
   
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.h
   
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.i
   
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py
Log:
Adding a polyphase filterbank M-to-1 downsampler.

Added: 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
===================================================================
--- 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
                              (rev 0)
+++ 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
      2009-06-30 02:22:59 UTC (rev 11310)
@@ -0,0 +1,149 @@
+/* -*- 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_decimator_ccf.h>
+#include <gr_fir_ccf.h>
+#include <gr_fir_util.h>
+#include <gri_fft.h>
+#include <gr_io_signature.h>
+#include <gr_expj.h>
+
+gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim, 
+                                                    const std::vector<float> 
&taps,
+                                                    unsigned int channel)
+{
+  return gr_pfb_decimator_ccf_sptr (new gr_pfb_decimator_ccf (decim, taps, 
channel));
+}
+
+
+gr_pfb_decimator_ccf::gr_pfb_decimator_ccf (unsigned int decim, 
+                                           const std::vector<float> &taps,
+                                           unsigned int channel)
+  : gr_block ("pfb_decimator_ccf",
+             gr_make_io_signature (decim, decim, sizeof(gr_complex)),
+             gr_make_io_signature (1, 1, sizeof(gr_complex))),
+    d_updated (false)
+{
+  d_rate = decim;
+  d_filters = std::vector<gr_fir_ccf*>(d_rate);
+  d_chan = channel;
+
+  // Create an FIR filter for each channel and zero out the taps
+  std::vector<float> vtaps(0, d_rate);
+  for(unsigned int i = 0; i < d_rate; i++) {
+    d_filters[i] = gr_fir_util::create_gr_fir_ccf(vtaps);
+  }
+
+  // Now, actually set the filters' taps
+  set_taps(taps);
+
+  // Create the FFT to handle the output de-spinning of the channels
+  d_fft = new gri_fft_complex (d_rate, false);
+}
+
+gr_pfb_decimator_ccf::~gr_pfb_decimator_ccf ()
+{
+  for(unsigned int i = 0; i < d_rate; i++) {
+    delete d_filters[i];
+  }
+}
+
+void
+gr_pfb_decimator_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_rate);
+
+  // Create d_numchan vectors to store each channel's taps
+  std::vector< std::vector<float> > vtaps(d_rate);
+
+  // Partition the filter
+  for(i = 0; i < d_rate; i++) {
+    // Each channel uses all d_taps_per_filter with 0's if not enough taps to 
fill out
+    vtaps[i] = std::vector<float>(d_taps_per_filter, 0);
+    for(j = 0; j < d_taps_per_filter; j++) {
+      vtaps[i][j] = taps[i + j*d_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(vtaps[i]);
+  }
+
+  // Set the history to ensure enough input items for each filter
+  set_history (d_taps_per_filter);
+
+  d_updated = true;
+}
+
+int
+gr_pfb_decimator_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;
+    consume_each(0);
+    return 0;               // history requirements may have changed.
+  }
+
+  int i = 0, count = 0;
+  while((i < noutput_items) && (count < ninput_items[0])) {
+    // Move through filters from bottom to top
+    out[i] = 0;
+    for(int j = d_rate-1; j >= 0; j--) {
+      // Take in the items from the first input stream to d_rate
+      in = (gr_complex*)input_items[d_rate - 1 - j];
+
+      // Filter current input stream from bottom filter to top
+      // The rotate them by expj(j*k*2pi/M) where M is the number of filters
+      // (the decimation rate) and k is the channel number to extract
+      
+      // This is the real math that goes on; we abuse the FFT to do this 
quickly
+      // for decimation rates > N where N is a small number (~5).
+      //out[i] += d_filters[j]->filter(&in[i])*gr_expj(j*d_chan*2*M_PI/d_rate);
+
+      d_fft->get_inbuf()[j] = d_filters[j]->filter(&in[i]);
+    }
+
+    // Perform the FFT to do the complex multiply despinning for all channels
+    d_fft->execute();
+
+    // Select only the desired channel out
+    out[i] = d_fft->get_outbuf()[d_chan];
+
+    i++;
+    count++;
+  }
+  
+  consume_each(count);
+  return i;
+}

Added: 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.h
===================================================================
--- 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.h
                               (rev 0)
+++ 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.h
       2009-06-30 02:22:59 UTC (rev 11310)
@@ -0,0 +1,76 @@
+/* -*- 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_DECIMATOR_CCF_H
+#define        INCLUDED_GR_PFB_DECIMATOR_CCF_H
+
+#include <gr_block.h>
+
+class gr_pfb_decimator_ccf;
+typedef boost::shared_ptr<gr_pfb_decimator_ccf> gr_pfb_decimator_ccf_sptr;
+gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim, 
+                                                    const std::vector<float> 
&taps,
+                                                    unsigned int channel=0);
+
+class gr_fir_ccf;
+class gri_fft_complex;
+
+/*!
+ * \brief FIR filter with gr_complex input, gr_complex output and float taps
+ * \ingroup filter_blk
+ */
+class gr_pfb_decimator_ccf : public gr_block
+{
+ private:
+  friend gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int 
decim,
+                                                             const 
std::vector<float> &taps,
+                                                             unsigned int 
channel);
+
+  std::vector<gr_fir_ccf*> d_filters;
+  gri_fft_complex         *d_fft;
+  unsigned int             d_rate;
+  unsigned int             d_chan;
+  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_decimator_ccf (unsigned int decim, 
+                       const std::vector<float> &taps,
+                       unsigned int channel);
+
+public:
+  ~gr_pfb_decimator_ccf ();
+  
+  void set_taps (const std::vector<float> &taps);
+  //void set_channel (unsigned int channel);
+
+  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_decimator_ccf.i
===================================================================
--- 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.i
                               (rev 0)
+++ 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.i
       2009-06-30 02:22:59 UTC (rev 11310)
@@ -0,0 +1,41 @@
+/* -*- 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_decimator_ccf);
+
+gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim,
+                                                    const std::vector<float> 
&taps,
+                                                    unsigned int channel);
+
+class gr_pfb_decimator_ccf : public gr_block
+{
+ private:
+  gr_pfb_decimator_ccf (unsigned int decim,
+                       const std::vector<float> &taps,
+                       unsigned int channel);
+
+ public:
+  ~gr_pfb_decimator_ccf ();
+
+  void set_taps (const std::vector<float> &taps);
+  //void set_channel (unsigned int channel);
+};

Added: 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py
                              (rev 0)
+++ 
gnuradio/branches/developers/trondeau/pfb/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py
      2009-06-30 02:22:59 UTC (rev 11310)
@@ -0,0 +1,48 @@
+#!/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_decimator_ccf(gr.hier_block2):
+    '''
+    Make a Polyphase Filter decimator (complex in, complex out, floating-point 
taps)
+    This simplifies the interface by allowing a single input stream to connect 
to this block.
+    It will then output a stream that is the decimated output stream.
+    '''
+    def __init__(self, decim, taps, channel=0):
+       gr.hier_block2.__init__(self, "pfb_decimator_ccf",
+                               gr.io_signature(1, 1, gr.sizeof_gr_complex), # 
Input signature
+                               gr.io_signature(1, 1, gr.sizeof_gr_complex)) # 
Output signature
+
+        self._decim = decim
+        self._taps = taps
+        self._channel = channel
+
+        self.s2ss = gr.stream_to_streams(gr.sizeof_gr_complex, self._decim)
+        self.pfb = gr.pfb_decimator_ccf(self._decim, self._taps, self._channel)
+
+        self.connect(self, self.s2ss)
+
+        for i in xrange(self._decim):
+            self.connect((self.s2ss,i), (self.pfb,i))
+
+        self.connect(self.pfb, self)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]