discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] patch to add complex agc and complex single_pole_iir


From: Martin Dvh
Subject: [Discuss-gnuradio] patch to add complex agc and complex single_pole_iir and phase modulator
Date: Mon, 20 Feb 2006 18:07:06 +0100
User-agent: Debian Thunderbird 1.0.2 (X11/20051002)

This patch adds complex agc and complex single_pole_iir  and  a phase modulator.
I implemented Eric's suggestion to use partial specialization for the needed 
changes in the gr_single_pole_iir template.
(This way the change doesn't affect any existing uses of gr_single_pole_iir.h)

Changelog below

Greetings,
Martin

2006-02-20  Martin Dudok van Heel <nldudok1 at olifantasia.com>

        Addded new blocks gr_single_pole_iir_filter_cc
                          gr_agc_cc
                          gr_phase_modulator_fc
        Changed gr_single_pole_i to make this work

        * src/lib/filter/Makefile.am: changed. Added 
gr_single_pole_iir_filter_cc
        * src/lib/filter/filter.i: changed. Added gr_single_pole_iir_filter_cc
        * src/lib/filter/gr_single_pole_iir.h: changed template to have partial 
specialization for <gr_complex,i_type,double>.
                                               Needed because calculations and 
temporary variables have to be gr_complexd in this special case
        * src/lib/filter/gr_single_pole_iir_filter_cc.cc: new
        * src/lib/filter/gr_single_pole_iir_filter_cc.h: new
        * src/lib/filter/gr_single_pole_iir_filter_cc.i: new
        * src/lib/general/Makefile.am: changed. Added gr_agc_cc, 
gr_phase_modulator_fc,gri_agc_cc
        * src/lib/general/general.i: changed. Added gr_agc_cc, 
gr_phase_modulator_fc
        * src/lib/general/gr_agc_cc.cc: new
        * src/lib/general/gr_agc_cc.h: new
        * src/lib/general/gr_agc_cc.i: new
        * src/lib/general/gr_phase_modulator_fc.cc: new
        * src/lib/general/gr_phase_modulator_fc.h: new
        * src/lib/general/gr_phase_modulator_fc.i: new
        * src/lib/general/gri_agc_cc.h: new
        * src/lib/general/gri_agc_cc.i: new
        * src/python/gnuradio/gr/Makefile.am: changed. Added 
qa_single_pole_iir_cc.py
        * src/python/gnuradio/gr/qa_single_pole_iir_cc.py: new
Index: src/lib/filter/Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/Makefile.am,v
retrieving revision 1.30
diff -u -r1.30 Makefile.am
--- src/lib/filter/Makefile.am  25 Jan 2006 21:24:14 -0000      1.30
+++ src/lib/filter/Makefile.am  20 Feb 2006 16:50:13 -0000
@@ -178,6 +178,7 @@
        gr_single_pole_rec_filter_ff.cc \
        gr_single_zero_avg_filter_ff.cc \
        gr_single_zero_rec_filter_ff.cc \
+       gr_single_pole_iir_filter_cc.cc \
        gri_mmse_fir_interpolator.cc    \
        gri_mmse_fir_interpolator_cc.cc \
        complex_dotprod_generic.cc      \
@@ -235,6 +236,7 @@
        gr_single_pole_rec_filter_ff.h  \
        gr_single_zero_avg_filter_ff.h  \
        gr_single_zero_rec_filter_ff.h  \
+       gr_single_pole_iir_filter_cc.h  \
        gr_single_zero_avg.h            \
        gr_single_zero_rec.h            \
        gri_iir.h                       \
@@ -285,7 +287,8 @@
        gr_single_pole_avg_filter_ff.i  \
        gr_single_pole_rec_filter_ff.i  \
        gr_single_zero_avg_filter_ff.i  \
-       gr_single_zero_rec_filter_ff.i  
+       gr_single_zero_rec_filter_ff.i  \
+       gr_single_pole_iir_filter_cc.i  
 
        $(GENERATED_I)
 
Index: src/lib/filter/filter.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/filter.i,v
retrieving revision 1.7
diff -u -r1.7 filter.i
--- src/lib/filter/filter.i     20 Jul 2005 05:34:17 -0000      1.7
+++ src/lib/filter/filter.i     20 Feb 2006 16:50:13 -0000
@@ -23,6 +23,7 @@
 %{
 #include <gr_iir_filter_ffd.h>
 #include <gr_single_pole_iir_filter_ff.h>
+#include <gr_single_pole_iir_filter_cc.h>
 #include <gr_hilbert_fc.h>
 #include <gr_filter_delay_fc.h>
 #include <gr_fft_filter_ccc.h>
@@ -31,6 +32,7 @@
 
 %include "gr_iir_filter_ffd.i"
 %include "gr_single_pole_iir_filter_ff.i"
+%include "gr_single_pole_iir_filter_cc.i"
 %include "gr_hilbert_fc.i"
 %include "gr_filter_delay_fc.i"
 %include "gr_fft_filter_ccc.i"
Index: src/lib/filter/gr_single_pole_iir.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/gr_single_pole_iir.h,v
retrieving revision 1.2
diff -u -r1.2 gr_single_pole_iir.h
--- src/lib/filter/gr_single_pole_iir.h 23 Feb 2005 07:49:28 -0000      1.2
+++ src/lib/filter/gr_single_pole_iir.h 20 Feb 2006 16:50:14 -0000
@@ -23,7 +23,7 @@
 #define _GR_SINGLE_POLE_IIR_H_
 
 #include <stdexcept>
-
+#include <gr_complex.h>
 /*!
  * \brief class template for single pole IIR filter
  */
@@ -107,4 +107,84 @@
 }
 
 
+//
+// Specialized case for gr_complex output and double taps
+// We need to have a gr_complexd type for the calculations and prev_output 
variable (in stead of double)
+
+template<class i_type> 
+class gr_single_pole_iir<gr_complex, i_type, double>  {
+public:
+  /*!
+   * \brief construct new single pole IIR with given alpha
+   *
+   * computes y(i) = (1-alpha) * y(i-1) + alpha * x(i)
+   */
+  gr_single_pole_iir (double alpha = 1.0)
+  {
+    d_prev_output = 0;
+    set_taps (alpha);
+  }
+
+  /*!
+   * \brief compute a single output value.
+   * \returns the filtered input value.
+   */
+ gr_complex filter (const i_type input);
+
+  /*!
+   * \brief compute an array of N output values.
+   * \p input must have n valid entries.
+   */
+  void filterN (gr_complex output[], const i_type input[], unsigned long n);
+
+  /*!
+   * \brief install \p alpha as the current taps.
+   */
+  void set_taps (double alpha)
+  { 
+    if (alpha < 0 || alpha > 1)
+      throw std::out_of_range ("Alpha must be in [0, 1]\n");
+
+    d_alpha = alpha;
+    d_one_minus_alpha = 1.0 - alpha;
+  }
+
+  //! reset state to zero
+  void reset ()
+  {
+    d_prev_output = 0;
+  }
+
+  gr_complexd prev_output () { return d_prev_output; }
+    
+protected:
+  double       d_alpha;
+  double       d_one_minus_alpha;
+  gr_complexd  d_prev_output;
+};
+
+template< class i_type> 
+gr_complex
+gr_single_pole_iir<gr_complex, i_type, double>::filter (const i_type input)
+{
+  gr_complexd  output;
+
+  output = d_alpha * (gr_complexd)input + d_one_minus_alpha * d_prev_output;
+  d_prev_output = output;
+
+  return (gr_complex) output;
+}
+
+//Do we need to specialize this, although it is the same as the general case?
+
+template<class i_type> 
+void 
+gr_single_pole_iir<gr_complex, i_type, double>::filterN (gr_complex output[],
+                                                      const i_type input[],
+                                                      unsigned long n)
+{
+  for (unsigned i = 0; i < n; i++)
+    output[i] = filter (input[i]);
+}
+
 #endif /* _GR_SINGLE_POLE_IIR_H_ */
Index: src/lib/filter/gr_single_pole_iir_filter_cc.cc
===================================================================
RCS file: src/lib/filter/gr_single_pole_iir_filter_cc.cc
diff -N src/lib/filter/gr_single_pole_iir_filter_cc.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/filter/gr_single_pole_iir_filter_cc.cc      20 Feb 2006 16:50:14 
-0000
@@ -0,0 +1,81 @@
+/* -*- 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_single_pole_iir_filter_cc.h>
+#include <gr_io_signature.h>
+#include <stdio.h>
+
+
+gr_single_pole_iir_filter_cc_sptr 
+gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen)
+{
+  return gr_single_pole_iir_filter_cc_sptr(new 
gr_single_pole_iir_filter_cc(alpha, vlen));
+}
+
+gr_single_pole_iir_filter_cc::gr_single_pole_iir_filter_cc (
+                                   double alpha, unsigned int vlen)
+  : gr_sync_block ("single_pole_iir_filter_cc",
+                  gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
+                  gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen)),
+    d_vlen(vlen), d_iir(vlen)
+{
+  set_taps(alpha);
+}
+
+gr_single_pole_iir_filter_cc::~gr_single_pole_iir_filter_cc ()
+{
+  // nop
+}
+
+void
+gr_single_pole_iir_filter_cc::set_taps (double alpha)
+{
+  for (unsigned int i = 0; i < d_vlen; i++)
+    d_iir[i].set_taps(alpha);
+}
+
+int
+gr_single_pole_iir_filter_cc::work (int noutput_items,
+                                   gr_vector_const_void_star &input_items,
+                                   gr_vector_void_star &output_items)
+{
+  const gr_complex *in = (const gr_complex *) input_items[0];
+  gr_complex *out = (gr_complex *) output_items[0];
+  unsigned int vlen = d_vlen;
+
+  if (d_vlen == 1){
+    for (int i = 0; i < noutput_items; i++)
+      out[i] = d_iir[0].filter (in[i]);
+  }
+  else {
+    for (int i = 0; i < noutput_items; i++){
+      for (unsigned int j = 0; j < vlen; j++){
+       *out++ = d_iir[j].filter (*in++);
+      }
+    }
+  }
+  return noutput_items;
+};
Index: src/lib/filter/gr_single_pole_iir_filter_cc.h
===================================================================
RCS file: src/lib/filter/gr_single_pole_iir_filter_cc.h
diff -N src/lib/filter/gr_single_pole_iir_filter_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/filter/gr_single_pole_iir_filter_cc.h       20 Feb 2006 16:50:14 
-0000
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_GR_SINGLE_POLE_IIR_FILTER_CC_H
+#define        INCLUDED_GR_SINGLE_POLE_IIR_FILTER_CC_H
+
+#include <gr_sync_block.h>
+#include <gr_single_pole_iir.h>
+#include <gr_complex.h>
+#include <stdexcept>
+
+class gr_single_pole_iir_filter_cc;
+typedef boost::shared_ptr<gr_single_pole_iir_filter_cc> 
gr_single_pole_iir_filter_cc_sptr;
+
+gr_single_pole_iir_filter_cc_sptr 
+gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen=1);
+
+/*!
+ * \brief  single pole IIR filter with complex input, complex output
+ * \ingroup filter
+ *
+ * The input and output satisfy a difference equation of the form
+
+ \f[
+ y[n] - (1-alpha) y[n-1] = alpha x[n]
+ \f]
+
+ * with the corresponding rational system function
+
+ \f[
+ H(z) = \frac{alpha}{1 - (1-alpha) z^{-1}}
+ \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 tap.
+ */
+class gr_single_pole_iir_filter_cc : public gr_sync_block
+{
+ private:
+  friend gr_single_pole_iir_filter_cc_sptr 
+  gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen);
+
+  unsigned int                                         d_vlen;
+  std::vector<gr_single_pole_iir<gr_complex,gr_complex,double> >       d_iir;
+
+  gr_single_pole_iir_filter_cc (double alpha, unsigned int vlen);
+
+ public:
+  ~gr_single_pole_iir_filter_cc ();
+
+  void set_taps (double alpha);
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif
Index: src/lib/filter/gr_single_pole_iir_filter_cc.i
===================================================================
RCS file: src/lib/filter/gr_single_pole_iir_filter_cc.i
diff -N src/lib/filter/gr_single_pole_iir_filter_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/filter/gr_single_pole_iir_filter_cc.i       20 Feb 2006 16:50:14 
-0000
@@ -0,0 +1,34 @@
+/* -*- 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,single_pole_iir_filter_cc);
+
+gr_single_pole_iir_filter_cc_sptr 
+gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen=1);
+
+class gr_single_pole_iir_filter_cc : public gr_sync_block
+{
+ public:
+  ~gr_single_pole_iir_filter_cc ();
+
+  void set_taps (double alpha);
+};
Index: src/lib/general/Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/Makefile.am,v
retrieving revision 1.73
diff -u -r1.73 Makefile.am
--- src/lib/general/Makefile.am 29 Dec 2005 10:40:51 -0000      1.73
+++ src/lib/general/Makefile.am 20 Feb 2006 16:50:14 -0000
@@ -122,6 +122,7 @@
        gr_float_to_complex.cc          \
        gr_float_to_short.cc            \
        gr_firdes.cc                    \
+       gr_phase_modulator_fc.cc                \
        gr_frequency_modulator_fc.cc    \
        gr_fxpt.cc                      \
        gr_head.cc                      \
@@ -154,6 +155,7 @@
        gr_simple_correlator.cc         \
        gr_simple_squelch_cc.cc         \
        gr_agc_ff.cc                \
+       gr_agc_cc.cc                \
        gr_stream_to_streams.cc         \
        gr_streams_to_stream.cc         \
        gr_streams_to_vector.cc         \
@@ -194,6 +196,7 @@
        $(GENERATED_H)                  \
        malloc16.h                      \
        gri_agc.h                       \
+       gri_agc_cc.h                    \
        gr_align_on_samplenumbers_ss.h          \
        gr_bytes_to_syms.h              \
        gr_check_counting_s.h           \
@@ -216,6 +219,7 @@
        gr_fft_vfc.h                    \
        gr_firdes.h                     \
        gr_float_to_complex.h           \
+       gr_phase_modulator_fc.h         \
        gr_frequency_modulator_fc.h     \
        gr_fxpt.h                       \
        gr_fxpt_nco.h                   \
@@ -255,6 +259,7 @@
        gr_simple_framer_sync.h         \
        gr_simple_squelch_cc.h          \
        gr_agc_ff.h                 \
+       gr_agc_cc.h                 \
        gr_stream_to_streams.h          \
        gr_streams_to_stream.h          \
        gr_streams_to_vector.h          \
@@ -316,6 +321,7 @@
        gr_float_to_uchar.i             \
        gr_float_to_complex.i           \
        gr_float_to_short.i             \
+       gr_phase_modulator_fc.i         \
        gr_frequency_modulator_fc.i     \
        gr_head.i                       \
        gr_skiphead.i                   \
@@ -344,7 +350,9 @@
        gr_simple_framer.i              \
        gr_simple_squelch_cc.i          \
        gri_agc.i                 \
+       gri_agc_cc.i                 \
        gr_agc_ff.i                 \
+       gr_agc_cc.i                 \
        gr_stream_to_streams.i          \
        gr_streams_to_stream.i          \
        gr_streams_to_vector.i          \
Index: src/lib/general/general.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/general.i,v
retrieving revision 1.45
diff -u -r1.45 general.i
--- src/lib/general/general.i   29 Dec 2005 10:40:51 -0000      1.45
+++ src/lib/general/general.i   20 Feb 2006 16:50:14 -0000
@@ -49,6 +49,7 @@
 #include <gr_char_to_float.h>
 #include <gr_uchar_to_float.h>
 #include <gr_frequency_modulator_fc.h>
+#include <gr_phase_modulator_fc.h>
 #include <gr_bytes_to_syms.h>
 #include <gr_simple_correlator.h>
 #include <gr_simple_framer.h>
@@ -61,6 +62,7 @@
 #include <gr_deinterleave.h>
 #include <gr_simple_squelch_cc.h>
 #include <gr_agc_ff.h>
+#include <gr_agc_cc.h>
 #include <gr_rms_cf.h>
 #include <gr_rms_ff.h>
 #include <gr_nlog10_ff.h>
@@ -115,6 +117,7 @@
 %include "gr_char_to_float.i"
 %include "gr_uchar_to_float.i"
 %include "gr_frequency_modulator_fc.i"
+%include "gr_phase_modulator_fc.i"
 %include "gr_bytes_to_syms.i"
 %include "gr_simple_correlator.i"
 %include "gr_simple_framer.i"
@@ -127,6 +130,7 @@
 %include "gr_deinterleave.i"
 %include "gr_simple_squelch_cc.i"
 %include "gr_agc_ff.i"
+%include "gr_agc_cc.i"
 %include "gr_rms_cf.i"
 %include "gr_rms_ff.i"
 %include "gr_nlog10_ff.i"
Index: src/lib/general/gr_agc_cc.cc
===================================================================
RCS file: src/lib/general/gr_agc_cc.cc
diff -N src/lib/general/gr_agc_cc.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_agc_cc.cc        20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_agc_cc.h>
+#include <gr_io_signature.h>
+#include <gri_agc_cc.h>
+
+gr_agc_cc_sptr
+gr_make_agc_cc (float rate, float reference, float gain)
+{
+  return gr_agc_cc_sptr (new gr_agc_cc (rate, reference, gain));
+}
+
+gr_agc_cc::gr_agc_cc (float rate, float reference, float gain)
+  : gr_sync_block ("gr_agc_cc",
+                  gr_make_io_signature (1, 1, sizeof (gr_complex)),
+                  gr_make_io_signature (1, 1, sizeof (gr_complex)))
+  , gri_agc_cc (rate,  reference, gain)
+{
+}
+
+int
+gr_agc_cc::work (int noutput_items,
+                        gr_vector_const_void_star &input_items,
+                        gr_vector_void_star &output_items)
+{
+  const gr_complex *in = (const gr_complex *) input_items[0];
+  gr_complex *out = (gr_complex *) output_items[0];
+  scaleN (out, in, noutput_items);
+  return noutput_items;
+}
Index: src/lib/general/gr_agc_cc.h
===================================================================
RCS file: src/lib/general/gr_agc_cc.h
diff -N src/lib/general/gr_agc_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_agc_cc.h 20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_GR_AGC_CC_H
+#define INCLUDED_GR_AGC_CC_H
+
+#include <gr_sync_block.h>
+#include <gri_agc_cc.h>
+class gr_agc_cc;
+typedef boost::shared_ptr<gr_agc_cc> gr_agc_cc_sptr;
+
+gr_agc_cc_sptr
+gr_make_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0);
+/*!
+ * \brief high performance Automatic Gain Control class
+ *
+ * For Power the absolute value of the complex number is used.
+ */
+
+class gr_agc_cc : public gr_sync_block, public gri_agc_cc
+{
+  friend gr_agc_cc_sptr gr_make_agc_cc (float rate, float reference, float 
gain);
+  gr_agc_cc (float rate, float reference, float gain);
+
+ public:
+  virtual int work (int noutput_items,
+                   gr_vector_const_void_star &input_items,
+                   gr_vector_void_star &output_items);
+};
+
+
+#endif /* INCLUDED_GR_AGC_CC_H */
Index: src/lib/general/gr_agc_cc.i
===================================================================
RCS file: src/lib/general/gr_agc_cc.i
diff -N src/lib/general/gr_agc_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_agc_cc.i 20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,agc_cc)
+
+%include <gri_agc_cc.i>
+
+gr_agc_cc_sptr
+gr_make_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0);
+
+class gr_agc_cc : public gr_sync_block , public gri_agc_cc
+{
+  gr_agc_cc (float rate, float reference, float gain);
+};
Index: src/lib/general/gr_phase_modulator_fc.cc
===================================================================
RCS file: src/lib/general/gr_phase_modulator_fc.cc
diff -N src/lib/general/gr_phase_modulator_fc.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_phase_modulator_fc.cc    20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_phase_modulator_fc.h>
+#include <gr_io_signature.h>
+#include <gr_sincos.h>
+#include <math.h>
+
+
+gr_phase_modulator_fc_sptr gr_make_phase_modulator_fc (double sensitivity)
+{
+  return gr_phase_modulator_fc_sptr (new gr_phase_modulator_fc (sensitivity));
+}
+
+gr_phase_modulator_fc::gr_phase_modulator_fc (double sensitivity)
+  : gr_sync_block ("phase_modulator_fc",
+                  gr_make_io_signature (1, 1, sizeof (float)),
+                  gr_make_io_signature (1, 1, sizeof (gr_complex))),
+    d_sensitivity (sensitivity), d_phase (0)
+{
+}
+
+int
+gr_phase_modulator_fc::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];
+  gr_complex *out = (gr_complex *) output_items[0];
+
+  for (int i = 0; i < noutput_items; i++){
+    d_phase = d_sensitivity * in[i];
+    float oi, oq;
+    gr_sincosf (d_phase, &oq, &oi);
+    out[i] = gr_complex (oi, oq);
+  }
+ 
+  return noutput_items;
+}
Index: src/lib/general/gr_phase_modulator_fc.h
===================================================================
RCS file: src/lib/general/gr_phase_modulator_fc.h
diff -N src/lib/general/gr_phase_modulator_fc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_phase_modulator_fc.h     20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_GR_PHASE_MODULATOR_FC_H
+#define INCLUDED_GR_PHASE_MODULATOR_FC_H
+
+#include <gr_sync_block.h>
+
+class gr_phase_modulator_fc;
+typedef boost::shared_ptr<gr_phase_modulator_fc> gr_phase_modulator_fc_sptr;
+
+gr_phase_modulator_fc_sptr gr_make_phase_modulator_fc (double sensitivity);
+
+/*!
+ * \brief Phase modulator block
+ * \ingroup block 
+ * output=complex(cos(in*sensitivity),sin(in*sensitivity))
+ */
+class gr_phase_modulator_fc : public gr_sync_block
+{
+  double       d_sensitivity;
+  double       d_phase;
+
+  friend gr_phase_modulator_fc_sptr
+  gr_make_phase_modulator_fc (double sensitivity);
+
+  gr_phase_modulator_fc (double sensitivity);
+
+ public:
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_PHASE_MODULATOR_FC_H */
Index: src/lib/general/gr_phase_modulator_fc.i
===================================================================
RCS file: src/lib/general/gr_phase_modulator_fc.i
diff -N src/lib/general/gr_phase_modulator_fc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_phase_modulator_fc.i     20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,phase_modulator_fc)
+
+gr_phase_modulator_fc_sptr gr_make_phase_modulator_fc (double sensitivity);
+
+class gr_phase_modulator_fc : public gr_sync_block
+{
+ private: 
+  gr_phase_modulator_fc (double sensitivity);
+};
Index: src/lib/general/gri_agc_cc.h
===================================================================
RCS file: src/lib/general/gri_agc_cc.h
diff -N src/lib/general/gri_agc_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gri_agc_cc.h        20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,66 @@
+/* -*- 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _GRI_AGC_CC_H_
+#define _GRI_AGC_CC_H_
+
+#include <math.h>
+
+/*!
+ * \brief high performance Automatic Gain Control class
+ *
+ * For Power the absolute value of the complex number is used.
+ */
+
+class gri_agc_cc {
+
+ public:
+  gri_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0)
+    : _rate(rate), _reference(reference), _gain(gain) {};
+
+  float rate () const      { return _rate; }
+  float reference () const { return _reference; }
+  float gain () const     { return _gain;  }
+
+  void set_rate (float rate) { _rate = rate; }
+  void set_reference (float reference) { _reference = reference; }
+  void set_gain (float gain) { _gain = gain; }
+
+  gr_complex scale (gr_complex input){
+    gr_complex output = input * _gain;
+    _gain += (_reference - 
sqrt(output.real()*output.real()+output.imag()*output.imag())) * _rate;//use 
abs or cabs to get approximation by absolute value, 
+                                                 //note that abs is 
computationally more intensive then norm for a complex number
+    return output;
+  }
+
+  void scaleN (gr_complex output[], const gr_complex input[], unsigned n){
+    for (unsigned i = 0; i < n; i++)
+      output[i] = scale (input[i]);
+  }
+  
+ protected:
+  float _rate;                 // adjustment rate
+  float        _reference;             // reference value
+  float        _gain;                  // current gain
+};
+
+#endif /* _GRI_AGC_CC_H_ */
Index: src/lib/general/gri_agc_cc.i
===================================================================
RCS file: src/lib/general/gri_agc_cc.i
diff -N src/lib/general/gri_agc_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gri_agc_cc.i        20 Feb 2006 16:50:14 -0000
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <math.h>
+
+/*!
+ * \brief high performance Automatic Gain Control class
+ *
+ * For Power the absolute value of the complex number is used.
+ */
+
+
+class gri_agc_cc {
+
+ public:
+  gri_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0);
+  float rate ();
+  float reference ();
+  float gain ();
+  };
Index: src/python/gnuradio/gr/Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/python/gnuradio/gr/Makefile.am,v
retrieving revision 1.29
diff -u -r1.29 Makefile.am
--- src/python/gnuradio/gr/Makefile.am  6 Oct 2005 02:39:18 -0000       1.29
+++ src/python/gnuradio/gr/Makefile.am  20 Feb 2006 16:50:15 -0000
@@ -62,6 +62,7 @@
        qa_pipe_fittings.py             \
        qa_rational_resampler.py        \
        qa_sig_source.py                \
