commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11529 - gnuradio/branches/developers/n4hy/pfb_iir2/gn


From: n4hy
Subject: [Commit-gnuradio] r11529 - gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter
Date: Mon, 3 Aug 2009 01:08:57 -0600 (MDT)

Author: n4hy
Date: 2009-08-03 01:08:56 -0600 (Mon, 03 Aug 2009)
New Revision: 11529

Added:
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gri_sos_iir.h
Modified:
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/Makefile.am
Log:
adding second order section iir

Modified: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/Makefile.am
 2009-08-03 05:32:57 UTC (rev 11528)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/Makefile.am
 2009-08-03 07:08:56 UTC (rev 11529)
@@ -195,6 +195,7 @@
        gr_sincos.c                     \
        gr_single_pole_iir_filter_ff.cc \
        gr_single_pole_iir_filter_cc.cc \
+       gr_sos_iir_filter_ffd.cc        \
        gri_goertzel.cc                 \
        gri_mmse_fir_interpolator.cc    \
        gri_mmse_fir_interpolator_cc.cc \
@@ -263,6 +264,7 @@
        gr_goertzel_fc.h                \
        gr_hilbert_fc.h                 \
        gr_iir_filter_ffd.h             \
+       gr_sos_iir_filter_ffd.h         \
        gr_rotator.h                    \
        gr_sincos.h                     \
        gr_single_pole_iir.h            \
@@ -327,6 +329,7 @@
        gr_iir_filter_ffd.i             \
        gr_single_pole_iir_filter_ff.i  \
        gr_single_pole_iir_filter_cc.i  \
+       gr_sos_iir_filter_ffd.i         \
        $(GENERATED_I)
 endif
 

Added: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
                            (rev 0)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
    2009-08-03 07:08:56 UTC (rev 11529)
@@ -0,0 +1,82 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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_sos_iir_filter_ffd.h>
+#include <gr_io_signature.h>
+#include <stdio.h>
+
+
+gr_sos_iir_filter_ffd_sptr 
+gr_make_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                       const std::vector<float> &fbtaps) throw 
(std::invalid_argument)
+{
+  return gr_sos_iir_filter_ffd_sptr (new gr_sos_iir_filter_ffd (fftaps, 
fbtaps));
+}
+
+gr_sos_iir_filter_ffd::gr_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                                     const std::vector<float> &fbtaps) throw 
(std::invalid_argument)
+
+  : gr_sync_block ("iir_filter_ffd",
+                  gr_make_io_signature (1, 1, sizeof (float)),
+                  gr_make_io_signature (1, 1, sizeof (float))),
+    d_sos_iir (fftaps, fbtaps),
+    d_updated (false)
+{
+  // fprintf (stderr, "gr_sos_iir_filter_ffd::ctor\n");
+}
+
+gr_sos_iir_filter_ffd::~gr_sos_iir_filter_ffd ()
+{
+  // nop
+}
+
+void
+gr_sos_iir_filter_ffd::set_taps (const std::vector<float> &fftaps,
+                            const std::vector<float> &fbtaps) throw 
(std::invalid_argument)
+{
+  
+  d_new_fftaps = fftaps;
+  d_new_fbtaps = fbtaps;
+  d_updated = true;
+}
+
+int
+gr_sos_iir_filter_ffd::work (int noutput_items,
+                        gr_vector_const_void_star &input_items,
+                        gr_vector_void_star &output_items)
+{
+  const float *in = (const float *) input_items[0];
+  float *out = (float *) output_items[0];
+
+
+  if (d_updated){
+    d_sos_iir.set_taps (d_new_fftaps, d_new_fbtaps);
+    d_updated = false;
+  }
+
+  d_sos_iir.filter_n (out, in, noutput_items);
+  return noutput_items;
+};

Added: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
                             (rev 0)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
     2009-08-03 07:08:56 UTC (rev 11529)
