[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r11264 - gnuradio/branches/developers/n4hy/iir_pfb/gnu
From: |
n4hy |
Subject: |
[Commit-gnuradio] r11264 - gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter |
Date: |
Tue, 23 Jun 2009 08:11:26 -0600 (MDT) |
Author: n4hy
Date: 2009-06-23 08:11:26 -0600 (Tue, 23 Jun 2009)
New Revision: 11264
Added:
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gri_sos_iir.h
Log:
beginning to add sos iir code
Added:
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
===================================================================
---
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
(rev 0)
+++
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.cc
2009-06-23 14:11:26 UTC (rev 11264)
@@ -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_iir_filter_ffd.h>
+#include <gr_io_signature.h>
+#include <stdio.h>
+
+
+gr_iir_filter_ffd_sptr
+gr_make_iir_filter_ffd (const std::vector<float> &fftaps,
+ const std::vector<float> &fbtaps) throw
(std::invalid_argument)
+{
+ return gr_iir_filter_ffd_sptr (new gr_iir_filter_ffd (fftaps, fbtaps));
+}
+
+gr_iir_filter_ffd::gr_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_iir (fftaps, fbtaps),
+ d_updated (false)
+{
+ // fprintf (stderr, "gr_iir_filter_ffd::ctor\n");
+}
+
+gr_iir_filter_ffd::~gr_iir_filter_ffd ()
+{
+ // nop
+}
+
+void
+gr_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_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_iir.set_taps (d_new_fftaps, d_new_fbtaps);
+ d_updated = false;
+ }
+
+ d_iir.filter_n (out, in, noutput_items);
+ return noutput_items;
+};
Added:
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
===================================================================
---
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
(rev 0)
+++
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.h
2009-06-23 14:11:26 UTC (rev 11264)
@@ -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/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
===================================================================
---
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
(rev 0)
+++
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gr_sos_iir_filter_ffd.i
2009-06-23 14:11:26 UTC (rev 11264)
@@ -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/iir_pfb/gnuradio-core/src/lib/filter/gri_sos_iir.h
===================================================================
---
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gri_sos_iir.h
(rev 0)
+++
gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter/gri_sos_iir.h
2009-06-23 14:11:26 UTC (rev 11264)
@@ -0,0 +1,151 @@
+/* -*- 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>
+
+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<float>& fftaps,
+ const std::vector<float>& fbtaps) throw (std::invalid_argument)
+ {
+ set_taps (fftaps, fbtaps);
+ }
+
+ gri_sos_iir () : d_v2(0),d_v1(0) { }
+
+ ~gri_sos_iir () {}
+
+ /*!
+ * \brief compute a single output value.
+ * \returns the filtered input value.
+ */
+ float filter (const float input);
+
+ /*!
+ * \brief compute an array of N output values.
+ * \p input must have N valid entries.
+ */
+ void filter_n (float output[], const float 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_v2 = 0;
+ d_v1 = 0;
+ d_fftaps = fftaps;
+ d_fbtaps = fbtaps;
+
+ }
+
+protected:
+ std::vector<float> d_fftaps;
+ std::vector<float> d_fbtaps;
+ int d_latest_n;
+ int d_latest_m;
+ double d_v2;
+ double d_v1;
+ std::vector<float> d_prev_input;
+};
+
+
+//
+// general case. We may want to specialize this
+//
+float
+gri_sos_iir<float, float, float>::filter (const float input)
+{
+ double acc;
+ double v0;
+ unsigned i = 0;
+
+ if (n == 0)
+ return (float) 0;
+
+
+ acc = d_fbtaps[0] * input - d_v1;
+ d_v1 = d_fbtaps[1] * input - d_fftaps[1] *
+ acc -= d_fbtaps[1] * d_v1 + d_fbtaps[2]*d_v2;
+ acc += d_fftaps[0]*d_v0 + d_fftapbs[1]*d_v1 +d_fftaps[2]*d_v2;
+
+ // store the values twice to avoid having to handle wrap-around in the loop
+ d_prev_output[latest_m] = acc;
+ d_prev_output[latest_m+m] = acc;
+ d_prev_input[latest_n] = input;
+ d_prev_input[latest_n+n] = input;
+
+ latest_n--;
+ latest_m--;
+ if (latest_n < 0)
+ latest_n += n;
+ if (latest_m < 0)
+ latest_m += m;
+
+ d_latest_m = latest_m;
+ d_latest_n = latest_n;
+ return (float) acc;
+}
+
+
+
+void
+gri_sos_iir<float, float, tap_type>::filter_n (float output[],
+ const float input[],
+ long n)
+{
+ for (int i = 0; i < n; i++)
+ output[i] = filter (input[i]);
+}
+
+#endif /* INCLUDED_GRI_SOS_IIR_H */
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r11264 - gnuradio/branches/developers/n4hy/iir_pfb/gnuradio-core/src/lib/filter,
n4hy <=