-       qa_single_pole_iir.py           
+       qa_single_pole_iir.py           \       
+       qa_single_pole_iir_cc.py                
 
 CLEANFILES = *.pyc
Index: src/python/gnuradio/gr/qa_single_pole_iir_cc.py
===================================================================
RCS file: src/python/gnuradio/gr/qa_single_pole_iir_cc.py
diff -N src/python/gnuradio/gr/qa_single_pole_iir_cc.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/python/gnuradio/gr/qa_single_pole_iir_cc.py     20 Feb 2006 16:50:15 
-0000
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+# 
+
+from gnuradio import gr, gr_unittest
+
+class test_single_pole_iir_cc(gr_unittest.TestCase):
+
+    def setUp (self):
+        self.fg = gr.flow_graph ()
+
+    def tearDown (self):
+        self.fg = None
+
+    def test_001(self):
+        src_data = (0+0j, 1000+1000j, 2000+2000j, 3000+3000j, 4000+4000j, 
5000+5000j)
+        expected_result = src_data
+        src = gr.vector_source_c(src_data)
+        op = gr.single_pole_iir_filter_cc (1.0)
+        dst = gr.vector_sink_c()
+        self.fg.connect (src, op, dst)
+        self.fg.run()
+        result_data = dst.data()
+        self.assertComplexTuplesAlmostEqual (expected_result, result_data)
+
+    def test_002(self):
+        src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), 
complex(3000,-3000), complex(4000,-4000), complex(5000,-5000))
+        expected_result = (complex(0,0), complex(125,-125), 
complex(359.375,-359.375), complex(689.453125,-689.453125), 
complex(1103.271484,-1103.271484), complex(1590.36255,-1590.36255))
+        src = gr.vector_source_c(src_data)
+        op = gr.single_pole_iir_filter_cc (0.125)
+        dst = gr.vector_sink_c()
+        self.fg.connect (src, op, dst)
+        self.fg.run()
+        result_data = dst.data()
+        self.assertComplexTuplesAlmostEqual (expected_result, result_data, 3)
+
+    def test_003(self):
+        block_size = 2
+        src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), 
complex(3000,-3000), complex(4000,-4000), complex(5000,-5000))
+        expected_result = (complex(0,0), complex(125,-125), complex(250,-250), 
complex(484.375,-484.375), complex(718.75,-718.75), 
complex(1048.828125,-1048.828125))
+        src = gr.vector_source_c(src_data)
+        s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, block_size)
+        op = gr.single_pole_iir_filter_cc (0.125, block_size)
+        p2s = gr.parallel_to_serial(gr.sizeof_gr_complex, block_size)
+        dst = gr.vector_sink_c()
+        self.fg.connect (src, s2p, op, p2s, dst)
+        self.fg.run()
+        result_data = dst.data()
+        self.assertComplexTuplesAlmostEqual (expected_result, result_data, 3)
+
+
+if __name__ == '__main__':
+    gr_unittest.main ()
+        

reply via email to

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