@@ -0,0 +1,88 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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_SOS_IIR_FILTER_FFD_H
+#define        INCLUDED_GR_SOS_IIR_FILTER_FFD_H
+
+#include <gr_sync_block.h>
+#include <gri_sos_iir.h>
+#include <stdexcept>
+
+class gr_sos_iir_filter_ffd;
+typedef boost::shared_ptr<gr_sos_iir_filter_ffd> gr_sos_iir_filter_ffd_sptr;
+gr_sos_iir_filter_ffd_sptr 
+gr_make_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                       const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+
+/*!
+ * \brief  SOS_IIR filter with float input, float output and float taps
+ * \ingroup filter_blk  and keep intermediate results in double accumulator.
+ *
+ * This filter uses the Direct Form I implementation, where
+ * \p fftaps contains the feed-forward taps, and \p fbtaps the feedback ones.
+ *
+ * 
+ * The input and output satisfy a difference equation of the form
+
+ \f[
+ y[n] - \sum_{k=1}^{M} a_k y[n-k] = \sum_{k=0}^{N} b_k x[n-k]
+ \f]
+
+ * with the corresponding rational system function
+
+ \f[
+ H(z) = \frac{\sum_{k=0}^{M} b_k z^{-k}}{1 - \sum_{k=1}^{N} a_k z^{-k}}
+ \f]
+
+ * Note that some texts define the system function with a + in the denominator.
+ * If you're using that convention, you'll need to negate the feedback taps.
+ */
+class gr_sos_iir_filter_ffd : public gr_sync_block
+{
+ private:
+  friend gr_sos_iir_filter_ffd_sptr 
+  gr_make_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                         const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+
+  gri_sos_iir<float,float,float>       d_sos_iir;
+  std::vector<float>                   d_new_fftaps;
+  std::vector<float>                   d_new_fbtaps;
+  bool                                 d_updated;
+
+  /*!
+   * Construct an SOS_IIR filter with the given taps
+   */
+  gr_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                    const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+
+ public:
+  ~gr_sos_iir_filter_ffd ();
+
+  void set_taps (const std::vector<float> &fftaps,
+                const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif

Added: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
                             (rev 0)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
     2009-08-03 07:08:56 UTC (rev 11529)
@@ -0,0 +1,40 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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,sos_iir_filter_ffd);
+
+gr_sos_iir_filter_ffd_sptr 
+gr_make_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                       const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+
+class gr_sos_iir_filter_ffd : public gr_sync_block
+{
+ private:
+  gr_sos_iir_filter_ffd (const std::vector<float> &fftaps,
+                    const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+
+ public:
+  ~gr_sos_iir_filter_ffd ();
+
+  void set_taps (const std::vector<float> &fftaps,
+                const std::vector<float> &fbtaps) throw 
(std::invalid_argument);
+};

Added: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gri_sos_iir.h
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gri_sos_iir.h
                               (rev 0)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/filter/gri_sos_iir.h
       2009-08-03 07:08:56 UTC (rev 11529)
@@ -0,0 +1,131 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 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_SOS_IIR_H
+#define INCLUDED_GRI_SOS_IIR_H
+
+#include <vector>
+#include <stdexcept>
+
+template<class i_type, class o_type, class tap_type> 
+class gri_sos_iir {
+public:
+  /*!
+   * \brief Construct an SOS_IIR with the given taps.
+   *
+   * This filter uses the Direct Form I implementation, where
+   * \p fftaps contains the feed-forward taps, and \p fbtaps the feedback ones.
+   *
+   * \p fftaps and \p fbtaps must have equal numbers of taps
+   *
+   * The input and output satisfy a difference equation of the form
+
+   \f[
+   y[n] - \sum_{k=1}^{M} a_k y[n-k] = \sum_{k=0}^{N} b_k x[n-k]
+   \f]
+
+   * with the corresponding rational system function
+
+   \f[
+   H(z) = \frac{\sum_{k=0}^{N} b_k z^{-k}}{1 - \sum_{k=1}^{M} a_k z^{-k}}
+   \f]
+
+   * Note that some texts define the system function with a + in the 
denominator.
+   * If you're using that convention, you'll need to negate the feedback taps.
+   */
+  gri_sos_iir (const std::vector<tap_type>& fftaps,
+         const std::vector<tap_type>& fbtaps) throw (std::invalid_argument)
+  {
+    set_taps (fftaps, fbtaps);
+  }
+
+  gri_sos_iir () : d_s1(0), d_s2(0) { }
+
+  ~gri_sos_iir () {}
+
+  /*!
+   * \brief compute a single output value.
+   * \returns the filtered input value.
+   */
+  o_type filter (const i_type input);
+
+  /*!
+   * \brief compute an array of N output values.
+   * \p input must have N valid entries.
+   */
+  void filter_n (o_type output[], const i_type input[], long n);
+
+  /*!
+   * \brief install new taps.
+   */
+  void set_taps (const std::vector<tap_type> &fftaps, 
+                const std::vector<tap_type> &fbtaps) throw 
(std::invalid_argument)
+  { 
+
+
+    d_s2 = 0;
+    d_s1 = 0;
+    d_fftaps = fftaps; 
+    d_fbtaps = fbtaps; 
+
+  }
+
+protected:
+  std::vector<tap_type>        d_fftaps;
+  std::vector<tap_type>        d_fbtaps;
+  int                  d_latest_n;
+  int                  d_latest_m;
+  o_type               d_s2;
+  o_type                d_s1;
+};
+
+
+//
+// general case.  We may want to specialize this
+//
+template<class i_type, class o_type, class tap_type> 
+o_type
+gri_sos_iir<i_type, o_type, tap_type>::filter (const i_type input)
+{
+  o_type       acc;
+  
+  acc  = d_fbtaps[0] * input + d_s1;
+  d_s1 = d_fftaps[1] * input - acc*d_fbtaps[1] * input +d_s2;
+  d_s2 = d_fftaps[2] * input - acc*d_fbtaps[2] * input;
+
+  return acc;
+}
+
+
+
+template<class i_type, class o_type, class tap_type> 
+void 
+gri_sos_iir<i_type, o_type, tap_type>::filter_n (o_type output[],
+                                            const i_type input[],
+                                            long n)
+{
+  for (int i = 0; i < n; i++)
+    output[i] = filter (input[i]);
+}
+
+#endif /* INCLUDED_GRI_SOS_IIR_H */
+





reply via email to

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